本文整理匯總了TypeScript中@dojo/framework/shim/global.sessionStorage類的典型用法代碼示例。如果您正苦於以下問題:TypeScript sessionStorage類的具體用法?TypeScript sessionStorage怎麽用?TypeScript sessionStorage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了sessionStorage類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: commandFactory
const registerCommand = commandFactory(async ({ get, path }) => {
const requestPayload = {
user: get(path('register'))
};
const response = await fetch(`${baseUrl}/users`, {
method: 'post',
body: JSON.stringify(requestPayload),
headers: getHeaders()
});
const json = await response.json();
if (!response.ok) {
return [
replace(path('register', 'failed'), true),
replace(path('register', 'loading'), false),
replace(path('errors'), json.errors),
replace(path('user'), {})
];
}
global.sessionStorage.setItem('conduit-session', JSON.stringify(json.user));
return [
replace(path('routing', 'outlet'), 'home'),
replace(path('register', 'loading'), false),
replace(path('errors'), undefined),
replace(path('user'), json.user),
replace(path('feed', 'items'), undefined),
replace(path('feed', 'loaded'), false)
];
});
示例2: add
import { getTagsProcess } from './processes/tagProcesses';
import { setSessionProcess } from './processes/loginProcesses';
import { State } from './interfaces';
import config from './routes';
import { changeRouteProcess } from './processes/routeProcesses';
const store = new Store<State>();
let session;
if (!exists("build-time-render")) {
add("build-time-render", false);
}
if (!has('build-time-render')) {
session = global.sessionStorage.getItem('conduit-session');
}
if (session) {
setSessionProcess(store)({ session: JSON.parse(session) });
}
getTagsProcess(store)({});
const registry = registerStoreInjector(store);
const router = registerRouterInjector(config, registry);
router.on('nav', ({ outlet, context }: any) => {
changeRouteProcess(store)({ outlet, context });
});
function onRouteChange() {
const outlet = store.get(store.path('routing', 'outlet'));
const params = store.get(store.path('routing', 'params'));