<commit_before>/**
 * 仅供typescript下使用，将redux-saga的yield select(selector)结果转换为实际类型
 * For typescript only, cast redux-saga yield select(selector) to actual result
 * 用法/usage： const result = asResult(selector, yield select(selector))
 */
export function asResult<T>(fn: (...any: any[]) => T, result: any): T {
  return result;
}

/**
 * 常用工具方法 - 生成reducer
 * helper - generate simple reducer
 * 用法/usage： num : reduceFromPayload(types.SET_NUM, 0)
 */
export function reduceFromPayload<TState, TType = string>(
  actionType: TType,
  initialState: TState
) {
  return (
    state: TState = initialState,
    action: { type: TType; payload?: TState }
  ) => {
    if (action.type === actionType) {
      return action.payload;
    }
    return state;
  };
}
/**
 * 常用工具方法 - 生成creator
 * helper - generate simple action creator
 * 用法/usage： inc: createToPayload(types.INC)
 */
export function createToPayload<TState, TType = string>(actionType: TType) {
  return (payload: TState) => ({
    type: actionType,
    payload
  });
}

/**
 * Memorize function result, for React Performance optimize
 * **MENTION** Should ONLY used to cache data associate with duck and dispatch, and duck MUST be stateless.
 *
 * 缓存与duck及dispatch关联的数据生成，使得每次输出都是一致的，方便React性能优化。
 * **注意** 仅能用于只和duck与dispatch有关的数据生成，并且duck必须是无状态的（即不可变的）
 *
 * @param {*} fn (duck, dispatch, {refs}) => any
 * @return {Function} memorizedFn (duckComponent | props) => cache
 * @deprecated use `React.useMemo` instead
 *    ```typescript
 *    const handlers = React.useMemo(() => { return {...} }, [duck, dispatch])
 *    ```
 */
export function memorize<T>(
  fn: (duck: any, dispatch: any) => T
): (reactInstanceOrProps: any) => T {
  const cacheKey = "_sagaDuckMemorized";<commit_msg>feat: add resolvePromise for better typings.<commit_after>/**
 * 仅供typescript下使用，将redux-saga的yield select(selector)结果转换为实际类型
 * For typescript only, cast redux-saga yield select(selector) to actual result
 * 用法/usage： const result = asResult(selector, yield select(selector))
 */
export function asResult<T>(fn: (...any: any[]) => T, result: any): T {
  return result;
}

/**
 * 常用工具方法 - 生成reducer
 * helper - generate simple reducer
 * 用法/usage： num : reduceFromPayload(types.SET_NUM, 0)
 */
export function reduceFromPayload<TState, TType = string>(
  actionType: TType,
  initialState: TState
) {
  return (
    state: TState = initialState,
    action: { type: TType; payload?: TState }
  ) => {
    if (action.type === actionType) {
      return action.payload;
    }
    return state;
  };
}
/**
 * 常用工具方法 - 生成creator
 * helper - generate simple action creator
 * 用法/usage： inc: createToPayload(types.INC)
 */
export function createToPayload<TState, TType = string>(actionType: TType) {
  return (payload: TState) => ({
    type: actionType,
    payload
  });
}

/**
 * 用于保留saga中 `yield promise` 调用的返回值
 * 
 * For typescript only, keep result type from promise effect.
 * ```typescript
 * const result = yield *resolvePromise(promise)
 * ```
 * @param promise
 */
export function* resolvePromise<T>(
  promise: Promise<T>
): Generator<any, T, any> {
  return yield promise
}


/**
 * Memorize function result, for React Performance optimize
 * **MENTION** Should ONLY used to cache data associate with duck and dispatch, and duck MUST be stateless.
 *
 * 缓存与duck及dispatch关联的数据生成，使得每次输出都是一致的，方便React性能优化。
 * **注意** 仅能用于只和duck与dispatch有关的数据生成，并且duck必须是无状态的（即不可变的）
 *
 * @param {*} fn (duck, dispatch, {refs}) => any
 * @return {Function} memorizedFn (duckComponent | props) => cache
 * @deprecated use `React.useMemo` instead
 *    ```typescript
 *    const handlers = React.useMemo(() => { return {...} }, [duck, dispatch])
 *    ```
 */
export function memorize<T>(
  fn: (duck: any, dispatch: any) => T
): (reactInstanceOrProps: any) => T {
  const cacheKey = "_sagaDuckMemorized";
{'fraction_non_alphanumeric': 0.14043330723048814, 'fraction_numerical': 0.0005220569042025581, 'mean_word_length': 4.055408970976253, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 30, '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': '53393', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1395, 'n_words': 339}