diff --git a/packages/lib/Context.ts b/packages/lib/Context.ts new file mode 100644 index 0000000..daf861c --- /dev/null +++ b/packages/lib/Context.ts @@ -0,0 +1,13 @@ +const ctx = new Map() + +export const getContext = (k: string) => ctx.get(k) + +export const setContext = (k: string, d: any) => ctx.set(k, d) + +export const withContext = (k: string, d: any, f: () => void) => { + const o = ctx.get(k) + + ctx.set(k, d) + f() + ctx.set(k, o) +} diff --git a/packages/lib/index.ts b/packages/lib/index.ts index cea9ebb..c06caad 100644 --- a/packages/lib/index.ts +++ b/packages/lib/index.ts @@ -1,3 +1,4 @@ +export * from './Context' export * from './Deferred' export * from './Emitter' export * from './Fluent'