singleton-manager
Advanced tools
Comparing version 1.6.1 to 1.7.0
@@ -12,3 +12,3 @@ # Tools >> Singleton Manager >> Overview ||10 | ||
⚠️ You need to make SURE that only ONE version of `singleton-manager` is installed. For how see [Non Goals](https://github.com/ing-bank/lion/blob/e89faca25965e6832c1e104862fbb54e6ffb31e6/docs/fundamentals/tools/singleton-manager/#non-goals). | ||
⚠️ You need to make SURE that only ONE version of `singleton-manager` is installed. For how see [Non Goals](https://github.com/ing-bank/lion/blob/40ddf2c2d2d3653f60cf2c4457a4a2ca6f2e868e/docs/fundamentals/tools/singleton-manager/#non-goals). | ||
@@ -163,3 +163,3 @@ ### Example Singleton Users | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/e89faca25965e6832c1e104862fbb54e6ffb31e6/docs/fundamentals/tools/singleton-manager/example-fail/index.md). <br> | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/40ddf2c2d2d3653f60cf2c4457a4a2ca6f2e868e/docs/fundamentals/tools/singleton-manager/example-fail/index.md). <br> | ||
➡️ See [the code](https://github.com/ing-bank/lion/tree/master/docs/fundamentals/tools/singleton-manager/example-fail/demo-app.js). | ||
@@ -207,3 +207,3 @@ | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/e89faca25965e6832c1e104862fbb54e6ffb31e6/docs/fundamentals/tools/singleton-manager/example-success/index.md). <br> | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/40ddf2c2d2d3653f60cf2c4457a4a2ca6f2e868e/docs/fundamentals/tools/singleton-manager/example-success/index.md). <br> | ||
➡️ See [the code](https://github.com/ing-bank/lion/tree/master/docs/fundamentals/tools/singleton-manager/example-success/demo-app.js). | ||
@@ -249,3 +249,3 @@ | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/e89faca25965e6832c1e104862fbb54e6ffb31e6/docs/fundamentals/tools/singleton-manager/example-complex/index.md). <br> | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/40ddf2c2d2d3653f60cf2c4457a4a2ca6f2e868e/docs/fundamentals/tools/singleton-manager/example-complex/index.md). <br> | ||
➡️ See [the code](https://github.com/ing-bank/lion/tree/master/docs/fundamentals/tools/singleton-manager/example-complex/demo-app.js). | ||
@@ -252,0 +252,0 @@ |
{ | ||
"name": "singleton-manager", | ||
"version": "1.6.1", | ||
"version": "1.7.0", | ||
"description": "Manage singletons across multiple major versions so they converge to a single instance", | ||
@@ -38,2 +38,3 @@ "license": "MIT", | ||
"test": "cd ../../ && npm run test:browser -- --group singleton-manager", | ||
"test:node": "mocha test-node", | ||
"types": "wireit" | ||
@@ -40,0 +41,0 @@ }, |
@@ -12,3 +12,3 @@ # Tools >> Singleton Manager >> Overview ||10 | ||
⚠️ You need to make SURE that only ONE version of `singleton-manager` is installed. For how see [Non Goals](https://github.com/ing-bank/lion/blob/e89faca25965e6832c1e104862fbb54e6ffb31e6/docs/fundamentals/tools/singleton-manager/#non-goals). | ||
⚠️ You need to make SURE that only ONE version of `singleton-manager` is installed. For how see [Non Goals](https://github.com/ing-bank/lion/blob/40ddf2c2d2d3653f60cf2c4457a4a2ca6f2e868e/docs/fundamentals/tools/singleton-manager/#non-goals). | ||
@@ -163,3 +163,3 @@ ### Example Singleton Users | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/e89faca25965e6832c1e104862fbb54e6ffb31e6/docs/fundamentals/tools/singleton-manager/example-fail/index.md). <br> | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/40ddf2c2d2d3653f60cf2c4457a4a2ca6f2e868e/docs/fundamentals/tools/singleton-manager/example-fail/index.md). <br> | ||
➡️ See [the code](https://github.com/ing-bank/lion/tree/master/docs/fundamentals/tools/singleton-manager/example-fail/demo-app.js). | ||
@@ -207,3 +207,3 @@ | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/e89faca25965e6832c1e104862fbb54e6ffb31e6/docs/fundamentals/tools/singleton-manager/example-success/index.md). <br> | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/40ddf2c2d2d3653f60cf2c4457a4a2ca6f2e868e/docs/fundamentals/tools/singleton-manager/example-success/index.md). <br> | ||
➡️ See [the code](https://github.com/ing-bank/lion/tree/master/docs/fundamentals/tools/singleton-manager/example-success/demo-app.js). | ||
@@ -249,3 +249,3 @@ | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/e89faca25965e6832c1e104862fbb54e6ffb31e6/docs/fundamentals/tools/singleton-manager/example-complex/index.md). <br> | ||
➡️ See [it on the example page](https://github.com/ing-bank/lion/blob/40ddf2c2d2d3653f60cf2c4457a4a2ca6f2e868e/docs/fundamentals/tools/singleton-manager/example-complex/index.md). <br> | ||
➡️ See [the code](https://github.com/ing-bank/lion/tree/master/docs/fundamentals/tools/singleton-manager/example-complex/demo-app.js). | ||
@@ -252,0 +252,0 @@ |
const sym = Symbol.for('lion::SingletonManagerClassStorage'); | ||
/** | ||
* Allow compatibility with node-js (for ssr). | ||
* In the future, we can just use globalThis directly | ||
* (for now, we're backwards compatible with browsers that still only use window, since we don't know all contexts singleton-manager is used in). | ||
*/ | ||
// eslint-disable-next-line no-undef | ||
const globalThisOrWindow = globalThis || window; | ||
export class SingletonManagerClass { | ||
constructor() { | ||
/** @protected */ | ||
this._map = window[sym] ? window[sym] : (window[sym] = new Map()); | ||
this._map = globalThisOrWindow[sym] | ||
? globalThisOrWindow[sym] | ||
: (globalThisOrWindow[sym] = new Map()); | ||
} | ||
@@ -8,0 +17,0 @@ |
import { expect } from '@open-wc/testing'; | ||
import { runSingletonManagerClassSuite } from '../test-suites/runSingletonManagerClassSuite.suite.js'; | ||
import { SingletonManagerClass } from 'singleton-manager'; | ||
describe('SingletonManagerClass', () => { | ||
it('returns undefined and has false if not set', async () => { | ||
const mngr = new SingletonManagerClass(); | ||
expect(mngr.get('overlays/overlays.js::0.13.x')).to.be.undefined; | ||
expect(mngr.has('overlays/overlays.js::0.13.x')).to.be.false; | ||
}); | ||
it('return value and has true if set', () => { | ||
const mngr = new SingletonManagerClass(); | ||
mngr.set('overlays/overlays.js::0.13.x', 'is-set'); | ||
expect(mngr.get('overlays/overlays.js::0.13.x')).to.equal('is-set'); | ||
expect(mngr.has('overlays/overlays.js::0.13.x')).to.be.true; | ||
// make sure non set values are still correct | ||
expect(mngr.get('overlays/overlays.js::0.14.x')).to.be.undefined; | ||
expect(mngr.has('overlays/overlays.js::0.14.x')).to.be.false; | ||
}); | ||
it('does not override existing keys (e.g. subsequential calls for the same keys are ignored)', () => { | ||
const mngr = new SingletonManagerClass(); | ||
mngr.set('overlays/overlays.js::0.14.x', 'is-set'); | ||
mngr.set('overlays/overlays.js::0.14.x', 'new-set'); | ||
expect(mngr.get('overlays/overlays.js::0.14.x')).to.equal('is-set'); | ||
}); | ||
it('should return the same value with two SingletonManager instances', () => { | ||
const mngr1 = new SingletonManagerClass(); | ||
const mngr2 = new SingletonManagerClass(); | ||
mngr1.set('overlays/overlays.js::0.15.x', 'is-set'); | ||
expect(mngr2.get('overlays/overlays.js::0.15.x')).to.equal('is-set'); | ||
}); | ||
}); | ||
runSingletonManagerClassSuite({ expect }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43939
17
77
1