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


TypeScript store.getState函數代碼示例

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


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

示例1: switch

const _getEntityByIDFromStore = (
  entityType: EntityType,
  entityID: string | number
) => {
  if (!entityType || !entityID) {
    return;
  }
  const _store = store.getState();
  const {
    linodes,
    domains,
    nodeBalancers,
    images,
    volumes
  } = _store.__resources;
  switch (entityType) {
    case 'linode':
      return linodes.entities.find(linode => entityID === linode.id);
    case 'image':
      return images.entities.find(image => entityID === image.id);
    case 'nodebalancer':
      return nodeBalancers.itemsById[entityID];
    case 'domain':
      return domains.entities.find(domain => entityID === domain.id);
    case 'volume':
      return volumes.itemsById[entityID];
    default:
      return;
  }
};
開發者ID:linode,項目名稱:manager,代碼行數:30,代碼來源:getEntityByIDFromStore.ts

示例2: path

Axios.interceptors.request.use((config: AxiosRequestConfig): AxiosRequestConfig => {
  const state = store.getState();
  const token = path(['authentication', 'token'], state);

  return {
    ...config,
    headers: {
      ...config.headers,
      ...(token && { Authorization: `Bearer ${token}` }),
    },
  };
});
開發者ID:displague,項目名稱:manager,代碼行數:12,代碼來源:request.ts

示例3: pathOr

  (config: AxiosRequestConfig): AxiosRequestConfig => {
    const state = store.getState();
    /** Will end up being "Admin: 1234" or "Bearer 1234" */
    const token =
      ACCESS_TOKEN || pathOr('', ['authentication', 'token'], state);

    return {
      ...config,
      headers: {
        ...config.headers,
        ...(token && { Authorization: `${token}` })
      }
    };
  }
開發者ID:linode,項目名稱:manager,代碼行數:14,代碼來源:request.ts

示例4: it

 it('should set tokens when setToken is invoked', () => {
   store.dispatch(
     handleStartSession({
       token: 'helloworld',
       scopes: '*',
       expires: 'never'
     })
   );
   expect(store.getState().authentication).toEqual({
     token: 'helloworld',
     scopes: '*',
     expiration: 'never',
     loggedInAsCustomer: false
   });
 });
開發者ID:linode,項目名稱:manager,代碼行數:15,代碼來源:authentication.test.ts

示例5: pathOr

export const formatDate = (
  date: string,
  options: FormatDateOptions = {}
): string => {
  let time;

  /** get the timezone from redux and use it as the moment timezone */
  const reduxProfile = store.getState().__resources.profile;
  const userTimezone = pathOr('GMT', ['data', 'timezone'], reduxProfile);

  try {
    // Unknown error was causing this to crash in rare situations.
    time = moment.utc(date).tz(userTimezone);
  } catch (e) {
    // Better to return a blank date than an error or incorrect information.
    reportException(e);
    return 'Error getting datetime';
  }
  const formattedTime = shouldHumanize(time, options.humanizeCutoff)
    ? time.fromNow()
    : time.format(options.format || ISO_FORMAT);
  return formattedTime;
};
開發者ID:linode,項目名稱:manager,代碼行數:23,代碼來源:formatDate.ts


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