uni-global
Global namespace with no global scope pollution
Use case
In modules world, there's possiblity that two different instance of same modules (e.g. installed in different node_modules
) are being run in same process.
If for any reason they need to operate on context instance that's same for the given application or process, then ocassionally introduced multiple installations may break the application.
This module provides interface wich can be used by those to modules to ensure that no matter how many instances of given module are loaded, in all cases they end with same context instance.
Example usage:
const globalContext = require("uni-global")("my-scope-name");
globalContext.someSingletonData = ...
Adapt manually other realm
If there's a need to adapt other environment realm (e.g. coming from iframe) to share same uni-global directory.
Register it with adaptRealm
util as below:
const adaptRealm = require("uni-global/adapt-realm");
adaptRealm(iFrameWindow);
Installation
npm install uni-global