ac-scope lets you load your resource in the global environment/scope and lets you access it from anywhere in your application while developing.
There are multiple use cases of this package, so that you can use those resources from anywhere in your application while coding:
- Loading and maintaining database connection.
- Logging system can be used in application context it can save you from importing everytime.
- Keeping logged in user details.
- Keeping configuration details which should be loaded in your app once by env files, config jsons, etc .
Please comment for other use cases as well.
- Now you can access your resources directly your
key
(please see the example below) or I have defined a variable nameapplicationContext
. To use, I recommendapplicationContext
to set and get your resource. It is compatible with most of the javascript based framework such as react.js, node.js, etc
- Set value in application context (gloabally) in the form of {key,value}.
- Get value in application context (gloabally).
Using npm:
$ npm install ac-scope
In order to set the variable in the application context, use the following approach:
applicationContext.set("key", "value");
In order to access your resources in the application context using get('key')
method using default keyword applicationContext
, use the following approach:
applicationContext.get("key");
In order to access your resources in the application context using directky key with default keyword applicationContext.key
, use the following approach:
applicationContext.key;
In order to access your resources in the application context using directky key without default keyword key
, use the following approach:
const s = key //using directly `key` saves you from writing `applicationContext` again and again;
You can also free up the space by deleting, for doing use the following approach:
applicationContext.delete("key");
Wonder! what is the source of this variable? It is actually loaded in your global scope when you imported/used this package in your application.
It is wrapper code that uses global variables provided by environment such as browser, node default modules, v8, etc