当前位置: 首页>>代码示例>>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;未经允许,请勿转载。