本文整理汇总了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;
}
};
示例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}` }),
},
};
});
示例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}` })
}
};
}
示例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
});
});
示例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;
};