ctx-core 5.15.0 → 5.16.1

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.
@@ -1,5 +1,5 @@
1
1
  import type { Be, be_config_T, Ctx, ctx__be_T, ctx__get_T, ctx__set_T, Ctx_wide_T, } from '../be_/index.js'
2
- import { lock_memosig_T } from '../rmemo/index.js'
2
+ import { lock_memosig_T, sig_T } from '../rmemo/index.js'
3
3
  export declare function be_lock_memosig_triple_<
4
4
  val_T,
5
5
  ns_T extends string = '',
@@ -13,9 +13,7 @@ export declare function be_lock_memosig_triple_<
13
13
  ctx_T extends Ctx = Ctx_wide_T<ns_T>,
14
14
  >(
15
15
  rmemo__new:(ctx:ctx_T, memosig:_sig_T)=>val_T,
16
- ...subscriber_a_THEN_config:
17
- |[...((ctx:ctx_T, sig:_sig_T)=>unknown)[]]
18
- |[...((ctx:ctx_T, sig:_sig_T)=>unknown)[], config:be_config_T<ns_T>]
16
+ config?:be_config_T<ns_T>
19
17
  ):be_lock_memosig_triple_T<val_T, ns_T, _sig_T, ctx_T>
20
18
  export type be_lock_memosig_triple_T<
21
19
  val_T,
@@ -26,4 +24,8 @@ export type be_lock_memosig_triple_T<
26
24
  ctx__be_T<ctx_T, _sig_T, ns_T>,
27
25
  ctx__get_T<ctx_T, val_T>,
28
26
  ctx__set_T<ctx_T, val_T>,
29
- ]
27
+ ]&{
28
+ add<add_val_T>(
29
+ add_def:(ctx:ctx_T, sig:_sig_T, prev_val:add_val_T|undefined)=>add_val_T
30
+ ):be_lock_memosig_triple_T<val_T, ns_T, _sig_T, ctx_T>
31
+ }
@@ -6,33 +6,34 @@ import { be_ } from '../be_/index.js'
6
6
  import { lock_memosig_ } from '../rmemo/index.js'
7
7
  /**
8
8
  * @param {Be<sig_T>|be__val__new_T<unknown>}be_OR_val__new
9
- * @param {memo_subscriber_T[]|[...memo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
9
+ * @param {be_config_T}[config]
10
10
  * @returns {be_lock_memosig_triple_T}
11
11
  * @private
12
12
  */
13
13
  export function be_lock_memosig_triple_(
14
14
  be_OR_val__new,
15
- ...subscriber_a_THEN_config
15
+ config
16
16
  ) {
17
- let config =
18
- typeof subscriber_a_THEN_config[subscriber_a_THEN_config.length - 1] === 'object'
19
- ? subscriber_a_THEN_config.pop()
20
- : 0
17
+ let add_def_a = []
21
18
  /** @type {Be<sig_T>} */
22
19
  let be =
23
20
  be_OR_val__new.is_be
24
21
  ? be_OR_val__new
25
22
  : be_(ctx=>
26
- lock_memosig_(
27
- memo=>be_OR_val__new(ctx, memo),
28
- ...subscriber_a_THEN_config.map(subscriber=>
29
- sig=>subscriber(ctx, sig))),
23
+ add_def_a.reduce(
24
+ (memosig, add_def)=>memosig.add((...arg_a)=>add_def(ctx, ...arg_a)),
25
+ lock_memosig_(memo=>be_OR_val__new(ctx, memo))),
30
26
  config)
31
- return [
27
+ let be_lock_memosig_triple = [
32
28
  be,
33
29
  ctx=>be(ctx)(),
34
30
  (ctx, val)=>{
35
31
  be(ctx)._ = val
36
32
  },
37
33
  ]
34
+ be_lock_memosig_triple.add = add_def=>{
35
+ add_def_a.push(add_def)
36
+ return be_lock_memosig_triple
37
+ }
38
+ return be_lock_memosig_triple
38
39
  }
@@ -67,11 +67,11 @@ test('be_lock_memosig_triple_|+id|+ns', ()=>{
67
67
  /* eslint-enable @typescript-eslint/no-unused-vars */
68
68
  return base_(ctx) + 1
69
69
  },
70
- (ctx, foobar$)=>{
71
- subscriber_count++
72
- subscriber_dep__set(ctx, subscriber_count + foobar$())
73
- },
74
- { id: 'foobar', ns: 'test_ns' })
70
+ { id: 'foobar', ns: 'test_ns' }
71
+ ).add((ctx, foobar$)=>{
72
+ subscriber_count++
73
+ subscriber_dep__set(ctx, subscriber_count + foobar$())
74
+ })
75
75
  equal(subscriber_count, 0)
76
76
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
77
77
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
@@ -116,11 +116,12 @@ test('be_lock_memosig_triple_|+be', ()=>{
116
116
  type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
117
117
  /* eslint-enable @typescript-eslint/no-unused-vars */
118
118
  const foobar$ =
119
- memosig_(()=>base_(ctx) + 1,
120
- foobar$=>{
121
- foobar$()
122
- subscriber_count++
123
- }) as custom_sig_T
119
+ memosig_(
120
+ ()=>base_(ctx) + 1
121
+ ).add(foobar$=>{
122
+ foobar$()
123
+ subscriber_count++
124
+ }) as custom_sig_T
124
125
  foobar$.custom = 'custom-val'
125
126
  return foobar$
126
127
  }, { id: 'foobar', ns: 'test_ns' }))
@@ -13,9 +13,7 @@ export declare function be_memo_pair_<
13
13
  ctx_T extends Ctx = Ctx_wide_T<ns_T>
