ctx-core 5.16.1 → 5.17.0

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.
@@ -6,23 +6,23 @@ test('batch_queue_(1).add|enqueue 1 at a time & run 1 at a time', async ()=>{
6
6
  const batch_queue = batch_queue_(1)
7
7
  const promise_o_a = [promise_o_(), promise_o_(), promise_o_()]
8
8
  const fn_a = [()=>promise_o_a[0].promise, ()=>promise_o_a[1].promise, ()=>promise_o_a[2].promise]
9
- const ret0_a:any[] = [null, null, null]
10
- const ret1_a:any[] = [null, null, null]
9
+ const ret0_a:unknown[] = [null, null, null]
10
+ const ret1_a:unknown[] = [null, null, null]
11
11
  batch_queue.add(fn_a[0])
12
- .then(([ret0, ret1_p])=>{
13
- ret0_a[0] = ret0
14
- ret1_p.then(ret0=>ret1_a[0] = ret0)
15
- })
12
+ .then(([ret0, ret1_p])=>{
13
+ ret0_a[0] = ret0
14
+ ret1_p.then(ret0=>ret1_a[0] = ret0)
15
+ })
16
16
  batch_queue.add(fn_a[1])
17
- .then(([ret0, ret1_p])=>{
18
- ret0_a[1] = ret0
19
- ret1_p.then(ret1=>ret1_a[1] = ret1)
20
- })
17
+ .then(([ret0, ret1_p])=>{
18
+ ret0_a[1] = ret0
19
+ ret1_p.then(ret1=>ret1_a[1] = ret1)
20
+ })
21
21
  batch_queue.add(fn_a[2])
22
- .then(([ret0, ret1_p])=>{
23
- ret0_a[2] = ret0
24
- ret1_p.then(ret1=>ret1_a[2] = ret1)
25
- })
22
+ .then(([ret0, ret1_p])=>{
23
+ ret0_a[2] = ret0
24
+ ret1_p.then(ret1=>ret1_a[2] = ret1)
25
+ })
26
26
  equal(ret0_a, [null, null, null])
27
27
  equal(ret1_a, [null, null, null])
28
28
  await new Promise(res=>queueMicrotask(()=>res(null)))
@@ -55,23 +55,23 @@ test('batch_queue_(1, 2).add|enqueue 2 at a time & run 1 at a time', async ()=>{
55
55
  const batch_queue = batch_queue_(1, 2)
56
56
  const promise_o_a = [promise_o_(), promise_o_(), promise_o_()]
57
57
  const fn_a = [()=>promise_o_a[0].promise, ()=>promise_o_a[1].promise, ()=>promise_o_a[2].promise]
58
- const ret0_a:any[] = [null, null, null]
59
- const ret1_a:any[] = [null, null, null]
58
+ const ret0_a:unknown[] = [null, null, null]
59
+ const ret1_a:unknown[] = [null, null, null]
60
60
  batch_queue.add(fn_a[0])
61
- .then(([ret0, ret1_p])=>{
62
- ret0_a[0] = ret0
63
- ret1_p.then(ret0=>ret1_a[0] = ret0)
64
- })
61
+ .then(([ret0, ret1_p])=>{
62
+ ret0_a[0] = ret0
63
+ ret1_p.then(ret0=>ret1_a[0] = ret0)
64
+ })
65
65
  batch_queue.add(fn_a[1])
66
- .then(([ret0, ret1_p])=>{
67
- ret0_a[1] = ret0
68
- ret1_p.then(ret1=>ret1_a[1] = ret1)
69
- })
66
+ .then(([ret0, ret1_p])=>{
67
+ ret0_a[1] = ret0
68
+ ret1_p.then(ret1=>ret1_a[1] = ret1)
69
+ })
70
70
  batch_queue.add(fn_a[2])
71
- .then(([ret0, ret1_p])=>{
72
- ret0_a[2] = ret0
73
- ret1_p.then(ret1=>ret1_a[2] = ret1)
74
- })
71
+ .then(([ret0, ret1_p])=>{
72
+ ret0_a[2] = ret0
73
+ ret1_p.then(ret1=>ret1_a[2] = ret1)
74
+ })
75
75
  equal(ret0_a, [null, null, null])
76
76
  equal(ret1_a, [null, null, null])
77
77
  await new Promise(res=>queueMicrotask(()=>res(null)))
@@ -104,23 +104,23 @@ test('batch_queue_(2).add|enqueue 2 at a time & run 2 at a time', async ()=>{
104
104
  const batch_queue = batch_queue_(2)
105
105
  const promise_o_a = [promise_o_(), promise_o_(), promise_o_()]
106
106
  const fn_a = [()=>promise_o_a[0].promise, ()=>promise_o_a[1].promise, ()=>promise_o_a[2].promise]
107
- const ret0_a:any[] = [null, null, null]
108
- const ret1_a:any[] = [null, null, null]
107
+ const ret0_a:unknown[] = [null, null, null]
108
+ const ret1_a:unknown[] = [null, null, null]
109
109
  batch_queue.add(fn_a[0])
110
- .then(([ret0, ret1_p])=>{
111
- ret0_a[0] = ret0
112
- ret1_p.then(ret0=>ret1_a[0] = ret0)
113
- })
110
+ .then(([ret0, ret1_p])=>{
111
+ ret0_a[0] = ret0
112
+ ret1_p.then(ret0=>ret1_a[0] = ret0)
113
+ })
114
114
  batch_queue.add(fn_a[1])
115
- .then(([ret0, ret1_p])=>{
116
- ret0_a[1] = ret0
117
- ret1_p.then(ret1=>ret1_a[1] = ret1)
118
- })
115
+ .then(([ret0, ret1_p])=>{
116
+ ret0_a[1] = ret0
117
+ ret1_p.then(ret1=>ret1_a[1] = ret1)
118
+ })
119
119
  batch_queue.add(fn_a[2])
120
- .then(([ret0, ret1_p])=>{
121
- ret0_a[2] = ret0
122
- ret1_p.then(ret1=>ret1_a[2] = ret1)
123
- })
120
+ .then(([ret0, ret1_p])=>{
121
+ ret0_a[2] = ret0
122
+ ret1_p.then(ret1=>ret1_a[2] = ret1)
123
+ })
124
124
  equal(ret0_a, [null, null, null])
125
125
  equal(ret1_a, [null, null, null])
126
126
  await new Promise(res=>queueMicrotask(()=>res(null)))
@@ -3,7 +3,7 @@ import { equal } from 'uvu/assert'
3
3
  import { be_, type Ctx_wide_T } from '../be_/index.js'
4
4
  import { be_sig_triple_ } from '../be_sig_triple/index.js'
5
5
  import { ctx__new, ns_ctx__new } from '../ctx/index.js'
6
- import { memosig_, type sig_T } from '../rmemo/index.js'
6
+ import { memo_, memosig_, type sig_T } from '../rmemo/index.js'
7
7
  import type { Equal, Expect } from '../test/index.js'
8
8
  import { be_lock_memosig_triple_ } from './index.js'
9
9
  test('be_lock_memosig_triple_', ()=>{
@@ -42,7 +42,7 @@ test('be_lock_memosig_triple_', ()=>{
42
42
  })
43
43
  test('be_lock_memosig_triple_|+id|+ns', ()=>{
44
44
  const ctx = ns_ctx__new('test_ns')
45
- let subscriber_count = 0
45
+ let add_count = 0
46
46
  const [
47
47
  ,
48
48
  base_,
@@ -52,8 +52,8 @@ test('be_lock_memosig_triple_|+id|+ns', ()=>{
52
52
  { ns: 'test_ns' })
53
53
  const [
54
54
  ,
55
- subscriber_dep_,
56
- subscriber_dep__set
55
+ add_dep_,
56
+ add_dep__set
57
57
  ] = be_sig_triple_(()=>1,
58
58
  { ns: 'test_ns' })
59
59
  const [
@@ -68,38 +68,38 @@ test('be_lock_memosig_triple_|+id|+ns', ()=>{
68
68
  return base_(ctx) + 1
69
69
  },
70
70
  { id: 'foobar', ns: 'test_ns' }
71
- ).add((ctx, foobar$)=>{
72
- subscriber_count++
73
- subscriber_dep__set(ctx, subscriber_count + foobar$())
74
- })
75
- equal(subscriber_count, 0)
71
+ ).add((ctx, foobar$)=>memo_(()=>{
72
+ add_count++
73
+ add_dep__set(ctx, add_count + foobar$())
74
+ }))
75
+ equal(add_count, 0)
76
76
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
77
77
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
78
78
  equal(foobar$_(ctx)._, 2)
79
79
  equal(foobar_(ctx), 2)
80
- equal(subscriber_count, 1)
80
+ equal(add_count, 1)
81
81
  equal((ctx.s['test_ns'].get('foobar')![0] as sig_T<number>)._, 2)
82
- equal(subscriber_dep_(ctx), 3)
82
+ equal(add_dep_(ctx), 3)
83
83
  foobar__set(ns_ctx__new(ctx__new(), ctx), 5)
84
84
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 5)
85
85
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 5)
86
86
  equal(foobar$_(ctx)._, 5)
87
87
  equal(foobar_(ctx), 5)
88
88
  equal((ctx.s['test_ns'].get('foobar')![0] as sig_T<number>)._, 5)
89
- equal(subscriber_count, 2)
90
- equal(subscriber_dep_(ctx), 7)
89
+ equal(add_count, 2)
90
+ equal(add_dep_(ctx), 7)
91
91
  base__set(ctx, 2)
92
92
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 5)
93
93
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 5)
94
94
  equal(foobar$_(ctx)._, 5)
95
95
  equal(foobar_(ctx), 5)
96
- equal(subscriber_count, 2)
96
+ equal(add_count, 2)
97
97
  equal((ctx.s['test_ns'].get('foobar')![0] as sig_T<number>)._, 5)
98
- equal(subscriber_dep_(ctx), 7)
98
+ equal(add_dep_(ctx), 7)
99
99
  })
100
100
  test('be_lock_memosig_triple_|+be', ()=>{
101
101
  const ctx = ns_ctx__new('test_ns')
102
- let subscriber_count = 0
102
+ let add_count = 0
103
103
  const [
104
104
  ,
105
105
  base_,
@@ -118,19 +118,20 @@ test('be_lock_memosig_triple_|+be', ()=>{
118
118
  const foobar$ =
119
119
  memosig_(
120
120
  ()=>base_(ctx) + 1
121
- ).add(foobar$=>{
122
- foobar$()
123
- subscriber_count++
124
- }) as custom_sig_T
121
+ ).add(foobar$=>
122
+ memo_(()=>{
123
+ foobar$()
124
+ add_count++
125
+ })) as custom_sig_T
125
126
  foobar$.custom = 'custom-val'
126
127
  return foobar$
127
128
  }, { id: 'foobar', ns: 'test_ns' }))
128
- equal(subscriber_count, 0)
129
+ equal(add_count, 0)
129
130
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
130
131
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
131
132
  equal(foobar$_(ctx)._, 2)
132
133
  equal(foobar_(ctx), 2)
133
- equal(subscriber_count, 1)
134
+ equal(add_count, 1)
134
135
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 2)
135
136
  equal(foobar$_(ctx).custom, 'custom-val')
136
137
  foobar__set(ctx, 5)
@@ -138,7 +139,7 @@ test('be_lock_memosig_triple_|+be', ()=>{
138
139
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 5)
139
140
  equal(foobar$_(ctx)._, 5)
140
141
  equal(foobar_(ctx), 5)
141
- equal(subscriber_count, 2)
142
+ equal(add_count, 2)
142
143
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 5)
143
144
  equal(foobar$_(ctx).custom, 'custom-val')
144
145
  base__set(ns_ctx__new(ctx__new(), ctx), 2)
@@ -148,7 +149,7 @@ test('be_lock_memosig_triple_|+be', ()=>{
148
149
  equal(foobar_(ctx), 3)
149
150
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 3)
150
151
  equal(foobar$_(ctx).custom, 'custom-val')
151
- equal(subscriber_count, 3)
152
+ equal(add_count, 3)
152
153
  })
153
154
  test.run()
154
155
  type custom_sig_T = sig_T<number>&{
@@ -3,8 +3,7 @@ import { equal } from 'uvu/assert'
3
3
  import { be_, type Ctx_wide_T } from '../be_/index.js'
4
4
  import { be_sig_triple_ } from '../be_sig_triple/index.js'
5
5
  import { ctx__new, ns_ctx__new } from '../ctx/index.js'
6
- import type { memo_T, sig_T } from '../rmemo/index.js'
7
- import { memo_ } from '../rmemo/index.js'
6
+ import { memo_, type memo_T } from '../rmemo/index.js'
8
7
  import type { Equal, Expect } from '../test/index.js'
9
8
  import { be_memo_pair_ } from './index.js'
10
9
  test('be_memo_pair_', ()=>{
@@ -16,7 +15,7 @@ test('be_memo_pair_', ()=>{
16
15
  const [
17
16
  foobar$_,
18
17
  foobar_,
19
- ] = be_memo_pair_<number, '', sig_T<number>&{ count:number }>((
18
+ ] = be_memo_pair_<number, '', memo_T<number>&{ count:number }>((
20
19
  _ctx,
21
20
  foobar$
22
21
  )=>{
@@ -37,13 +36,13 @@ test('be_memo_pair_', ()=>{
37
36
  equal(foobar_(ctx), 3)
38
37
  equal(foobar$_(ctx).count, 2)
39
38
  })
40
- test('be_memo_pair_|+id|+ns|+oninit|+subscriber_a', ()=>{
39
+ test('be_memo_pair_|+id|+ns|+oninit|+add', ()=>{
41
40
  const ctx = ns_ctx__new('test_ns')
42
- let subscriber_count = 0
41
+ let add_count = 0
43
42
  const [
44
43
  ,
45
- subscriber_dep_,
46
- subscriber_dep__set
44
+ add_dep_,
45
+ add_dep__set
47
46
  ] = be_sig_triple_(()=>1,
48
47
  { ns: 'test_ns' })
49
48
  const [
@@ -58,31 +57,31 @@ test('be_memo_pair_|+id|+ns|+oninit|+subscriber_a', ()=>{
58
57
  ] = be_memo_pair_<number, 'test_ns'>(
59
58
  ctx=>base_(ctx) + 1,
60
59
  { id: 'foobar', ns: 'test_ns' }
61
- ).add((ctx, foobar$)=>{
60
+ ).add((ctx, foobar$)=>memo_(()=>{
62
61
  /* eslint-disable @typescript-eslint/no-unused-vars */
63
62
  type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
64
63
  /* eslint-enable @typescript-eslint/no-unused-vars */
65
- subscriber_count++
66
- subscriber_dep__set(ctx, subscriber_count + foobar$())
67
- })
68
- equal(subscriber_count, 0)
64
+ add_count++
65
+ add_dep__set(ctx, add_count + foobar$())
66
+ }))
67
+ equal(add_count, 0)
69
68
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
70
69
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
71
70
  equal(foobar$_(ctx)._, 2)
72
71
  equal(foobar_(ctx), 2)
73
72
  equal((ctx.s.test_ns.get('foobar')![0] as memo_T<number>)._, 2)
74
- equal(subscriber_count, 1)
75
- equal(subscriber_dep_(ctx), 3)
73
+ equal(add_count, 1)
74
+ equal(add_dep_(ctx), 3)
76
75
  base__set(ctx, 2)
77
76
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 3)
78
77
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 3)
79
78
  equal(foobar$_(ctx)._, 3)
80
79
  equal(foobar_(ctx), 3)
81
80
  equal((ctx.s.test_ns.get('foobar')![0] as memo_T<number>)._, 3)
82
- equal(subscriber_count, 2)
83
- equal(subscriber_dep_(ctx), 5)
81
+ equal(add_count, 2)
82
+ equal(add_dep_(ctx), 5)
84
83
  })
85
- test('be_memo_pair_|subscriber|receives a memosig to set the value of the memo', ()=>{
84
+ test('be_memo_pair_|add|receives a memosig to set the value of the memo', ()=>{
86
85
  const ctx = ctx__new()
87
86
  const [
88
87
  ,
@@ -97,9 +96,9 @@ test('be_memo_pair_|subscriber|receives a memosig to set the value of the memo',
97
96
  type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<''>>>
98
97
  /* eslint-enable @typescript-eslint/no-unused-vars */
99
98
  return 1
100
- }).add((ctx, foobar$)=>{
99
+ }).add((ctx, foobar$)=>memo_(()=>{
101
100
  foobar$._ = base_(ctx) + 1
102
- })
101
+ }))
103
102
  equal(foobar$_(ctx)._, 2)
104
103
  equal(foobar_(ctx), 2)
105
104
  base__set(ctx, 2)
@@ -108,7 +107,7 @@ test('be_memo_pair_|subscriber|receives a memosig to set the value of the memo',
108
107
  })
109
108
  test('be_memo_pair_|be', ()=>{
110
109
  const ctx = ns_ctx__new('test_ns')
111
- let subscriber_count = 0
110
+ let add_count = 0
112
111
  const [
113
112
  ,
114
113
  base_,
@@ -125,7 +124,7 @@ test('be_memo_pair_|be', ()=>{
125
124
  /* eslint-enable @typescript-eslint/no-unused-vars */
126
125
  const foobar$ = memo_(
127
126
  ()=>base_(ctx) + 1
128
- ).add(()=>subscriber_count++) as custom_memo_T
127
+ ).add(()=>add_count++) as custom_memo_T
129
128
  equal(_ctx.s.test_ns, ctx.s.test_ns)
130
129
  foobar$.custom = 'custom-val'
131
130
  return foobar$
@@ -133,14 +132,14 @@ test('be_memo_pair_|be', ()=>{
133
132
  id: 'foobar',
134
133
  ns: 'test_ns',
135
134
  }))
136
- equal(subscriber_count, 0)
135
+ equal(add_count, 0)
137
136
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
138
137
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
139
138
  equal(foobar$_(ctx)._, 2)
140
139
  equal(foobar_(ctx), 2)
141
140
  equal((ctx.s.test_ns.get('foobar')![0] as memo_T<number>)._, 2)
142
141
  equal(foobar$_(ctx).custom, 'custom-val')
143
- equal(subscriber_count, 1)
142
+ equal(add_count, 1)
144
143
  base__set(ctx, 2)
145
144
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 3)
146
145
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 3)
@@ -148,7 +147,7 @@ test('be_memo_pair_|be', ()=>{
148
147
  equal(foobar_(ctx), 3)
149
148
  equal((ctx.s.test_ns.get('foobar')![0] as memo_T<number>)._, 3)
150
149
  equal(foobar$_(ctx).custom, 'custom-val')
151
- equal(subscriber_count, 1)
150
+ equal(add_count, 1)
152
151
  })
153
152
  test.run()
154
- type custom_memo_T = sig_T<number>&{ custom:string }
153
+ type custom_memo_T = memo_T<number>&{ custom:string }
@@ -3,7 +3,7 @@ import { equal } from 'uvu/assert'
3
3
  import { be_, type Ctx_wide_T } from '../be_/index.js'
4
4
  import { be_sig_triple_ } from '../be_sig_triple/index.js'
5
5
  import { ctx__new, ns_ctx__new } from '../ctx/index.js'
6
- import { memosig_, type sig_T } from '../rmemo/index.js'
6
+ import { memo_, memosig_, type sig_T } from '../rmemo/index.js'
7
7
  import type { Equal, Expect } from '../test/index.js'
8
8
  import { be_memosig_triple_ } from './index.js'
9
9
  test('be_memosig_triple_', ()=>{
@@ -42,7 +42,7 @@ test('be_memosig_triple_', ()=>{
42
42
  })
43
43
  test('be_memosig_triple_|+id|+ns', ()=>{
44
44
  const ctx = ns_ctx__new('test_ns')
45
- let subscriber_count = 0
45
+ let add_count = 0
46
46
  const [
47
47
  ,
48
48
  base_,
@@ -52,8 +52,8 @@ test('be_memosig_triple_|+id|+ns', ()=>{
52
52
  { ns: 'test_ns' })
53
53
  const [
54
54
  ,
55
- subscriber_dep_,
56
- subscriber_dep__set
55
+ add_dep_,
56
+ add_dep__set
57
57
  ] = be_sig_triple_(()=>1,
58
58
  { ns: 'test_ns' })
59
59
  const [
@@ -68,41 +68,41 @@ test('be_memosig_triple_|+id|+ns', ()=>{
68
68
  return base_(ctx) + 1
69
69
  },
70
70
  { id: 'foobar', ns: 'test_ns' }
71
- ).add((ctx, foobar$)=>{
71
+ ).add((ctx, foobar$)=>memo_(()=>{
72
72
  /* eslint-disable @typescript-eslint/no-unused-vars */
73
73
  type test_ctx = Expect<Equal<typeof ctx, Ctx_wide_T<'test_ns'>>>
74
74
  /* eslint-enable @typescript-eslint/no-unused-vars */
75
- subscriber_count++
76
- subscriber_dep__set(ctx, subscriber_count + foobar$())
77
- })
78
- equal(subscriber_count, 0)
75
+ add_count++
76
+ add_dep__set(ctx, add_count + foobar$())
77
+ }))
78
+ equal(add_count, 0)
79
79
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
80
80
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
81
81
  equal(foobar$_(ctx)._, 2)
82
82
  equal(foobar_(ctx), 2)
83
- equal(subscriber_count, 1)
83
+ equal(add_count, 1)
84
84
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 2)
85
- equal(subscriber_dep_(ctx), 3)
85
+ equal(add_dep_(ctx), 3)
86
86
  foobar__set(ns_ctx__new(ctx__new(), ctx), 5)
87
87
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 5)
88
88
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 5)
89
89
  equal(foobar$_(ctx)._, 5)
90
90
  equal(foobar_(ctx), 5)
91
91
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 5)
92
- equal(subscriber_count, 2)
93
- equal(subscriber_dep_(ctx), 7)
92
+ equal(add_count, 2)
93
+ equal(add_dep_(ctx), 7)
94
94
  base__set(ctx, 2)
95
95
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 3)
96
96
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 3)
97
97
  equal(foobar$_(ctx)._, 3)
98
98
  equal(foobar_(ctx), 3)
99
- equal(subscriber_count, 3)
99
+ equal(add_count, 3)
100
100
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 3)
101
- equal(subscriber_dep_(ctx), 6)
101
+ equal(add_dep_(ctx), 6)
102
102
  })
103
103
  test('be_memosig_triple_|+be', ()=>{
104
104
  const ctx = ns_ctx__new('test_ns')
105
- let subscriber_count = 0
105
+ let add_count = 0
106
106
  const [
107
107
  ,
108
108
  base_,
@@ -121,19 +121,20 @@ test('be_memosig_triple_|+be', ()=>{
121
121
  const foobar$ =
122
122
  memosig_(
123
123
  ()=>base_(ctx) + 1
124
- ).add(foobar$=>{
125
- foobar$()
126
- subscriber_count++
127
- }) as custom_sig_T
124
+ ).add(foobar$=>
125
+ memo_(()=>{
126
+ foobar$()
127
+ add_count++
128
+ })) as custom_sig_T
128
129
  foobar$.custom = 'custom-val'
129
130
  return foobar$
130
131
  }, { id: 'foobar', ns: 'test_ns' }))
131
- equal(subscriber_count, 0)
132
+ equal(add_count, 0)
132
133
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
133
134
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
134
135
  equal(foobar$_(ctx)._, 2)
135
136
  equal(foobar_(ctx), 2)
136
- equal(subscriber_count, 1)
137
+ equal(add_count, 1)
137
138
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 2)
138
139
  equal(foobar$_(ctx).custom, 'custom-val')
139
140
  foobar__set(ctx, 5)
@@ -141,7 +142,7 @@ test('be_memosig_triple_|+be', ()=>{
141
142
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 5)
142
143
  equal(foobar$_(ctx)._, 5)
143
144
  equal(foobar_(ctx), 5)
144
- equal(subscriber_count, 2)
145
+ equal(add_count, 2)
145
146
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 5)
146
147
  equal(foobar$_(ctx).custom, 'custom-val')
147
148
  base__set(ns_ctx__new(ctx__new(), ctx), 2)
@@ -151,7 +152,7 @@ test('be_memosig_triple_|+be', ()=>{
151
152
  equal(foobar_(ctx), 3)
152
153
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 3)
153
154
  equal(foobar$_(ctx).custom, 'custom-val')
154
- equal(subscriber_count, 3)
155
+ equal(add_count, 3)
155
156
  })
156
157
  test.run()
157
158
  type custom_sig_T = sig_T<number>&{
@@ -26,6 +26,6 @@ export type be_sig_triple_T<
26
26
  ctx__set_T<ctx_T, val_T>
27
27
  ]&{
28
28
  add<add_val_T>(
29
- add_def:(ctx:ctx_T, sig:_sig_T, prev_val:add_val_T|undefined)=>add_val_T
29
+ add_def:(ctx:ctx_T, sig:_sig_T)=>add_val_T
30
30
  ):be_sig_triple_T<val_T, ns_T, _sig_T, ctx_T>
31
31
  }
@@ -2,7 +2,7 @@ import { test } from 'uvu'
2
2
  import { equal } from 'uvu/assert'
3
3
  import { be_, type Ctx_wide_T } from '../be_/index.js'
4
4
  import { ctx__new, ns_ctx__new } from '../ctx/index.js'
5
- import { sig_, type sig_T } from '../rmemo/index.js'
5
+ import { memo_, sig_, type sig_T } from '../rmemo/index.js'
6
6
  import type { Equal, Expect } from '../test/index.js'
7
7
  import { be_sig_triple_ } from './index.js'
8
8
  test('be_sig_triple_', ()=>{
@@ -26,11 +26,11 @@ test('be_sig_triple_', ()=>{
26
26
  })
27
27
  test('be_sig_triple_|+id|+ns', ()=>{
28
28
  const ctx = ns_ctx__new('test_ns')
29
- let subscriber_count = 0
29
+ let add_count = 0
30
30
  const [
31
31
  ,
32
- subscriber_dep_,
33
- subscriber_dep__set
32
+ add_dep_,
33
+ add_dep__set
34
34
  ] = be_sig_triple_(()=>1,
35
35
  { ns: 'test_ns' })
36
36
  const [
@@ -44,17 +44,17 @@ test('be_sig_triple_|+id|+ns', ()=>{
44
44
  /* eslint-enable @typescript-eslint/no-unused-vars */
45
45
  return 1
46
46
  }, { id: 'foobar', ns: 'test_ns' }
47
- ).add((ctx, foobar$)=>{
48
- subscriber_count++
49
- subscriber_dep__set(ctx, subscriber_count + foobar$())
50
- })
51
- equal(subscriber_count, 0)
47
+ ).add((ctx, foobar$)=>memo_(()=>{
48
+ add_count++
49
+ add_dep__set(ctx, add_count + foobar$())
50
+ }))
51
+ equal(add_count, 0)
52
52
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 1)
53
53
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 1)
54
54
  equal(foobar$_(ctx)._, 1)
55
55
  equal(foobar_(ctx), 1)
56
- equal(subscriber_count, 1)
57
- equal(subscriber_dep_(ctx), 2)
56
+ equal(add_count, 1)
57
+ equal(add_dep_(ctx), 2)
58
58
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 1)
59
59
  foobar__set(ns_ctx__new(ctx__new(), ctx), 2)
60
60
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 2)
@@ -62,12 +62,12 @@ test('be_sig_triple_|+id|+ns', ()=>{
62
62
  equal(foobar$_(ctx)._, 2)
63
63
  equal(foobar_(ctx), 2)
64
64
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 2)
65
- equal(subscriber_count, 2)
66
- equal(subscriber_dep_(ctx), 4)
65
+ equal(add_count, 2)
66
+ equal(add_dep_(ctx), 4)
67
67
  })
68
68
  test('be_sig_triple_|+be', ()=>{
69
69
  const ctx = ns_ctx__new('test_ns')
70
- let subscriber_count = 0
70
+ let add_count = 0
71
71
  const [
72
72
  foobar$_,
73
73
  foobar_,
@@ -80,16 +80,16 @@ test('be_sig_triple_|+be', ()=>{
80
80
  const foobar$ =
81
81
  sig_(
82
82
  1
83
- ).add(()=>subscriber_count++) as custom_sig_T
83
+ ).add(()=>add_count++) as custom_sig_T
84
84
  foobar$.custom = 'custom-val'
85
85
  return foobar$ as custom_sig_T
86
86
  }, { id: 'foobar', ns: 'test_ns' }))
87
- equal(subscriber_count, 0)
87
+ equal(add_count, 0)
88
88
  equal(foobar$_(ns_ctx__new(ctx__new(), ctx))._, 1)
89
89
  equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 1)
90
90
  equal(foobar$_(ctx)._, 1)
91
91
  equal(foobar_(ctx), 1)
92
- equal(subscriber_count, 1)
92
+ equal(add_count, 1)
93
93
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 1)
94
94
  equal(foobar$_(ctx).custom, 'custom-val')
95
95
  foobar__set(ns_ctx__new(ctx__new(), ctx), 2)
@@ -99,7 +99,7 @@ test('be_sig_triple_|+be', ()=>{
99
99
  equal(foobar_(ctx), 2)
100
100
  equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)._, 2)
101
101
  equal(foobar$_(ctx).custom, 'custom-val')
102
- equal(subscriber_count, 1)
102
+ equal(add_count, 1)
103
103
  })
104
104
  test.run()
105
105
  type custom_sig_T = sig_T<number>&{
@@ -3,28 +3,36 @@ export declare function memo_<val_T>(def:memo_def_T<val_T>):memo_T<val_T>
3
3
  export declare function sig_<val_T>(init_val:val_T):sig_T<val_T>
4
4
  export declare function memosig_<val_T>(def:memo_def_T<val_T>):sig_T<val_T>
5
5
  export declare function lock_memosig_<val_T>(def:memo_def_T<val_T>):sig_T<val_T>
6
- export declare function rmemo__on(rmemo:rmemo_T<unknown>):void
7
- export declare function rmemo__off(rmemo:rmemo_T<unknown>):void
8
- export declare function rmemo__add(rmemo:rmemo_T<unknown>, listener:()=>unknown):()=>void
6
+ export declare function rmemo__on<val_T>(rmemo:rmemo_T<val_T>, off_fn?:(rmemo:rmemo_T<val_T>)=>unknown):void
7
+ export declare function rmemo__off<val_T>(rmemo:rmemo_T<val_T>):void
8
+ export declare function rmemo__off__add<val_T>(rmemo:rmemo_T<val_T>, off_fn:(rmemo:rmemo_T<val_T>)=>unknown):void
9
+ export declare function rmemo__add<val_T, listener_val_T>(
10
+ rmemo:rmemo_T<val_T>,
11
+ listener:(sig:sig_T<val_T>)=>listener_val_T
12
+ ):()=>void
9
13
  export type rmemo_T<val_T> = memo_T<val_T>|sig_T<val_T>|lock_memosig_T<val_T>
10
14
  export type circular_rmemo_T = circular_memo_T|circular_sig_T|circular_lock_memosig_T
11
15
  export type memo_T<val_T> = (()=>val_T)&{
12
16
  readonly _:val_T
17
+ readonly a?:rmemo_a_T[]
18
+ readonly f?:rmemo_f_T
19
+ readonly s?:rmemo_r_T
20
+ readonly t:rmemo_r_T[]
13
21
  readonly val:val_T
14
- r?:WeakRef<()=>val_T>
15
- memor:WeakRef<()=>val_T>[]
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>
22
+ add<add_val_T>(add_def:rmemo_add_def_T<val_T, add_val_T>):memo_T<val_T>
23
+ memo_<_val_T>(def:memo_def_T<_val_T>):memo_T<_val_T>
18
24
  }
19
25
  export interface circular_memo_T extends memo_T<circular_memo_T> {
20
26
  }
21
27
  export type sig_T<val_T> = (()=>val_T)&{
22
28
  _:val_T
29
+ readonly a?:rmemo_a_T
30
+ readonly f?:rmemo_f_T
31
+ readonly s?:rmemo_r_T
32
+ readonly t:rmemo_r_T[]
23
33
  readonly val:val_T
24
- r?:WeakRef<()=>val_T>
25
- memor:WeakRef<()=>val_T>[]
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>
34
+ add<add_val_T>(fn:rmemo_add_def_T<val_T, add_val_T>):sig_T<val_T>
35
+ memo_<_val_T>(def:memo_def_T<_val_T>):memo_T<_val_T>
28
36
  }
29
37
  export interface circular_sig_T extends sig_T<circular_sig_T> {
30
38
  }
@@ -37,5 +45,11 @@ export type rmemo_val_T<sig_T> = sig_T extends { ():infer val_T }
37
45
  ? val_T
38
46
  : unknown
39
47
  export type memo_def_T<val_T> = (sig:sig_T<val_T>)=>val_T
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
48
+ export type rmemo_a_T = unknown[]
49
+ export type rmemo_add_def_T<val_T, add_val_T> = (sig:sig_T<val_T>)=>add_val_T
50
+ export type rmemo_f_T = (()=>void)&{
51
+ readonly l:number
52
+ readonly s:rmemo_T<unknown>[]
53
+ readonly t:rmemo_T<unknown>[]
54
+ }
55
+ export type rmemo_r_T = WeakRef<rmemo_f_T>&{ readonly d?: ()=>rmemo_f_T }
@@ -1,26 +1,31 @@
1
1
  /// <reference types="./index.d.ts" />
2
- /** @type {WeakRef<memo_T>} */
2
+ /** @type {memo_T} */
3
3
  let cur_memo
4
- /** @type {Set<()=>unknown>} */
4
+ /** @type {Set<(()=>unknown)&{ l:number }>} */
5
5
  let queue = new Set
6
6
  /**
7
7
  * @param {memo_def_T}memo_def
8
- * @param {rmemo_add_T<unknown>[]}add_def_a
8
+ * @param {rmemo_add_def_T}add_def_a
9
9
  * @returns {memo_T}
10
10
  * @private
11
11
  */
12
12
  export function memo_(memo_def, ...add_def_a) {
13
+ /** @type {memo_T} */
13
14
  let memo = ()=>{
14
15
  if (!('val' in memo)) {
15
16
  memo.f()
16
17
  }
17
18
  if (cur_memo) {
18
- if (!memo.memor.includes(cur_memo.r ||= new WeakRef(cur_memo.f))) memo.memor.push(cur_memo.r)
19
+ if (!memo.t.includes(
20
+ cur_memo.s ||= new WeakRef(cur_memo.f)
21
+ )) {
22
+ memo.t.push(cur_memo.s)
23
+ }
19
24
  if (cur_memo.f.l < memo.f.l + 1) cur_memo.f.l = memo.f.l + 1
20
25
  // memo is called by cur_memo's conditional execution...next change to memo will notify cur_memo
21
26
  cur_memo.f.s.push(memo)
22
27
  // prevent memo from GC while cur_memo still has a strong reference
23
- if (!cur_memo.f.S.includes(memo)) cur_memo.f.S.push(memo)
28
+ if (!cur_memo.f.t.includes(memo)) cur_memo.f.t.push(memo)
24
29
  }
25
30
  return memo.val
26
31
  }
@@ -28,7 +33,7 @@ export function memo_(memo_def, ...add_def_a) {
28
33
  get: memo,
29
34
  set: val=>{
30
35
  if (memo.val !== val) {
31
- memo.memor = memo.memor.filter(r=>{
36
+ memo.t = memo.t.filter(r=>{
32
37
  r = r.deref()
33
38
  if (r && r.s.includes(memo)) { // if added by cur_memo.f.s.push(memo), add to queue
34
39
  queue.add(r)
@@ -53,16 +58,21 @@ export function memo_(memo_def, ...add_def_a) {
53
58
  }
54
59
  },
55
60
  })
61
+ /**
62
+ * @param {rmemo_add_def_T}add_def
63
+ * @returns {memo_T}
64
+ */
56
65
  memo.add = add_def=>{
57
66
  if (memo.a) {
58
- let pair = [memo_(()=>pair[1] = add_def(memo, pair[1]))]
59
- memo.a.push(pair)
60
- pair[0]()
67
+ let v = add_def(memo)
68
+ if (v instanceof Object) memo.a.push(v)
69
+ if (v.memo_) v()
61
70
  } else {
62
71
  add_def_a.push(add_def)
63
72
  }
64
73
  return memo
65
74
  }
75
+ memo.memo_ = memo_
66
76
  memo.f = ()=>{
67
77
  let prev_memo = cur_memo
68
78
  cur_memo = memo
@@ -76,22 +86,23 @@ export function memo_(memo_def, ...add_def_a) {
76
86
  }
77
87
  memo.f.l = 0
78
88
  memo.f.s = []
79
- memo.f.S = []
80
- memo.memor = []
89
+ memo.f.t = []
90
+ memo.t = []
81
91
  return memo
82
92
  }
83
93
  export { memo_ as memosig_ }
84
94
  /**
85
95
  * @param {memo_def_T}memo_def
86
- * @param {rmemo_add_T<unknown>[]}subscriber_a
96
+ * @param {rmemo_add_def_T}add_def_a
87
97
  * @returns {sig_T}
88
98
  * @private
89
99
  */
90
- export function lock_memosig_(memo_def, ...subscriber_a) {
100
+ export function lock_memosig_(memo_def, ...add_def_a) {
91
101
  let lock_memosig = new Proxy(
92
- /** @type {sig_T} */memo_(memo=>
93
- memo.lock ? memo._ : memo_def(memo),
94
- ...subscriber_a),
102
+ /** @type {sig_T} */
103
+ memo_(memo=>
104
+ memo.lock ? memo() : memo_def(memo),
105
+ ...add_def_a),
95
106
  {
96
107
  get(memo, prop) {
97
108
  if (prop === 'add') {
@@ -114,54 +125,75 @@ export function lock_memosig_(memo_def, ...subscriber_a) {
114
125
  }
115
126
  /**
116
127
  * @param {unknown}init_val
117
- * @param {rmemo_add_T[]}add_a
128
+ * @param {rmemo_add_def_T}add_def_a
118
129
  * @returns {sig_T}
119
130
  * @private
120
131
  */
121
- export function sig_(init_val, ...add_a) {
132
+ export function sig_(init_val, ...add_def_a) {
122
133
  return memo_(sig=>
123
134
  'val' in sig
124
135
  ? sig.val
125
136
  : init_val,
126
- ...add_a)
137
+ ...add_def_a)
127
138
  }
128
139
  /**
129
140
  * Call the rmemo & enable updates from it's parents.
130
141
  * @param {rmemo_T}rmemo
142
+ * @param {(rmemo:rmemo_T)=>unknown}[off_fn]
143
+ * @returns {rmemo_T}
131
144
  */
132
- export function rmemo__on(rmemo) {
133
- if (rmemo.r?.d) {
134
- rmemo.r.deref = rmemo.r.d
145
+ export function rmemo__on(rmemo, off_fn) {
146
+ if (off_fn) rmemo__off__add(rmemo, off_fn)
147
+ if (rmemo.s?.d) {
148
+ rmemo.s.deref = rmemo.s.d
135
149
  }
136
150
  rmemo.f()
151
+ return rmemo
137
152
  }
138
153
  /**
139
154
  * Disable updates from the rmemo's parents.
140
155
  * @param {rmemo_T}rmemo
156
+ * @returns {rmemo_T}
141
157
  */
142
158
  export function rmemo__off(rmemo) {
143
- if (rmemo.r) {
144
- rmemo.r.d ||= rmemo.r.deref
145
- rmemo.r.deref = ()=>{
159
+ if (rmemo.s) {
160
+ rmemo.s.d ??= rmemo.s.deref
161
+ rmemo.s.deref = ()=>{
146
162
  }
147
163
  }
164
+ for (let a_o of rmemo.a ?? []) {
165
+ if (a_o.memo_) rmemo__off(a_o)
166
+ }
167
+ for (let fn of rmemo.o ?? []) {
168
+ fn(rmemo)
169
+ }
170
+ return rmemo
171
+ }
172
+ /**
173
+ * @param {rmemo_T}rmemo
174
+ * @param {(rmemo:rmemo_T)=>unknown}off_fn
175
+ * @returns {rmemo_T}
176
+ */
177
+ export function rmemo__off__add(rmemo, off_fn) {
178
+ rmemo.o ??= []
179
+ rmemo.o.push(off_fn)
180
+ return rmemo
148
181
  }
149
182
  /**
150
183
  * Bind reactive add_def onto the given memo to prevent GC.
151
184
  * The add_def can autosubscribe to any rmemo.
152
185
  * Returns an "off" function which deactivates the reactive add_def & removes the GC binding from the given memo.
153
186
  * @param {rmemo_T}memo
154
- * @param {()=>unknown}add_def
187
+ * @param {rmemo_add_def_T}add_def
155
188
  * @returns {()=>void}
156
189
  */
157
190
  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)
191
+ let val
192
+ memo.add((...arg_a)=>{
193
+ return val = add_def(...arg_a)
162
194
  })
163
195
  return ()=>{
164
- rmemo__off(pair[0])
165
- memo.a.splice(memo.a.indexOf(pair), 1)
196
+ if (val.memo_) rmemo__off(val)
197
+ if (val instanceof Object) memo.a.splice(memo.a.indexOf(val), 1)
166
198
  }
167
199
  }
@@ -4,7 +4,19 @@ 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__add, sig_ } from './index.js'
7
+ import {
8
+ lock_memosig_,
9
+ memo_,
10
+ type memo_T,
11
+ memosig_,
12
+ rmemo__add,
13
+ rmemo__off,
14
+ rmemo__off__add,
15
+ rmemo__on,
16
+ type rmemo_T,
17
+ sig_,
18
+ type sig_T
19
+ } from './index.js'
8
20
  test('memo_|static value', ()=>{
9
21
  let count = 0
10
22
  const memo = memo_(()=>{
@@ -19,7 +31,7 @@ test('memo_|static value', ()=>{
19
31
  })
20
32
  test('memo_|def function|rmemo argument', ()=>{
21
33
  const sig = sig_('val0')
22
- const memo:memo_T<string>&{ custom?:string } = memo_<string>((_rmemo$:memo_T<string>&{ custom?:string })=>
34
+ const memo:memo_T<string>&{ custom?:string } = memo_<string>((_rmemo$:sig_T<string>&{ custom?:string })=>
23
35
  `${_rmemo$.custom}-${sig()}`)
24
36
  memo.custom = 'custom_val0'
25
37
  equal(memo(), 'custom_val0-val0')
@@ -172,17 +184,21 @@ test('sig_|undefined', ()=>{
172
184
  equal(memo(), undefined)
173
185
  })
174
186
  test('rmemo|subscriber|has strong reference to the return value', ()=>{
175
- const add_arg_aa:[memo_T<number|undefined>, number|undefined][] = []
187
+ const add_arg_aa:[sig_T<number|undefined>, number|undefined][] = []
188
+ let memo:memo_T<number>|undefined
176
189
  const num$ = sig_<number|undefined>(
177
190
  undefined
178
- ).add<number>((sig, old_val)=>{
179
- add_arg_aa.push([sig, old_val])
180
- return 99
181
- })
191
+ ).add(sig=>
192
+ memo = memo_<number>(memo=>{
193
+ add_arg_aa.push([sig, memo.val])
194
+ return 99
195
+ }))
182
196
  equal(num$.a, undefined)
183
197
  equal(add_arg_aa, [])
184
198
  equal(num$(), undefined)
185
- equal(num$.a![0][1], 99)
199
+ equal(num$.a![0], memo)
200
+ equal(memo!.val, 99)
201
+ equal((num$.a![0] as memo_T<number>).val, 99)
186
202
  equal(add_arg_aa, [[num$, undefined]])
187
203
  })
188
204
  test('sig_|subscriber|notified if sig is set before read', ()=>{
@@ -190,10 +206,11 @@ test('sig_|subscriber|notified if sig is set before read', ()=>{
190
206
  let subscriber__num:number|undefined = undefined
191
207
  const num$ = sig_<number|undefined>(
192
208
  undefined
193
- ).add(num$=>{
194
- count++
195
- subscriber__num = num$()
196
- })
209
+ ).add(num$=>
210
+ memo_(()=>{
211
+ count++
212
+ subscriber__num = num$()
213
+ }))
197
214
  equal(count, 0)
198
215
  equal(subscriber__num, undefined)
199
216
  num$._ = 1
@@ -208,10 +225,11 @@ test('sig_|subscriber|sets sig', ()=>{
208
225
  let count = 0
209
226
  const num$ = sig_(
210
227
  0
211
- ).add(async num$=>{
212
- count++
213
- num$._ = base$() + 1
214
- })
228
+ ).add(num$=>
229
+ memo_(()=>{
230
+ count++
231
+ num$._ = base$() + 1
232
+ }))
215
233
  equal(count, 0)
216
234
  equal(num$(), 1)
217
235
  equal(count, 1)
@@ -227,12 +245,12 @@ test('sig_|async subsubscriber|case 1', async ()=>{
227
245
  let count = 0
228
246
  const user$ = sig_<{ id:string }|null>(
229
247
  null
230
- ).add(async (_user$)=>{
248
+ ).add((_user$)=>memo_(async ()=>{
231
249
  count++
232
250
  id$()
233
251
  const user:{ id:string } = await new Promise(_resolve=>resolve = _resolve)
234
252
  _user$._ = user
235
- })
253
+ }))
236
254
  equal(count, 0)
237
255
  equal(user$(), null)
238
256
  equal(count, 1)
@@ -255,13 +273,14 @@ test('sig_|async subsubscriber|case 2', async ()=>{
255
273
  const taskArgumentsCalls:number[][] = []
256
274
  const sum$ = sig_<null|number>(
257
275
  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
- })
276
+ ).add(sum$=>
277
+ memo_(async ()=>{
278
+ taskArgumentsCalls.push([a$(), b$()])
279
+ for (let i = 0; i < sleepCycles; i++) {
280
+ await Promise.resolve()
281
+ }
282
+ sum$._ = a$() + b$()
283
+ }))
265
284
  equal(sum$(), null)
266
285
  deepStrictEqual(taskArgumentsCalls, [[1, 2]])
267
286
  a$._ = 10
@@ -312,8 +331,9 @@ test('prevents diamond dependency problem 1', ()=>{
312
331
  const d$ = memo_(()=>a$().replace('a', 'd'))
313
332
  memo_(
314
333
  ()=>`${b$()}${c$()}${d$()}`)
315
- .add(combined$=>values.push(combined$()))
316
- ()
334
+ .add(combined$=>
335
+ memo_(()=>values.push(combined$()))
336
+ )()
317
337
  deepStrictEqual(values, ['b0c0d0'])
318
338
  store$._ = 1
319
339
  store$._ = 2
@@ -329,8 +349,9 @@ test('prevents diamond dependency problem 2', ()=>{
329
349
  const e$ = memo_(()=>d$().replace('d', 'e'))
330
350
  memo_<string>(
331
351
  ()=>[a$(), e$()].join(''))
332
- .add($=>values.push($()))
333
- ()
352
+ .add($=>
353
+ memo_(()=>values.push($()))
354
+ )()
334
355
  deepStrictEqual(values, ['a0e0'])
335
356
  store$._ = 1
336
357
  deepStrictEqual(values, ['a0e0', 'a1e1'])
@@ -344,8 +365,9 @@ test('prevents diamond dependency problem 3', ()=>{
344
365
  const d$ = memo_(()=>c$().replace('c', 'd'))
345
366
  memo_<string>(
346
367
  ()=>`${a$()}${b$()}${c$()}${d$()}`)
347
- .add(combined$=>values.push(combined$()))
348
- ()
368
+ .add(combined$=>
369
+ memo_(()=>values.push(combined$()))
370
+ )()
349
371
  deepStrictEqual(values, ['a0b0c0d0'])
350
372
  store$._ = 1
351
373
  deepStrictEqual(values, ['a0b0c0d0', 'a1b1c1d1'])
@@ -363,12 +385,14 @@ test('autosubscribe: prevents diamond dependency problem 4 (complex)', ()=>{
363
385
  const g$ = memo_(()=>`g${f$()}`)
364
386
  memo_(
365
387
  ()=>e$())
366
- .add(combined1$=>values.push(combined1$()))
367
- ()
388
+ .add(combined1$=>
389
+ memo_(()=>values.push(combined1$()))
390
+ )()
368
391
  memo_(
369
392
  ()=>[e$(), g$()].join(''))
370
- .add(combined2$=>values.push(combined2$()))
371
- ()
393
+ .add(combined2$=>
394
+ memo_(()=>values.push(combined2$()))
395
+ )()
372
396
  deepStrictEqual(values, ['eca0b0da0', 'eca0b0da0gfeca0b0da0'])
373
397
  store1$._ = 1
374
398
  store2$._ = 2
@@ -416,8 +440,9 @@ test('prevents diamond dependency problem 6', ()=>{
416
440
  const c$ = memo_(()=>b$().replace('b', 'c'))
417
441
  memo_(
418
442
  ()=>`${a$()}${c$()}`)
419
- .add(combined$=>values.push(combined$()))
420
- ()
443
+ .add(combined$=>
444
+ memo_(()=>values.push(combined$()))
445
+ )()
421
446
  deepStrictEqual(values, ['a0c0'])
422
447
  store1$._ = 1
423
448
  deepStrictEqual(values, ['a0c0', 'a1c0'])
@@ -430,7 +455,8 @@ test('prevents dependency listeners from being out of order', ()=>{
430
455
  const values:string[] = []
431
456
  const b$ = memo_(
432
457
  ()=>`${a$()}b`)
433
- .add(b$=>values.push(b$()))
458
+ .add(b$=>
459
+ memo_(()=>values.push(b$())))
434
460
  equal(b$(), '0ab')
435
461
  deepStrictEqual(values, ['0ab'])
436
462
  equal(a$(), '0a')
@@ -443,51 +469,67 @@ test('computes initial value when argument is undefined', ()=>{
443
469
  equal(one$(), undefined)
444
470
  equal(two$(), false)
445
471
  })
446
- test('.rmemo__on + .rmemo__off', ()=>{
472
+ test('.rmemo__on,.rmemo__off__add,.rmemo__off', ()=>{
447
473
  const base$ = sig_(1)
448
474
  let count = 0
475
+ const rmemo__off__add_arg_aa:[rmemo_T<number>][] = []
476
+ const rmemo__on__off_arg_aa:[rmemo_T<number>][] = []
449
477
  const memo$ = memo_(()=>{
450
478
  count++
451
479
  return base$() + 10
452
480
  })
481
+ rmemo__off__add(memo$, (...arg_a)=>{
482
+ rmemo__off__add_arg_aa.push(arg_a)
483
+ })
453
484
  equal(memo$(), 11)
454
485
  equal(count, 1)
455
486
  base$._ = 2
456
487
  equal(memo$(), 12)
457
488
  equal(count, 2)
489
+ equal(rmemo__off__add_arg_aa, [])
458
490
  rmemo__off(memo$)
491
+ equal(rmemo__off__add_arg_aa, [[memo$]])
459
492
  base$._ = 3
460
493
  equal(memo$(), 12)
461
494
  equal(count, 2)
495
+ equal(rmemo__off__add_arg_aa, [[memo$]])
462
496
  rmemo__on(memo$)
463
497
  equal(memo$(), 13)
464
498
  equal(count, 3)
499
+ equal(rmemo__off__add_arg_aa, [[memo$]])
465
500
  rmemo__off(memo$)
466
- rmemo__on(memo$)
501
+ equal(rmemo__off__add_arg_aa, [[memo$], [memo$]])
502
+ rmemo__on(memo$, (...arg_a)=>{
503
+ rmemo__on__off_arg_aa.push(arg_a)
504
+ })
505
+ equal(rmemo__off__add_arg_aa, [[memo$], [memo$]])
506
+ equal(rmemo__on__off_arg_aa, [])
467
507
  equal(count, 4)
468
508
  base$._ = 4
469
509
  equal(memo$(), 14)
470
510
  equal(count, 5)
511
+ equal(rmemo__off__add_arg_aa, [[memo$], [memo$]])
512
+ equal(rmemo__on__off_arg_aa, [])
513
+ rmemo__off(memo$)
514
+ equal(rmemo__off__add_arg_aa, [[memo$], [memo$], [memo$]])
515
+ equal(rmemo__on__off_arg_aa, [[memo$]])
471
516
  })
472
517
  test('rmemo__add', ()=>{
473
518
  const base$ = sig_(1)
474
- let count = 0
475
- const subscriber_base_a:number[] = []
476
- const off = rmemo__add(base$, ()=>{
477
- count++
478
- subscriber_base_a.push(base$())
519
+ const add_arg_aa_val_aaa:[[sig_T<number>], string|undefined, number][] = []
520
+ const off = rmemo__add<number, memo_T<string>>(base$, (...arg_a)=>{
521
+ return memo_(val$=>{
522
+ add_arg_aa_val_aaa.push([arg_a, val$.val, arg_a[0]()])
523
+ return 'val-' + arg_a[0]()
524
+ })
479
525
  })
480
- equal(subscriber_base_a, [])
481
- equal(count, 0)
526
+ equal(add_arg_aa_val_aaa, [])
482
527
  base$()
483
- equal(subscriber_base_a, [1])
484
- equal(count, 1)
528
+ equal(add_arg_aa_val_aaa, [[[base$], undefined, 1]])
485
529
  base$._ = 2
486
- equal(subscriber_base_a, [1, 2])
487
- equal(count, 2)
530
+ equal(add_arg_aa_val_aaa, [[[base$], undefined, 1], [[base$], 'val-1', 2]])
488
531
  off()
489
532
  base$._ = 3
490
- equal(subscriber_base_a, [1, 2])
491
- equal(count, 2)
533
+ equal(add_arg_aa_val_aaa, [[[base$], undefined, 1], [[base$], 'val-1', 2]])
492
534
  })
493
535
  test.run()
@@ -8,7 +8,7 @@ test('rmemo__wait', async ()=>{
8
8
  subject$,
9
9
  subject=>subject >= 0,
10
10
  10_000)
11
- equal(promise.m.memor, [])
11
+ equal(promise.m.t, [])
12
12
  equal(subject$(), -1)
13
13
  subject$._ = 1
14
14
  equal(subject$(), 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "5.16.1",
3
+ "version": "5.17.0",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -145,8 +145,8 @@
145
145
  "@arethetypeswrong/cli": "^0.13.5",
146
146
  "@ctx-core/preprocess": "^0.1.0",
147
147
  "@size-limit/preset-small-lib": "^11.0.1",
148
- "@types/node": "^20.10.7",
149
- "@types/sinon": "^17.0.2",
148
+ "@types/node": "^20.11.0",
149
+ "@types/sinon": "^17.0.3",
150
150
  "c8": "^9.0.0",
151
151
  "check-dts": "^0.7.2",
152
152
  "esbuild": "^0.19.11",
@@ -210,28 +210,28 @@
210
210
  "import": {
211
211
  "./rmemo": "{ memo_ }"
212
212
  },
213
- "limit": "355 B"
213
+ "limit": "352 B"
214
214
  },
215
215
  {
216
216
  "name": "memo_ sig_",
217
217
  "import": {
218
218
  "./rmemo": "{ sig_, memo_ }"
219
219
  },
220
- "limit": "377 B"
220
+ "limit": "370 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": "478 B"
227
+ "limit": "471 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": "580 B"
234
+ "limit": "570 B"
235
235
  },
236
236
  {
237
237
  "name": "uuid",
@@ -248,4 +248,4 @@
248
248
  "limit": "116 B"
249
249
  }
250
250
  ]
251
- }
251
+ }