<commit_before>import * as BaseActions from './BaseActions';

export type CommonAction = BaseActions.Action;

export type NavigationState = {
  /**
   * Unique key for the navigation state.
   */
  key: string;
  /**
   * Index of the currently focused route.
   */
  index: number;
  /**
   * List if valid route names as defined in the screen components.
   */
  routeNames: string[];
  /**
   * List of rendered routes.
   */
  routes: Array<Route & { state?: NavigationState }>;
};

export type PartialState = Omit<Omit<NavigationState, 'routeNames'>, 'key'> & {
  key?: undefined;
  routeNames?: undefined;
  state?: PartialState;
};

export type Route<RouteName = string> = {
  /**
   * Unique key for the route.
   */
  key: string;
  /**
   * User-provided name for the route.
   */
  name: RouteName;
  /**
   * Params for the route.
   */
  params?: object;
};

export type NavigationAction = {
  type: string;
};

export type ActionCreators<Action extends NavigationAction = CommonAction> = {
  [key: string]: (...args: any) => Action;
};

export type Router<Action extends NavigationAction = CommonAction> = {
  /**
   * Initialize the navigation state.
   */
  getInitialState(options: {
    routeNames: string[];
    initialRouteName: string;
    initialParamsList: ParamListBase;
  }): NavigationState;

  /**
   * Rehydrate the full navigation state from a given partial state.
   */
  getRehydratedState(options: {
    routeNames: string[];
    partialState: NavigationState | PartialState;
  }): NavigationState;

  /**
   * Take the current state and action, and return a new state.
   * If the action cannot be handled, return `null`.
   */
  getStateForAction(
    state: NavigationState,
    action: Action
  ): NavigationState | null;

  /**
   * Action creators for the router.
   */
  actionCreators: ActionCreators<Action>;
};

export type ParamListBase = { [key: string]: object | undefined };

class PrivateValueStore<T> {
  /**
   * TypeScript requires a type to be actually used to be able to infer it.
   * This is a hacky way of storing type in a property without surfacing it in intellisense.
   */
  // @ts-ignore
  private __private_value_type?: T;
}

export type NavigationHelpers<
  ParamList extends ParamListBase = ParamListBase
> = {
  /**
   * Dispatch an action or an update function to the router.
   * The update function will receive the current state,
   */
  dispatch(
    action: NavigationAction | ((state: NavigationState) => NavigationState)
  ): void;

  /**
   * Navigate to a route in current navigation tree.
   *
   * @param name Name of the route to navigate to.
   * @param [params] Params object for the route.
   */
  navigate<RouteName extends keyof ParamList>(
    ...args: ParamList[RouteName] extends undefined
      ? [RouteName] | [RouteName, undefined]
      : [RouteName, ParamList[RouteName]]
  ): void;

  /**
   * Replace the current route with a new one.
   *
   * @param name Route name of the new route.
   * @param [params] Params object for the new route.
   */
  replace<RouteName extends keyof ParamList>(
    ...args: ParamList[RouteName] extends undefined
      ? [RouteName] | [RouteName, undefined]
      : [RouteName, ParamList[RouteName]]
  ): void;

  /**
   * Reset the navigation state to the provided state.
   * If a key is provided, the state with matching key will be reset.
   */
  reset(state: PartialState & { key?: string }): void;

  /**
   * Go back to the previous route in history.
   */
  goBack(): void;
} & PrivateValueStore<ParamList>;

export type NavigationProp<
  ParamList extends ParamListBase,
  RouteName extends keyof ParamList
> = NavigationHelpers<ParamList> & {
  /**
   * State for the child navigator.
   */
  state: Omit<Route<RouteName>, 'params'> &
    (ParamList[RouteName] extends undefined
      ? {}
      : { params: ParamList[RouteName] });

  /**
   * Update the param object for the route.
   * The new params will be shallow merged with the old one.
   */
  setParams(params: ParamList[RouteName]): void;
};

export type CompositeNavigationProp<
  A extends NavigationHelpers<ParamListBase>,
  B extends NavigationHelpers<ParamListBase>
> = Omit<A & B, keyof NavigationHelpers<any>> &
  NavigationHelpers<
    (A extends NavigationHelpers<infer T> ? T : never) &
      (B extends NavigationHelpers<infer U> ? U : never)
  >;<commit_msg>docs: add JSDoc for some comments<commit_after>import * as BaseActions from './BaseActions';

export type CommonAction = BaseActions.Action;

export type NavigationState = {
  /**
   * Unique key for the navigation state.
   */
  key: string;
  /**
   * Index of the currently focused route.
   */
  index: number;
  /**
   * List of valid route names as defined in the screen components.
   */
  routeNames: string[];
  /**
   * List of rendered routes.
   */
  routes: Array<Route & { state?: NavigationState }>;
};

