@dimerapp/context
v2.0.0
Published
Context to be passed around dimer low level libraries
Downloads
13
Readme
Dimer Context
Runtime context for dimer
Dimer is a combination of several small modules, joining together to build the final app. Passing user options from top-level to all these libraries can be daunting and hence a context
is used to read and write runtime values.
At the lowest level, context starts with the basePath
and new values are added, as it is passed through several modules.
Also you can debug the actions taken on the context by defining DEBUG
environment variable.
DEBUG=dimer:context node yourapp.js
Installation
npm i @dimerapp/context
# Yarn
yarn add @dimerapp/context
Usage
const Context = require('@dimerapp/context')
const ctx = new Context(__dirname)
// later pass around other libs
const config = new (require('@dimerapp/config-parser'))(ctx)
const store = new (require('@dimerapp/datastore'))(ctx)
API
The following methods are available to read/write to the context.
constructor(basePath, [distPath = 'dist'])
const ctx = new Context(__dirname, 'dist')
set(lib, key, value)
The lib
option is required for debugging, so that context can log name of the library, which has mutated the state.
ctx.set('config-parser', 'config', value)
get(key)
Get value for a given key. We recommend you not to mutate the return value and instead transform it.
ctx.get('config')
remove(key)
Remove value for a given key
ctx.remove('config')
Change log
The change log can be found in the CHANGELOG.md file.
Contributing
Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.
Authors & License
thetutlage and contributors.
MIT License, see the included MIT file.