/
githubmirror
/
taro
Обзор
Документация
Войти
/
githubmirror
/
taro
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/taro-runtime/src/utils/cache.ts
30 строк
598 B
advancedcat
feat(runtime): add history & location bom api
15 сен 2022, 15:10
15 сен 2022, 15:10
e7c764c
Код
Авторство
О чём код?
/** * 一个小型缓存池,用于在切换页面时,存储一些上下文信息 */ export class RuntimeCache<T> { name: string cache = new Map<string, T>() constructor (name: string) { this.name = name } has (identifier: string) { return this.cache.has(identifier) } set (identifier: string, ctx: T) { if (identifier && ctx) { this.cache.set(identifier, ctx) } } get (identifier: string): T | undefined { if (this.has(identifier)) return this.cache.get(identifier) } delete (identifier: string) { this.cache.delete(identifier) } }