export type PartialState = Omit<Omit<NavigationState, 'routeNames'>, 'key'> & {
  key?: undefined;
  routeNames?: undefined;
  state?: PartialState;
};

export type Route<RouteName = string> = {
  /**
   * Unique key for the route.
   */
  key: string;
  /**
   * User-provided name for the route.
   */
  name: RouteName;
  /**
   * Params for the route.
   */
  params?: object;
};

export type NavigationAction = {
  type: string;
};

export type ActionCreators<Action extends NavigationAction = CommonAction> = {
  [key: string]: (...args: any) => Action;
};

export type Router<Action extends NavigationAction = CommonAction> = {
  /**
   * Initialize the navigation state.
   *
   * @param routeNames List of valid route names as defined in the screen components.
   * @param initialRouteName Route to focus in the state.
   * @param initialParamsList Object containing initial params for each route.
   */
  getInitialState(options: {
    routeNames: string[];
    initialRouteName: string;
    initialParamsList: ParamListBase;
  }): NavigationState;

  /**
   * Rehydrate the full navigation state from a given partial state.
   *
   * @param routeNames List of valid route names as defined in the screen components.
   * @param partialState Navigation state to rehydrate from.
   */
  getRehydratedState(options: {
    routeNames: string[];
    partialState: NavigationState | PartialState;
  }): NavigationState;

  /**
   * Take the current state and action, and return a new state.
   * If the action cannot be handled, return `null`.
   *
   * @param state State object to apply the action on.
   * @param action Action object to apply.
   */
  getStateForAction(
    state: NavigationState,
    action: Action
  ): NavigationState | null;

  /**
   * Action creators for the router.
   */
  actionCreators: ActionCreators<Action>;
};

export type ParamListBase = { [key: string]: object | undefined };

class PrivateValueStore<T> {
  /**
   * TypeScript requires a type to be actually used to be able to infer it.
   * This is a hacky way of storing type in a property without surfacing it in intellisense.
   */
  // @ts-ignore
  private __private_value_type?: T;
}

export type NavigationHelpers<
  ParamList extends ParamListBase = ParamListBase
> = {
  /**
   * Dispatch an action or an update function to the router.
   * The update function will receive the current state,
   *
   * @param action Action object or update function.
   */
  dispatch(
    action: NavigationAction | ((state: NavigationState) => NavigationState)
  ): void;

  /**
   * Navigate to a route in current navigation tree.
   *
   * @param name Name of the route to navigate to.
   * @param [params] Params object for the route.
   */
  navigate<RouteName extends keyof ParamList>(
    ...args: ParamList[RouteName] extends undefined
      ? [RouteName] | [RouteName, undefined]
      : [RouteName, ParamList[RouteName]]
  ): void;

  /**
   * Replace the current route with a new one.
   *
   * @param name Route name of the new route.
   * @param [params] Params object for the new route.
   */
  replace<RouteName extends keyof ParamList>(
    ...args: ParamList[RouteName] extends undefined
      ? [RouteName] | [RouteName, undefined]
      : [RouteName, ParamList[RouteName]]
  ): void;

  /**
   * Reset the navigation state to the provided state.
   * If a key is provided, the state with matching key will be reset.
   *
   * @param state Navigation state object.
   */
  reset(state: PartialState & { key?: string }): void;

  /**
   * Go back to the previous route in history.
   */
  goBack(): void;
} & PrivateValueStore<ParamList>;

export type NavigationProp<
  ParamList extends ParamListBase,
  RouteName extends keyof ParamList
> = NavigationHelpers<ParamList> & {
  /**
   * State for the child navigator.
   */
  state: Omit<Route<RouteName>, 'params'> &
    (ParamList[RouteName] extends undefined
      ? {}
      : { params: ParamList[RouteName] });

  /**
   * Update the param object for the route.
   * The new params will be shallow merged with the old one.
   *
   * @param params Params object for the current route.
   */
  setParams(params: ParamList[RouteName]): void;
};

export type CompositeNavigationProp<
  A extends NavigationHelpers<ParamListBase>,
  B extends NavigationHelpers<ParamListBase>
> = Omit<A & B, keyof NavigationHelpers<any>> &
  NavigationHelpers<
    (A extends NavigationHelpers<infer T> ? T : never) &
      (B extends NavigationHelpers<infer U> ? U : never)
  >;
{'fraction_non_alphanumeric': 0.10821451372632475, 'fraction_numerical': 0.0, 'mean_word_length': 3.2242696629213485, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 55, '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': '1491908', 'n_tokens_mistral': 2785, 'n_tokens_neox': 2751, 'n_words': 948}