UNPKG

bixi

Version:

企业级中后台前端解决方案

29 lines (24 loc) 692 B
import { ITokenModel } from '../token/interface'; import { IStore } from './interface'; /** * `localStorage` storage, **not lost after closing the browser**. * * ```ts * { provide: BIXI_STORE_TOKEN, useClass: LocalStorageStore } * ``` */ export class LocalStorageStore implements IStore { get(key: string): ITokenModel { return JSON.parse(localStorage.getItem(key) || '{}') || {}; } set(key: string, value: ITokenModel | null): boolean { localStorage.setItem(key, JSON.stringify(value)); return true; } remove(key: string) { localStorage.removeItem(key); } } export function BIXI_STORE_TOKEN_LOCAL_FACTORY(): IStore { return new LocalStorageStore(); }