@webreflection/utils 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,9 +35,10 @@ resolve(4);
35
35
  boundOnce(Promise).all === all;
36
36
  boundOnce(Promise).resolve === resolve;
37
37
 
38
- // example: do not import or export same module
38
+ // example: always retrieve the first time data/module
39
+ import sticky from '@webreflection/utils/sticky';
39
40
 
40
- import sticky from '@webreflection/utils/sticky-module';
41
+ const [module, known] = sticky('@module/name', { always: 'same' });
41
42
 
42
- export default sticky('@module/name', { always: 'same' });
43
+ export default module;
43
44
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webreflection/utils",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "type": "module",
5
5
  "types": {
6
6
  "./bound-once": "./types/bound-once.d.ts",
@@ -21,9 +21,9 @@
21
21
  "types": "./types/shared-array-buffer.d.ts",
22
22
  "import": "./src/shared-array-buffer.js"
23
23
  },
24
- "./sticky-module": {
25
- "types": "./types/sticky-module.d.ts",
26
- "import": "./src/sticky-module.js"
24
+ "./sticky": {
25
+ "types": "./types/sticky.d.ts",
26
+ "import": "./src/sticky.js"
27
27
  },
28
28
  "./with-resolvers": {
29
29
  "types": "./types/with-resolvers.d.ts",
@@ -35,7 +35,7 @@
35
35
  "bound-once",
36
36
  "bound",
37
37
  "shared-array-buffer",
38
- "sticky-module",
38
+ "sticky",
39
39
  "with-resolvers"
40
40
  ],
41
41
  "scripts": {
package/src/bound-once.js CHANGED
@@ -1,13 +1,11 @@
1
1
  //@ts-check
2
2
 
3
- const $ = Symbol.for('@webreflection/utils/bound-once');
3
+ import sticky from './sticky.js';
4
4
 
5
- // @ts-ignore
6
- const methods = globalThis[$] || Object.defineProperty(
7
- globalThis,
8
- $,
9
- { value: new WeakMap },
10
- )[$];
5
+ const [methods] = sticky(
6
+ '@webreflection/utils/bound-once',
7
+ /** @type {WeakMap<object, Map<string | symbol, (...args: any[]) => unknown>>} */ (new WeakMap),
8
+ );
11
9
 
12
10
  /**
13
11
  * @type {ProxyHandler<any>}
@@ -13,15 +13,12 @@ const { for: symbolFor } = Symbol;
13
13
  * @returns {[T, boolean]} the passed `value` or the previous one as first entry, a boolean indicating if it was known or not
14
14
  */
15
15
  export default (name, value, global = globalThis) => {
16
- /** @type {symbol} */
17
16
  const symbol = symbolFor(name);
18
- const known = symbol in global;
17
+ // @ts-ignore
18
+ const known = global[symbol];
19
19
  return [
20
- known ?
21
- // @ts-ignore
22
- global[symbol] :
23
- // @ts-ignore
24
- defineProperty(global, symbol, { value })[symbol],
25
- known,
20
+ // @ts-ignore
21
+ known ?? defineProperty(global, symbol, { value })[symbol],
22
+ !!known,
26
23
  ];
27
24
  };
File without changes