@stormzx/context
v0.1.3
Published
A simple context library using AsyncLocalStorage.
Downloads
4
Readme
Description
This is a simple context library.
Node.js 16.0 or higher is required.
Installation
Installation is done using the
npm install
command:
$ npm install @stormzx/context
Examples:
const {Context} = require('@stormzx/context')
// set something on global context
Context.set('arg', 'at global')
// or
Context.rootStore.set('arg2', 'arg2 at global')
Context.run({arg: 'at context'}, () => {
console.log(Context.get('arg')); // at contxt
console.log(Context.get('arg2')); // arg2 at global
Context.run({arg: 'at context 2'}, () => {
console.log(Context.get('arg')); // at contxt 2
})
})
console.log(Context.get('arg')); // at global