當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript recompose.withStateHandlers函數代碼示例

本文整理匯總了TypeScript中recompose.withStateHandlers函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript withStateHandlers函數的具體用法?TypeScript withStateHandlers怎麽用?TypeScript withStateHandlers使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了withStateHandlers函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: mapState

const localStorageContainer = <TState, TUpdaters extends StateHandlerMap<TState>, TOutter>(
  mapState: (s: Storage) => TState,
  mapHandlers: (s: Storage) => StateUpdaters<TOutter, TState, TUpdaters>,
  ) => {

  const state = mapState(storage);
  const handlers = mapHandlers(storage);
  return withStateHandlers<TState, TUpdaters, TOutter>(state, handlers);
}
開發者ID:displague,項目名稱:manager,代碼行數:9,代碼來源:localStorage.container.ts

示例2:

import { withStateHandlers } from 'recompose';

interface State {
  editableLabelError: string;
}

interface Handlers {
  resetEditableLabel: () => State;
  setEditableLabelError: (error: string) => State;
  [key: string]: any;
}

export type EditableLabelProps = State & Handlers;

export default withStateHandlers<State, Handlers, { linodeLabel: string }>(
  ({ linodeLabel }) => ({
    editableLabelError: ''
  }),
  {
    resetEditableLabel: (state, { linodeLabel }) => () => ({
      ...state,
      editableLabelError: ''
    }),

    setEditableLabelError: (state, ownProp) => errorText => ({
      ...state,
      editableLabelError: errorText
    })
  }
);
開發者ID:linode,項目名稱:manager,代碼行數:30,代碼來源:editableLabelState.ts

示例3:

  configDrawerOpen: false,
  configDrawerError: undefined,
  configDrawerSelected: undefined,
  configDrawerAction: undefined
};

export type ConfigDrawerProps = State & Handlers;

export default withStateHandlers<State, Handlers & Record<string, any>>(
  initialState,
  {
    openConfigDrawer: state => (_, action: (id: number) => void) => ({
      ...state,
      configDrawerOpen: true,
      configDrawerError: undefined,
      configDrawerSelected: undefined,
      configDrawerAction: action
    }),

    closeConfigDrawer: state => () => ({
      ...state,
      configDrawerOpen: false
    }),

    configDrawerSelectConfig: state => (id: number) => ({
      ...state,
      configDrawerSelected: id
    })
  }
);
開發者ID:linode,項目名稱:manager,代碼行數:30,代碼來源:configDrawerState.ts

示例4: withStateAndHandlers

 *
 *  return (<div>Hello world!</div>)
 * }
 */
const withStateAndHandlers = withStateHandlers<
  LoadingAndErrorState,
  StateAndStateUpdaters,
  {}
>(
  {
    loading: false,
    error: undefined
  },
  {
    setLoadingAndClearErrors: () => () => ({
      loading: true,
      error: undefined
    }),
    setErrorAndClearLoading: () => (error: string) => ({
      loading: false,
      error
    }),
    clearLoadingAndErrors: () => () => ({
      loading: false,
      error: undefined
    })
  }
);

const withLoadingAndError = (Component: any) =>
  withStateAndHandlers(Component);
開發者ID:displague,項目名稱:manager,代碼行數:31,代碼來源:withLoadingAndError.ts

示例5:

  [key: string]: any;
}

export type MutationDrawerProps = State & Handlers;

export default withStateHandlers<State, Handlers>(
  ownProps => ({
    mutationDrawerError: '',
    mutationDrawerLoading: false,
    mutationDrawerOpen: false
  }),
  {
    openMutationDrawer: state => () => ({
      mutationDrawerError: '',
      mutationDrawerLoading: false,
      mutationDrawerOpen: true
    }),

    closeMutationDrawer: state => () => ({
      ...state,
      mutationDrawerOpen: false
    }),

    mutationFailed: state => (error: string) => ({
      mutationDrawerError: error,
      mutationDrawerLoading: false,
      mutationDrawerOpen: true
    })
  }
);
開發者ID:linode,項目名稱:manager,代碼行數:30,代碼來源:mutationDrawerState.ts


注:本文中的recompose.withStateHandlers函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。