ctx-core 4.11.2 → 4.11.4

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.
@@ -2,7 +2,7 @@ export declare const pending_symbol:unique symbol
2
2
  export declare function globalThis__be_<
3
3
  val_T,
4
4
  ctx_T extends Ctx = Ctx
5
- >(val_:be__val__new_T<val_T, ctx_T>):Be<val_T, ctx_T>
5
+ >(id:string|symbol, val_:be__val__new_T<val_T, ctx_T>, config?:be_config_T):Be<val_T, ctx_T>
6
6
  /**
7
7
  * Auto-memoization function for the Ctx.
8
8
  *
package/all/be_/index.js CHANGED
@@ -12,12 +12,16 @@ import { globalThis__prop__ensure } from '../globalThis__prop__ensure/index.js'
12
12
  *
13
13
  * Returns a function to ensure that a member id_OR_val_ is defined on a ctx object,
14
14
  * otherwise it caches & uses the return value of val__new.
15
+ * @param {string|symbol}id
15
16
  * @param {be__val__new_T}val__new
17
+ * @param {be_config_T}[config]
16
18
  * @returns {Be}
17
19
  * @private
18
20
  */
19
- export function globalThis__be_(val__new) {
20
- return globalThis__prop__ensure(Symbol.for(val__new), ()=>be_(val__new)) }
21
+ export function globalThis__be_(id, val__new, config) {
22
+ return globalThis__prop__ensure(id, ()=>
23
+ be_(val__new, { id, ...(config||{}) }))
24
+ }
21
25
  /**
22
26
  * Auto-memoization function for the Ctx.
23
27
  *
@@ -9,10 +9,29 @@ import {
9
9
  type Ctx,
10
10
  ctx__delete,
11
11
  ctx__set,
12
+ globalThis__be_,
12
13
  type MapCtx
13
14
  } from '../be_/index.js'
14
15
  import { ctx__new } from '../ctx/index.js'
15
-
16
+ test.after(()=>{
17
+ delete (globalThis as { root_be?:Be<unknown> }).root_be
18
+ })
19
+ test('globalThis__be_', ()=>{
20
+ const ctx = ctx__new()
21
+ equal(root_be_(), undefined)
22
+ const be = globalThis__be_('root_be', ()=>1)
23
+ equal(root_be_(), be)
24
+ equal(root_be_()!(ctx), 1)
25
+ equal(be(ctx), 1)
26
+ const be2 = globalThis__be_('root_be', ()=>1)
27
+ equal(be2, be)
28
+ equal(root_be_(), be2)
29
+ equal(root_be_()!(ctx), 1)
30
+ equal(be2(ctx), 1)
31
+ function root_be_() {
32
+ return (globalThis as { root_be?:Be<unknown> }).root_be
33
+ }
34
+ })
16
35
  test('be_|Map', ()=>{
17
36
  const ctx = ctx__new()
18
37
  let incrementer_num = 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "4.11.2",
3
+ "version": "4.11.4",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -142,7 +142,7 @@
142
142
  "import": {
143
143
  "./be": "{ be_, ctx_ }"
144
144
  },
145
- "limit": "187 B"
145
+ "limit": "189 B"
146
146
  },
147
147
  {
148
148
  "name": "memo_",