@w5s/global-storage
W5S Time manipulation (@w5s/time)
Installation
npm install @w5s/time
Usage
import { globalStorage, useStorage } from '@w5s/global-storage';
export const moduleStorage = useStorage({});
export function main(): void {
const key = Symbol('someId');
function nextId() {
const id = globalStorage.get(key) ?? 0;
globalStorage.set(key, id + 1);
return id;
}
console.log(nextId()); // 0
console.log(nextId()); // 1
console.log(nextId()); // 2
}
License
MIT © Julien Polo julien.polo@gmail.com
Index
Variables
const$storage
constglobalStorage
Get or create a storage Map at globalThis[Symbol.for('@w5s/storage')].
This storage is persistent through hot module reload and shared across modules.
const key = Symbol('someKey');
if (!globalStorage.has(key)) {
globalStorage.set(key, ['foo', 'bar']);
}
globalStorage.get();// ['foo', 'bar']
Symbol for property hosting storage