Debian Codegraph @

uni-global/README.md

raw
1 [![Build status][build-image]][build-url]
2 [![Tests coverage][cov-image]][cov-url]
3 [![npm version][npm-image]][npm-url]
4
5 # uni-global
6
7 ## Global namespace with no global scope pollution
8
9 ### Use case
10
11 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.
12
13 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.
14
15 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.
16
17 ### Example usage:
18
19 ```javascript
20 // No matter how many instances of given module are loaded in the process, they will always end with same context instance
21 const globalContext = require("uni-global")("my-scope-name");
22
23 // globalContext is a plain object, on which needed global data can be stored.
24 globalContext.someSingletonData = ...
25
26 ```
27
28 ### Adapt manually other realm
29
30 If there's a need to adapt other environment realm (e.g. coming from iframe) to share same uni-global directory.
31
32 Register it with `adaptRealm` util as below:
33
34 ```javascript
35 const adaptRealm = require("uni-global/adapt-realm");
36
37 adaptRealm(iFrameWindow); // Pass global object of the other realm
38 ```
39
40 ### Installation
41
42 ```bash
43 npm install uni-global
44 ```
45
46 [build-image]: https://github.com/medikoo/uni-global/workflows/Integrate/badge.svg
47 [build-url]: https://github.com/medikoo/uni-global/actions?query=workflow%3AIntegrate
48 [cov-image]: https://img.shields.io/codecov/c/github/medikoo/uni-global.svg
49 [cov-url]: https://codecov.io/gh/medikoo/uni-global
50 [npm-image]: https://img.shields.io/npm/v/uni-global.svg
51 [npm-url]: https://www.npmjs.com/package/uni-global