<commit_before>import * as React from 'react';
import { connect } from 'react-redux';
import { ApplicationState } from '../state/ApplicationState';
import { matchesPermissions } from '../state/Selectors';
import { createSelector } from 'reselect';
import { memoize } from 'ramda';

type StateProps = {
  readonly show: boolean;
};

export type WithPermissionProps = {
  readonly permission: string | string[];
  readonly alternative?: React.ComponentType;
};

const WithPermissionComponent: React.SFC<StateProps & WithPermissionProps> = ({ show, alternative, children }) => {
  if (show) {
    return <>children</> || null;
  }

  if (alternative) {
    const Alt = alternative;

    return <Alt />;
  }

  return null;
};

const memoizedStateSelector = memoize((perms: string | string[]) =>
  createSelector(matchesPermissions(perms), show => ({
    show,
  })),
);

export const WithPermission = connect<StateProps, {}, WithPermissionProps>(
  (state: ApplicationState, props?: WithPermissionProps): StateProps => memoizedStateSelector(props!.permission)(state),
)(WithPermissionComponent);<commit_msg>children<commit_after>import * as React from 'react';
import { connect } from 'react-redux';
import { ApplicationState } from '../state/ApplicationState';
import { matchesPermissions } from '../state/Selectors';
import { createSelector } from 'reselect';
import { memoize } from 'ramda';

type StateProps = {
  readonly show: boolean;
};

export type WithPermissionProps = {
  readonly permission: string | string[];
  readonly alternative?: React.ComponentType;
};

const WithPermissionComponent: React.FunctionComponent<StateProps & WithPermissionProps> = ({ show, alternative, children }) => {
  if (show) {
    return <>{children}</> || null;
  }

  if (alternative) {
    const Alt = alternative;

    return <Alt />;
  }

  return null;
};

const memoizedStateSelector = memoize((perms: string | string[]) =>
  createSelector(matchesPermissions(perms), show => ({
    show,
  })),
);

export const WithPermission = connect<StateProps, {}, WithPermissionProps>(
  (state: ApplicationState, props?: WithPermissionProps): StateProps => memoizedStateSelector(props!.permission)(state),
)(WithPermissionComponent);
{'fraction_non_alphanumeric': 0.138801261829653, 'fraction_numerical': 0.0, 'mean_word_length': 5.082191780821918, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5888908', 'n_tokens_mistral': 605, 'n_tokens_neox': 601, 'n_words': 161}