14
14
  >(
15
15
  rmemo__new:(ctx:ctx_T, memo:_memo_T&{ _:val_T })=>val_T,
16
- ...subscriber_a_THEN_config:
17
- |[...((ctx:ctx_T, memosig:sig_T<val_T>)=>unknown)[]]
18
- |[...((ctx:ctx_T, memosig:sig_T<val_T>)=>unknown)[], config:be_config_T]
16
+ config?:be_config_T
19
17
  ):be_memo_pair_T<val_T, ns_T, _memo_T, ctx_T>
20
18
  export type be_memo_pair_T<
21
19
  val_T,
@@ -25,4 +23,8 @@ export type be_memo_pair_T<
25
23
  > = [
26
24
  ctx__be_T<ctx_T, _memo_T, ns_T>,
27
25
  ctx__get_T<ctx_T, val_T>,
28
- ]
26
+ ]&{
27
+ add<add_val_T>(
28
+ add_def:(ctx:ctx_T, sig:sig_T<val_T>, prev_val:add_val_T|undefined)=>add_val_T
29
+ ):be_memo_pair_T<val_T, ns_T, _memo_T, ctx_T>
30
+ }
@@ -5,32 +5,34 @@ import { be_ } from '../be_/index.js'
5
5
  import { memo_ } from '../rmemo/index.js'
6
6
  /**
7
7
  * @param {Be|be__val__new_T<unknown>}be_OR_val__new
8
- * @param {memo_subscriber_T[]|[...memo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
8
+ * @param {be_config_T}[config]
9
9
  * @returns {be_memo_pair_T}
10
10
  * @private
11
11
  */
12
12
  export function be_memo_pair_(
13
13
  be_OR_val__new,
14
- ...subscriber_a_THEN_config
14
+ config
15
15
  ) {
16
- let config =
17
- typeof subscriber_a_THEN_config[subscriber_a_THEN_config.length - 1] === 'object'
18
- && subscriber_a_THEN_config.pop()
16
+ let add_def_a = []
19
17
  /** @type {Be} */
20
18
  let be =
21
19
  be_OR_val__new.is_be
22
20
  ? be_OR_val__new
23
21
  : be_(ctx=>
24
- memo_(
25
- memo=>be_OR_val__new(ctx, memo),
26
- ...subscriber_a_THEN_config.map(subscriber=>
27
- memo=>subscriber(ctx, memo))),
22
+ add_def_a.reduce(
23
+ (memo, add_def)=>memo.add((...arg_a)=>add_def(ctx, ...arg_a)),
24
+ memo_(memo=>be_OR_val__new(ctx, memo))),
28
25
  config)
29
- return [
26
+ let be_memo_pair = [
30
27
  be,
31
28
  ctx=>be(ctx)._,
32
29
  (ctx, val)=>{
33
30
  be(ctx)._ = val
34
31
  },
35
32
  ]
33
+ be_memo_pair.add = add_def=>{
34
+ add_def_a.push(add_def)
35
+ return be_memo_pair
36
+ }
37
+ return be_memo_pair
36
38
  }
@@ -55,15 +55,16 @@ test('be_memo_pair_|+id|+ns|+oninit|+subscriber_a', ()=>{
55
55
  const [
56
56
  foobar$_,
57
57
  foobar_,
58
- ] = be_memo_pair_<number, 'test_ns'>(ctx=>base_(ctx) + 1,
59
- (ctx, foobar$)=>{
60
- /* eslint-disable @typescript-eslint/no-unused-vars */
61
- type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
62
- /* eslint-enable @typescript-eslint/no-unused-vars */
63
- subscriber_count++
64
- subscriber_dep__set(ctx, subscriber_count + foobar$())
65
- },
66
- { id: 'foobar', ns: 'test_ns' })
58
+ ] = be_memo_pair_<number, 'test_ns'>(
59
+ ctx=>base_(ctx) + 1,
60
+ { id: 'foobar', ns: 'test_ns' }
61
+ ).add((ctx, foobar$)=>{
62
+ /* eslint-disable @typescript-eslint/no-unused-vars */
63
+ type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
64
+ /* eslint-enable @typescript-eslint/no-unused-vars */
65
+ subscriber_count++
66
+ subscriber_dep__set(ctx, subscriber_count + foobar$())
67
+ })
67
68
  equal(subscriber_count, 0)
68
69
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
69
70
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
@@ -96,7 +97,7 @@ test('be_memo_pair_|subscriber|receives a memosig to set the value of the memo',
96
97
  type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<''>>>
97
98
  /* eslint-enable @typescript-eslint/no-unused-vars */
98
99
  return 1
99
- }, (ctx, foobar$)=>{
100
+ }).add((ctx, foobar$)=>{
100
101
  foobar$._ = base_(ctx) + 1
101
102
  })
102
103
  equal(foobar$_(ctx)._, 2)
@@ -123,9 +124,8 @@ test('be_memo_pair_|be', ()=>{
123
124
  type test__ctx = Expect<Equal<typeof _ctx, Ctx_wide_T<'test_ns'>>>
124
125
  /* eslint-enable @typescript-eslint/no-unused-vars */
125
126
  const foobar$ = memo_(
126
- ()=>base_(ctx) + 1,
127
- ()=>subscriber_count++
128
- ) as custom_memo_T
127
+ ()=>base_(ctx) + 1
128
+ ).add(()=>subscriber_count++) as custom_memo_T
129
129
  equal(_ctx.s.test_ns, ctx.s.test_ns)
130
130
  foobar$.custom = 'custom-val'
131
131
  return foobar$
@@ -13,9 +13,7 @@ export declare function be_memosig_triple_<
13
13
  ctx_T extends Ctx = Ctx_wide_T<ns_T>
14
14
  >(
15
15
  rmemo__new:(ctx:ctx_T, memosig:_sig_T)=>val_T,
16
- ...subscriber_a_THEN_config:
17
- |[...((ctx:ctx_T, sig:_sig_T)=>unknown)[]]
18
- |[...((ctx:ctx_T, sig:_sig_T)=>unknown)[], config:be_config_T<ns_T>]
16
+ config?:be_config_T<ns_T>
19
17
  ):be_memosig_triple_T<val_T, ns_T, _sig_T, ctx_T>
20
18
  export type be_memosig_triple_T<
21
19
  val_T,
@@ -26,4 +24,8 @@ export type be_memosig_triple_T<
26
24
  ctx__be_T<ctx_T, _sig_T, ns_T>,
27
25
  ctx__get_T<ctx_T, val_T>,
28
26
  ctx__set_T<ctx_T, val_T>,
29
- ]
27
+ ]&{
28
+ add<add_val_T>(
29
+ add_def:(ctx:ctx_T, sig:_sig_T, prev_val:add_val_T|undefined)=>add_val_T
30
+ ):be_memosig_triple_T<val_T, ns_T, _sig_T, ctx_T>
31
+ }
@@ -67,14 +67,14 @@ test('be_memosig_triple_|+id|+ns', ()=>{
67
67
  /* eslint-enable @typescript-eslint/no-unused-vars */
68
68
  return base_(ctx) + 1
69
69
  },
70
- (ctx, foobar$)=>{
71
- /* eslint-disable @typescript-eslint/no-unused-vars */
72
- type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
73
- /* eslint-enable @typescript-eslint/no-unused-vars */
74
- subscriber_count++
75
- subscriber_dep__set(ctx, subscriber_count + foobar$())
76
- },
77
- { id: 'foobar', ns: 'test_ns' })
70
+ { id: 'foobar', ns: 'test_ns' }
71
+ ).add((ctx, foobar$)=>{
72
+ /* eslint-disable @typescript-eslint/no-unused-vars */
73
+ type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
74
+ /* eslint-enable @typescript-eslint/no-unused-vars */
75
+ subscriber_count++
76
+ subscriber_dep__set(ctx, subscriber_count + foobar$())
77
+ })
78
78
  equal(subscriber_count, 0)
79
79
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
80
80
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
@@ -119,11 +119,12 @@ test('be_memosig_triple_|+be', ()=>{
119
119
  type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
120
120
  /* eslint-enable @typescript-eslint/no-unused-vars */
121
121
  const foobar$ =
122
- memosig_(()=>base_(ctx) + 1,
123
- foobar$=>{
124
- foobar$()
125
- subscriber_count++
126
- }) as custom_sig_T
122
+ memosig_(
123
+ ()=>base_(ctx) + 1
124
+ ).add(foobar$=>{
125
+ foobar$()
126
+ subscriber_count++
127
+ }) as custom_sig_T
127
128
  foobar$.custom = 'custom-val'
128
129
  return foobar$
129
130
  }, { id: 'foobar', ns: 'test_ns' }))
@@ -13,17 +13,19 @@ export declare function be_sig_triple_<
13
13
  ctx_T extends Ctx = Ctx_wide_T<ns_T>,
14
14
  >(
15
15
  val__new:(ctx:ctx_T)=>val_T,
16
- ...subscriber_a_THEN_config:
17
- |[...((ctx:ctx_T, sig:_sig_T)=>unknown)[]]
18
- |[...((ctx:ctx_T, sig:_sig_T)=>unknown)[], config:be_config_T<ns_T>]
16
+ config?:be_config_T<ns_T>
19
17
  ):be_sig_triple_T<val_T, ns_T, _sig_T, ctx_T>
20
18
  export type be_sig_triple_T<
21
19
  val_T,
22
- source extends string = '',
20
+ ns_T extends string = '',
23
21
  _sig_T extends sig_T<val_T> = sig_T<val_T>,
24
- ctx_T extends Ctx = Ctx_wide_T<source>
22
+ ctx_T extends Ctx = Ctx_wide_T<ns_T>
25
23
  > = [
26
- ctx__be_T<ctx_T, _sig_T, source>,
24
+ ctx__be_T<ctx_T, _sig_T, ns_T>,
27
25
  ctx__get_T<ctx_T, val_T>,
28
26
  ctx__set_T<ctx_T, val_T>
29
- ]
27
+ ]&{
28
+ add<add_val_T>(
29
+ add_def:(ctx:ctx_T, sig:_sig_T, prev_val:add_val_T|undefined)=>add_val_T
30
+ ):be_sig_triple_T<val_T, ns_T, _sig_T, ctx_T>
31
+ }
@@ -5,32 +5,34 @@ import { be_ } from '../be_/index.js'
5
5
  import { sig_ } from '../rmemo/index.js'
6
6
  /**
7
7
  * @param {Be<sig_T>|be__val__new_T<unknown>}be_OR_val__new
8
- * @param {memo_subscriber_T[]|[...memo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
8
+ * @param {be_config_T}[config]
9
9
  * @returns {be_sig_triple_T}
10
10
  * @private
11
11
  */
12
12
  export function be_sig_triple_(
13
13
  be_OR_val__new,
14
- ...subscriber_a_THEN_config
14
+ config
15
15
  ) {
16
- let config =
17
- typeof subscriber_a_THEN_config[subscriber_a_THEN_config.length - 1] === 'object'
18
- && subscriber_a_THEN_config.pop()
16
+ let add_def_a = []
19
17
  /** @ype {Be<sig_T>} */
20
18
  let be =
21
19
  be_OR_val__new.is_be
22
20
  ? be_OR_val__new
23
21
  : be_(ctx=>
24
- sig_(
25
- be_OR_val__new(ctx),
26
- ...subscriber_a_THEN_config.map(subscriber=>
27
- sig=>subscriber(ctx, sig))),
22
+ add_def_a.reduce(
23
+ (sig, add_def)=>sig.add((...arg_a)=>add_def(ctx, ...arg_a)),
24
+ sig_(be_OR_val__new(ctx))),
28
25
  config)
29
- return [
26
+ let be_sig_triple = [
30
27
  be,
31
28
  ctx=>be(ctx)(),
32
29
  (ctx, val)=>{
33
30
  be(ctx)._ = val
34
31
  },
35
32
  ]
33
+ be_sig_triple.add = add_def=>{
34
+ add_def_a.push(add_def)
35
+ return be_sig_triple
36
+ }
37
+ return be_sig_triple
36
38
  }
@@ -43,11 +43,11 @@ test('be_sig_triple_|+id|+ns', ()=>{
43
43
  type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
44
44
  /* eslint-enable @typescript-eslint/no-unused-vars */
45
45
  return 1
46
- },
47
- (ctx, foobar$)=>{
48
- subscriber_count++
49
- subscriber_dep__set(ctx, subscriber_count + foobar$())
50
- }, { id: 'foobar', ns: 'test_ns' })
46
+ }, { id: 'foobar', ns: 'test_ns' }
47
+ ).add((ctx, foobar$)=>{
48
+ subscriber_count++
49
+ subscriber_dep__set(ctx, subscriber_count + foobar$())
50
+ })
51
51
  equal(subscriber_count, 0)
52
52
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 1)
53
53
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 1)
@@ -78,7 +78,9 @@ test('be_sig_triple_|+be', ()=>{
78
78
  type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
79
79
  /* eslint-enable @typescript-eslint/no-unused-vars */
80
80
  const foobar$ =
81
- sig_(1, ()=>subscriber_count++) as custom_sig_T
81
+ sig_(
82
+ 1
83
+ ).add(()=>subscriber_count++) as custom_sig_T
82
84
  foobar$.custom = 'custom-val'
83
85
  return foobar$ as custom_sig_T
84
86
  }, { id: 'foobar', ns: 'test_ns' }))
@@ -4,6 +4,7 @@ export const [
4
4
  is_development$_,
5
5
  is_development_,
6
6
  ] = be_memo_pair_(ctx=>
7
- NODE_ENV_(ctx) === 'dev' || NODE_ENV_(ctx) === 'development',
7
+ NODE_ENV_(ctx) === 'dev'
8
+ || NODE_ENV_(ctx) === 'development',
8
9
  { id: 'is_development' })
9
10
  export { is_development$_ as is_development__ }
@@ -4,7 +4,8 @@ export const [
4
4
  is_production$_,
5
5
  is_production_,
6
6
  ] = be_memo_pair_(ctx=>
7
- NODE_ENV_(ctx) === 'prod' || NODE_ENV_(ctx) === 'production',
7
+ NODE_ENV_(ctx) === 'prod'
8
+ || NODE_ENV_(ctx) === 'production',
8
9
  { id: 'is_production' })
9
10
  export {
10
11
  is_production$_ as is_production__,
@@ -1,23 +1,11 @@
1
1
  /// <reference lib="es2021" />
2
- export declare function memo_<val_T>(
3
- def:memo_def_T<val_T>,
4
- ...subscriber_a:memo_subscriber_T<val_T>[]
5
- ):memo_T<val_T>
6
- export declare function sig_<val_T>(
7
- init_val:val_T,
8
- ...subscriber_a:memo_subscriber_T<val_T>[]
9
- ):sig_T<val_T>
10
- export declare function memosig_<val_T>(
11
- def:memo_def_T<val_T>,
12
- ...subscriber_a:memo_subscriber_T<val_T>[]
13
- ):sig_T<val_T>
14
- export declare function lock_memosig_<val_T>(
15
- def:memo_def_T<val_T>,
16
- ...subscriber_a:memo_subscriber_T<val_T>[]
17
- ):sig_T<val_T>
2
+ export declare function memo_<val_T>(def:memo_def_T<val_T>):memo_T<val_T>
3
+ export declare function sig_<val_T>(init_val:val_T):sig_T<val_T>
4
+ export declare function memosig_<val_T>(def:memo_def_T<val_T>):sig_T<val_T>
5
+ export declare function lock_memosig_<val_T>(def:memo_def_T<val_T>):sig_T<val_T>
18
6
  export declare function rmemo__on(rmemo:rmemo_T<unknown>):void
19
7
  export declare function rmemo__off(rmemo:rmemo_T<unknown>):void
20
- export declare function rmemo__subscribe(rmemo:rmemo_T<unknown>, listener:()=>unknown):()=>void
8
+ export declare function rmemo__add(rmemo:rmemo_T<unknown>, listener:()=>unknown):()=>void
21
9
  export type rmemo_T<val_T> = memo_T<val_T>|sig_T<val_T>|lock_memosig_T<val_T>
22
10
  export type circular_rmemo_T = circular_memo_T|circular_sig_T|circular_lock_memosig_T
23
11
  export type memo_T<val_T> = (()=>val_T)&{
@@ -25,23 +13,29 @@ export type memo_T<val_T> = (()=>val_T)&{
25
13
  readonly val:val_T
26
14
  r?:WeakRef<()=>val_T>
27
15
  memor:WeakRef<()=>val_T>[]
28
- b?:[unknown, memo_T<unknown>][]
16
+ a?:rmemo_a_T[]
17
+ add<add_val_T>(add_def:(sig:sig_T<val_T>, prev_val:add_val_T|undefined)=>add_val_T):memo_T<val_T>
18
+ }
19
+ export interface circular_memo_T extends memo_T<circular_memo_T> {
29
20
  }
30
- export interface circular_memo_T extends memo_T<circular_memo_T> {}
31
21
  export type sig_T<val_T> = (()=>val_T)&{
32
22
  _:val_T
33
23
  readonly val:val_T
34
24
  r?:WeakRef<()=>val_T>
35
25
  memor:WeakRef<()=>val_T>[]
36
- b?:[unknown, memo_T<unknown>][]
26
+ a?:rmemo_a_T[]
27
+ add<add_val_T>(fn:(sig:sig_T<val_T>, prev_val:add_val_T|undefined)=>add_val_T):sig_T<val_T>
28
+ }
29
+ export interface circular_sig_T extends sig_T<circular_sig_T> {
37
30
  }
38
- export interface circular_sig_T extends sig_T<circular_sig_T> {}
39
31
  export type lock_memosig_T<val_T> = sig_T<val_T>&{
40
32
  lock?:0|1
41
33
  }
42
- export interface circular_lock_memosig_T extends lock_memosig_T<circular_lock_memosig_T> {}
34
+ export interface circular_lock_memosig_T extends lock_memosig_T<circular_lock_memosig_T> {
35
+ }
43
36
  export type rmemo_val_T<sig_T> = sig_T extends { ():infer val_T }
44
37
  ? val_T
45
38
  : unknown
46
39
  export type memo_def_T<val_T> = (sig:sig_T<val_T>)=>val_T
47
- export type memo_subscriber_T<val_T> = (sig:sig_T<val_T>)=>unknown
40
+ export type rmemo_a_T = [memo_T<unknown>, unknown]
41
+ export type rmemo_add_T<val_T, SV> = (sig:sig_T<val_T>, old_val:SV|undefined)=>SV
@@ -5,11 +5,11 @@ let cur_memo
5
5
  let queue = new Set
6
6
  /**
7
7
  * @param {memo_def_T}memo_def
8
- * @param {memo_subscriber_T<unknown>[]}subscriber_a
8
+ * @param {rmemo_add_T<unknown>[]}add_def_a
9
9
  * @returns {memo_T}
10
10
  * @private
11
11
  */
12
- export function memo_(memo_def, ...subscriber_a) {
12
+ export function memo_(memo_def, ...add_def_a) {
13
13
  let memo = ()=>{
14
14
  if (!('val' in memo)) {
15
15
  memo.f()
@@ -17,9 +17,9 @@ export function memo_(memo_def, ...subscriber_a) {
17
17
  if (cur_memo) {
18
18
  if (!memo.memor.includes(cur_memo.r ||= new WeakRef(cur_memo.f))) memo.memor.push(cur_memo.r)
19
19
  if (cur_memo.f.l < memo.f.l + 1) cur_memo.f.l = memo.f.l + 1
20
- // conditional in r calls this r_memo
20
+ // memo is called by cur_memo's conditional execution...next change to memo will notify cur_memo
21
21
  cur_memo.f.s.push(memo)
22
- // prevent this rmemo from GC while cur_memo is still active
22
+ // prevent memo from GC while cur_memo still has a strong reference
23
23
  if (!cur_memo.f.S.includes(memo)) cur_memo.f.S.push(memo)
24
24
  }
25
25
  return memo.val
@@ -27,46 +27,52 @@ export function memo_(memo_def, ...subscriber_a) {
27
27
  Object.defineProperty(memo, '_', {
28
28
  get: memo,
29
29
  set: val=>{
30
- let run_queue
31
30
  if (memo.val !== val) {
32
- run_queue = !queue.size
33
31
  memo.memor = memo.memor.filter(r=>{
34
32
  r = r.deref()
35
- if (r && r.s.includes(memo)) { // if conditional r refresh calls this r_memo, add to queue
33
+ if (r && r.s.includes(memo)) { // if added by cur_memo.f.s.push(memo), add to queue
36
34
  queue.add(r)
37
35
  }
38
36
  return r
39
37
  })
40
38
  }
41
39
  memo.val = val
42
- if (!memo.b) {
43
- memo.b = subscriber_a.map(subscriber=>memo_(()=>subscriber(memo)))
44
- memo.b = memo.b.map(subscriber_memo=>[subscriber_memo(), subscriber_memo])
40
+ if (!memo.a) {
41
+ memo.a = []
42
+ add_def_a.map(memo.add)
45
43
  }
46
- if (run_queue) {
47
- cur_refresh_loop:for (let cur_refresh of queue) {
48
- queue.delete(cur_refresh)
49
- for (let queue_refresh of queue) {
50
- if (cur_refresh.l > queue_refresh.l) {
51
- queue.add(cur_refresh)
52
- continue cur_refresh_loop
53
- }
44
+ cur_refresh_loop:for (let cur_refresh of queue) {
45
+ queue.delete(cur_refresh)
46
+ for (let queue_refresh of queue) {
47
+ if (cur_refresh.l > queue_refresh.l) {
48
+ queue.add(cur_refresh)
49
+ continue cur_refresh_loop
54
50
  }
55
- cur_refresh()
56
51
  }
52
+ cur_refresh()
57
53
  }
58
54
  },
59
55
  })
56
+ memo.add = add_def=>{
57
+ if (memo.a) {
58
+ let pair = [memo_(()=>pair[1] = add_def(memo, pair[1]))]
59
+ memo.a.push(pair)
60
+ pair[0]()
61
+ } else {
62
+ add_def_a.push(add_def)
63
+ }
64
+ return memo
65
+ }
60
66
  memo.f = ()=>{
61
67
  let prev_memo = cur_memo
62
68
  cur_memo = memo
63
- memo.f.s = []
69
+ memo.f.s = [] // reset references in memo_def conditional execution path...see cur_memo.f.s.push(memo)
64
70
  try {
65
71
  memo._ = memo_def(memo)
66
72
  } catch (err) {
67
73
  console.error(err)
68
74
  }
69
- cur_memo = prev_memo // finally is not necessary...catch does not throw
75
+ cur_memo = prev_memo // catch does not throw
70
76
  }
71
77
  memo.f.l = 0
72
78
  memo.f.s = []
@@ -77,16 +83,25 @@ export function memo_(memo_def, ...subscriber_a) {
77
83
  export { memo_ as memosig_ }
78
84
  /**
79
85
  * @param {memo_def_T}memo_def
80
- * @param {memo_subscriber_T<unknown>[]}subscriber_a
86
+ * @param {rmemo_add_T<unknown>[]}subscriber_a
81
87
  * @returns {sig_T}
82
88
  * @private
83
89
  */
84
90
  export function lock_memosig_(memo_def, ...subscriber_a) {
85
- return new Proxy(
91
+ let lock_memosig = new Proxy(
86
92
  /** @type {sig_T} */memo_(memo=>
87
93
  memo.lock ? memo._ : memo_def(memo),
88
94
  ...subscriber_a),
89
95
  {
96
+ get(memo, prop) {
97
+ if (prop === 'add') {
98
+ return (...arg_a)=>{
99
+ memo[prop](...arg_a)
100
+ return lock_memosig
101
+ }
102
+ }
103
+ return memo[prop]
104
+ },
90
105
  set(memo, prop, val) {
91
106
  if (prop === '_') {
92
107
  memo.lock = 1
@@ -95,20 +110,20 @@ export function lock_memosig_(memo_def, ...subscriber_a) {
95
110
  return 1
96
111
  }
97
112
  })
113
+ return lock_memosig
98
114
  }
99
115
  /**
100
116
  * @param {unknown}init_val
101
- * @param {memo_subscriber_T[]}subscriber_a
117
+ * @param {rmemo_add_T[]}add_a
102
118
  * @returns {sig_T}
103
119
  * @private
104
120
  */
105
- export function sig_(init_val, ...subscriber_a) {
106
- return memo_(sig=>{
107
- return 'val' in sig
121
+ export function sig_(init_val, ...add_a) {
122
+ return memo_(sig=>
123
+ 'val' in sig
108
124
  ? sig.val
109
- : init_val
110
- },
111
- ...subscriber_a)
125
+ : init_val,
126
+ ...add_a)
112
127
  }
113
128
  /**
114
129
  * Call the rmemo & enable updates from it's parents.
@@ -132,20 +147,21 @@ export function rmemo__off(rmemo) {
132
147
  }
133
148
  }
134
149
  /**
135
- * Bind reactive listener onto the given memo to prevent GC.
136
- * The listener can autosubscribe to any rmemo.
137
- * Returns an "off" function which deactivates the reactive listener & removes the GC binding from the given memo.
150
+ * Bind reactive add_def onto the given memo to prevent GC.
151
+ * The add_def can autosubscribe to any rmemo.
152
+ * Returns an "off" function which deactivates the reactive add_def & removes the GC binding from the given memo.
138
153
  * @param {rmemo_T}memo
139
- * @param {()=>unknown}listener
154
+ * @param {()=>unknown}add_def
140
155
  * @returns {()=>void}
141
156
  */
142
- export function rmemo__subscribe(memo, listener) {
143
- let listener_memo = memo_(()=>listener())
144
- listener_memo()
145
- memo.b ??= []
146
- memo.b.push(listener_memo)
157
+ export function rmemo__add(memo, add_def) {
158
+ let pair
159
+ memo.add(()=>{
160
+ pair = memo.a[memo.a.length - 1]
161
+ return add_def(memo)
162
+ })
147
163
  return ()=>{
148
- rmemo__off(listener_memo)
149
- memo.b.splice(memo.b.indexOf(listener_memo), 1)
164
+ rmemo__off(pair[0])
165
+ memo.a.splice(memo.a.indexOf(pair), 1)
150
166
  }
151
167
  }
@@ -4,7 +4,7 @@ import { deepStrictEqual } from 'node:assert'
4
4
  import { test } from 'uvu'
5
5
  import { equal } from 'uvu/assert'
6
6
  import { sleep } from '../sleep/index.js'
7
- import { lock_memosig_, memo_, type memo_T, memosig_, rmemo__off, rmemo__on, rmemo__subscribe, sig_ } from './index.js'
7
+ import { lock_memosig_, memo_, type memo_T, memosig_, rmemo__off, rmemo__on, rmemo__add, sig_ } from './index.js'
8
8
  test('memo_|static value', ()=>{
9
9
  let count = 0
10
10
  const memo = memo_(()=>{
@@ -171,23 +171,29 @@ test('sig_|undefined', ()=>{
171
171
  equal(sig(), undefined)
172
172
  equal(memo(), undefined)
173
173
  })
174
- test('rmemo|subscriber|has strong refernce to the return value', ()=>{
174
+ test('rmemo|subscriber|has strong reference to the return value', ()=>{
175
+ const add_arg_aa:[memo_T<number|undefined>, number|undefined][] = []
175
176
  const num$ = sig_<number|undefined>(
176
- undefined,
177
- ()=>99)
178
- equal(num$.b, undefined)
177
+ undefined
178
+ ).add<number>((sig, old_val)=>{
179
+ add_arg_aa.push([sig, old_val])
180
+ return 99
181
+ })
182
+ equal(num$.a, undefined)
183
+ equal(add_arg_aa, [])
179
184
  equal(num$(), undefined)
180
- equal(num$.b![0][0], 99)
185
+ equal(num$.a![0][1], 99)
186
+ equal(add_arg_aa, [[num$, undefined]])
181
187
  })
182
188
  test('sig_|subscriber|notified if sig is set before read', ()=>{
183
189
  let count = 0
184
190
  let subscriber__num:number|undefined = undefined
185
191
  const num$ = sig_<number|undefined>(
186
- undefined,
187
- num$=>{
188
- count++
189
- subscriber__num = num$()
190
- })
192
+ undefined
193
+ ).add(num$=>{
194
+ count++
195
+ subscriber__num = num$()
196
+ })
191
197
  equal(count, 0)
192
198
  equal(subscriber__num, undefined)
193
199
  num$._ = 1
@@ -201,11 +207,11 @@ test('sig_|subscriber|sets sig', ()=>{
201
207
  const base$ = sig_(0)
202
208
  let count = 0
203
209
  const num$ = sig_(
204
- 0,
205
- async num$=>{
206
- count++
207
- num$._ = base$() + 1
208
- })
210
+ 0
211
+ ).add(async num$=>{
212
+ count++
213
+ num$._ = base$() + 1
214
+ })
209
215
  equal(count, 0)
210
216
  equal(num$(), 1)
211
217
  equal(count, 1)
@@ -220,13 +226,13 @@ test('sig_|async subsubscriber|case 1', async ()=>{
220
226
  const id$ = sig_('id-0')
221
227
  let count = 0
222
228
  const user$ = sig_<{ id:string }|null>(
223
- null,
224
- async (_user$)=>{
225
- count++
226
- id$()
227
- const user:{ id:string } = await new Promise(_resolve=>resolve = _resolve)
228
- _user$._ = user
229
- })
229
+ null
230
+ ).add(async (_user$)=>{
231
+ count++
232
+ id$()
233
+ const user:{ id:string } = await new Promise(_resolve=>resolve = _resolve)
234
+ _user$._ = user
235
+ })
230
236
  equal(count, 0)
231
237
  equal(user$(), null)
232
238
  equal(count, 1)
@@ -247,14 +253,15 @@ test('sig_|async subsubscriber|case 2', async ()=>{
247
253
  const b$ = sig_(2)
248
254
  const sleepCycles = 5
249
255
  const taskArgumentsCalls:number[][] = []
250
- const sum$ = sig_<null|number>(null,
251
- async sum$=>{
252
- taskArgumentsCalls.push([a$(), b$()])
253
- for (let i = 0; i < sleepCycles; i++) {
254
- await Promise.resolve()
255
- }
256
- sum$._ = a$() + b$()
257
- })
256
+ const sum$ = sig_<null|number>(
257
+ null
258
+ ).add(async sum$=>{
259
+ taskArgumentsCalls.push([a$(), b$()])
260
+ for (let i = 0; i < sleepCycles; i++) {
261
+ await Promise.resolve()
262
+ }
263
+ sum$._ = a$() + b$()
264
+ })
258
265
  equal(sum$(), null)
259
266
  deepStrictEqual(taskArgumentsCalls, [[1, 2]])
260
267
  a$._ = 10
@@ -303,10 +310,10 @@ test('prevents diamond dependency problem 1', ()=>{
303
310
  const b$ = memo_(()=>a$().replace('a', 'b'))
304
311
  const c$ = memo_(()=>a$().replace('a', 'c'))
305
312
  const d$ = memo_(()=>a$().replace('a', 'd'))
306
- memo_(()=>`${b$()}${c$()}${d$()}`,
307
- combined$=>
308
- values.push(combined$())
309
- )()
313
+ memo_(
314
+ ()=>`${b$()}${c$()}${d$()}`)
315
+ .add(combined$=>values.push(combined$()))
316
+ ()
310
317
  deepStrictEqual(values, ['b0c0d0'])
311
318
  store$._ = 1
312
319
  store$._ = 2
@@ -321,9 +328,9 @@ test('prevents diamond dependency problem 2', ()=>{
321
328
  const d$ = memo_(()=>c$().replace('c', 'd'))
322
329
  const e$ = memo_(()=>d$().replace('d', 'e'))
323
330
  memo_<string>(
324
- ()=>[a$(), e$()].join(''),
325
- $=>values.push($())
326
- )()
331
+ ()=>[a$(), e$()].join(''))
332
+ .add($=>values.push($()))
333
+ ()
327
334
  deepStrictEqual(values, ['a0e0'])
328
335
  store$._ = 1
329
336
  deepStrictEqual(values, ['a0e0', 'a1e1'])
@@ -336,9 +343,9 @@ test('prevents diamond dependency problem 3', ()=>{
336
343
  const c$ = memo_(()=>b$().replace('b', 'c'))
337
344
  const d$ = memo_(()=>c$().replace('c', 'd'))
338
345
  memo_<string>(
339
- ()=>`${a$()}${b$()}${c$()}${d$()}`,
340
- combined$=>values.push(combined$())
341
- )()
346
+ ()=>`${a$()}${b$()}${c$()}${d$()}`)
347
+ .add(combined$=>values.push(combined$()))
348
+ ()
342
349
  deepStrictEqual(values, ['a0b0c0d0'])
343
350
  store$._ = 1
344
351
  deepStrictEqual(values, ['a0b0c0d0', 'a1b1c1d1'])
@@ -355,13 +362,13 @@ test('autosubscribe: prevents diamond dependency problem 4 (complex)', ()=>{
355
362
  const f$ = memo_(()=>`f${e$()}`)
356
363
  const g$ = memo_(()=>`g${f$()}`)
357
364
  memo_(
358
- ()=>e$(),
359
- combined1$=>values.push(combined1$())
360
- )()
365
+ ()=>e$())
366
+ .add(combined1$=>values.push(combined1$()))
367
+ ()
361
368
  memo_(
362
- ()=>[e$(), g$()].join(''),
363
- combined2$=>values.push(combined2$())
364
- )()
369
+ ()=>[e$(), g$()].join(''))
370
+ .add(combined2$=>values.push(combined2$()))
371
+ ()
365
372
  deepStrictEqual(values, ['eca0b0da0', 'eca0b0da0gfeca0b0da0'])
366
373
  store1$._ = 1
367
374
  store2$._ = 2
@@ -408,9 +415,9 @@ test('prevents diamond dependency problem 6', ()=>{
408
415
  const b$ = memo_(()=>`b${store2$()}`)
409
416
  const c$ = memo_(()=>b$().replace('b', 'c'))
410
417
  memo_(
411
- ()=>`${a$()}${c$()}`,
412
- combined$=>values.push(combined$())
413
- )()
418
+ ()=>`${a$()}${c$()}`)
419
+ .add(combined$=>values.push(combined$()))
420
+ ()
414
421
  deepStrictEqual(values, ['a0c0'])
415
422
  store1$._ = 1
416
423
  deepStrictEqual(values, ['a0c0', 'a1c0'])
@@ -421,9 +428,9 @@ test('prevents dependency listeners from being out of order', ()=>{
421
428
  return `${base$()}a`
422
429
  })
423
430
  const values:string[] = []
424
- const b$ = memo_(()=>{
425
- return `${a$()}b`
426
- }, b$=>values.push(b$()))
431
+ const b$ = memo_(
432
+ ()=>`${a$()}b`)
433
+ .add(b$=>values.push(b$()))
427
434
  equal(b$(), '0ab')
428
435
  deepStrictEqual(values, ['0ab'])
429
436
  equal(a$(), '0a')
@@ -462,14 +469,17 @@ test('.rmemo__on + .rmemo__off', ()=>{
462
469
  equal(memo$(), 14)
463
470
  equal(count, 5)
464
471
  })
465
- test('rmemo__subscribe', ()=>{
472
+ test('rmemo__add', ()=>{
466
473
  const base$ = sig_(1)
467
474
  let count = 0
468
475
  const subscriber_base_a:number[] = []
469
- const off = rmemo__subscribe(base$, ()=>{
476
+ const off = rmemo__add(base$, ()=>{
470
477
  count++
471
478
  subscriber_base_a.push(base$())
472
479
  })
480
+ equal(subscriber_base_a, [])
481
+ equal(count, 0)
482
+ base$()
473
483
  equal(subscriber_base_a, [1])
474
484
  equal(count, 1)
475
485
  base$._ = 2
@@ -9,7 +9,7 @@ test('waitfor|success', async ()=>{
9
9
  const promise = waitfor(()=>{
10
10
  count++
11
11
  return ret
12
- }, 10)
12
+ }, 50)
13
13
  .then(returned_value=>{
14
14
  returned_value_a.push(returned_value)
15
15
  return returned_value
@@ -40,7 +40,7 @@ test('waitfor|cancel', async ()=>{
40
40
  const promise = waitfor(()=>{
41
41
  count++
42
42
  return false
43
- }, 10)
43
+ }, 50)
44
44
  equal(count, 1)
45
45
  equal(await promise.cancel(), false)
46
46
  equal(count, 1)
@@ -50,7 +50,7 @@ test('waitfor|cancel', async ()=>{
50
50
  const undefinable_promise = waitfor<boolean|undefined>(()=>{
51
51
  count++
52
52
  return false
53
- }, 10)
53
+ }, 50)
54
54
  equal(count, 1)
55
55
  equal(await undefinable_promise.cancel(undefined), undefined)
56
56
  equal(count, 1)
@@ -63,7 +63,7 @@ test('waitfor|period|number', async ()=>{
63
63
  const promise = waitfor(()=>{
64
64
  count++
65
65
  return ret
66
- }, 10, 2)
66
+ }, 50, 2)
67
67
  try {
68
68
  equal(count, 1)
69
69
  await sleep(2)
@@ -85,7 +85,7 @@ test('waitfor|period|async function', async ()=>{
85
85
  const promise = waitfor(()=>{
86
86
  count++
87
87
  return ret
88
- }, 10, (...arg_a)=>{
88
+ }, 50, (...arg_a)=>{
89
89
  period_arg_aa.push(arg_a)
90
90
  return sleep(2)
91
91
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "5.15.0",
3
+ "version": "5.16.1",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -210,28 +210,28 @@
210
210
  "import": {
211
211
  "./rmemo": "{ memo_ }"
212
212
  },
213
- "limit": "335 B"
213
+ "limit": "355 B"
214
214
  },
215
215
  {
216
216
  "name": "memo_ sig_",
217
217
  "import": {
218
218
  "./rmemo": "{ sig_, memo_ }"
219
219
  },
220
- "limit": "353 B"
220
+ "limit": "377 B"
221
221
  },
222
222
  {
223
223
  "name": "memo_ sig_ be_ ctx_",
224
224
  "import": {
225
225
  "./rmemo": "{ sig_, memo_, be_, ctx_ }"
226
226
  },
227
- "limit": "460 B"
227
+ "limit": "478 B"
228
228
  },
229
229
  {
230
230
  "name": "memo_ sig_ be_ ctx_ be_memo_pair_ be_sig_triple_",
231
231
  "import": {
232
232
  "./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
233
233
  },
234
- "limit": "553 B"
234
+ "limit": "580 B"
235
235
  },
236
236
  {
237
237
  "name": "uuid",
package/rmemo/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { rmemo__off, rmemo__on, rmemo__subscribe } from '../rmemo/index.js'
2
- export { rmemo__off as off, rmemo__on as on, rmemo__subscribe as subscribe }
1
+ import { rmemo__off, rmemo__on, rmemo__add } from '../rmemo/index.js'
2
+ export { rmemo__off as off, rmemo__on as on, rmemo__add as subscribe }
3
3
  export * from '../all/be/index.js'
4
4
  export * from '../all/be_/index.js'
5
5
  export * from '../all/be_lock_memosig_triple/index.js'
package/rmemo/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { rmemo__off, rmemo__on, rmemo__subscribe } from '../rmemo/index.js'
2
- export { rmemo__off as off, rmemo__on as on, rmemo__subscribe as subscribe }
1
+ import { rmemo__off, rmemo__on, rmemo__add } from '../rmemo/index.js'
2
+ export { rmemo__off as off, rmemo__on as on, rmemo__add as subscribe }
3
3
  export * from '../all/be/index.js'
4
4
  export * from '../all/be_/index.js'
5
5
  export * from '../all/be_lock_memosig_triple/index.js'