uni-global
Global namespace without polluting the global scope
Last updated 5 years ago by medikoo .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install uni-global 
SYNC missed versions from official npm registry.

Build status Tests coverage npm version

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:

// No matter how many instances of given module are loaded in the process, they will always end with same context instance
const globalContext = require("uni-global")("my-scope-name");

// globalContext is a plain object, on which needed global data can be stored.
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); // Pass global object of the other realm

Installation

npm install uni-global

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

1 Versions

  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (14)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |