ctx-core 6.8.2 → 7.0.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.
- package/all/be_/index.d.ts +24 -0
- package/all/be_/index.js +28 -0
- package/all/be_/index.test.ts +26 -0
- package/all/be_lock_memosig_triple/index.d.ts +7 -8
- package/all/be_lock_memosig_triple/index.js +20 -17
- package/all/be_lock_memosig_triple/index.test.ts +100 -86
- package/all/be_memo_pair/index.d.ts +7 -8
- package/all/be_memo_pair/index.js +22 -20
- package/all/be_memo_pair/index.test.ts +114 -97
- package/all/be_memosig_triple/index.d.ts +7 -8
- package/all/be_memosig_triple/index.test.ts +115 -100
- package/all/be_sig_triple/index.d.ts +7 -8
- package/all/be_sig_triple/index.js +20 -17
- package/all/be_sig_triple/index.test.ts +63 -52
- package/all/event_log/index.js +11 -9
- package/all/is_development/index.js +6 -5
- package/all/is_production/index.js +6 -5
- package/all/is_staging/index.js +5 -4
- package/all/rmemo/index.d.ts +42 -31
- package/all/rmemo/index.js +88 -94
- package/all/rmemo/index.test.ts +131 -115
- package/all/rmemo__wait/index.test.ts +2 -2
- package/all/wanimato/index.js +12 -12
- package/package.json +7 -7
|
@@ -18,10 +18,10 @@ test('be_sig_triple_', ()=>{
|
|
|
18
18
|
return 1
|
|
19
19
|
})
|
|
20
20
|
const ctx = ctx__new()
|
|
21
|
-
equal(foobar$_(ctx)
|
|
21
|
+
equal(foobar$_(ctx)(), 1)
|
|
22
22
|
equal(foobar_(ctx), 1)
|
|
23
23
|
foobar__set(ctx, 2)
|
|
24
|
-
equal(foobar$_(ctx)
|
|
24
|
+
equal(foobar$_(ctx)(), 2)
|
|
25
25
|
equal(foobar_(ctx), 2)
|
|
26
26
|
})
|
|
27
27
|
test('be_sig_triple_|+id|+ns|+add', ()=>{
|
|
@@ -31,37 +31,42 @@ test('be_sig_triple_|+id|+ns|+add', ()=>{
|
|
|
31
31
|
,
|
|
32
32
|
add_dep_,
|
|
33
33
|
add_dep__set
|
|
34
|
-
] =
|
|
35
|
-
|
|
34
|
+
] = ns_be_sig_triple_(
|
|
35
|
+
'test_ns',
|
|
36
|
+
()=>1)
|
|
36
37
|
const [
|
|
37
38
|
foobar$_,
|
|
38
39
|
foobar_,
|
|
39
40
|
foobar__set,
|
|
40
|
-
] =
|
|
41
|
+
] = ns_id_be_sig_triple_<number, 'test_ns'>(
|
|
42
|
+
'test_ns',
|
|
43
|
+
'foobar',
|
|
41
44
|
ctx=>{
|
|
42
45
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
43
46
|
type test_ctx = Expect<Equal<typeof ctx, wide_ctx_T<'test_ns'>>>
|
|
44
47
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
45
48
|
return 1
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
},
|
|
50
|
+
[
|
|
51
|
+
(ctx, foobar$)=>memo_(()=>{
|
|
52
|
+
add_count++
|
|
53
|
+
add_dep__set(ctx, add_count + foobar$())
|
|
54
|
+
})
|
|
55
|
+
])
|
|
51
56
|
equal(add_count, 0)
|
|
52
|
-
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))
|
|
57
|
+
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))(), 1)
|
|
53
58
|
equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 1)
|
|
54
|
-
equal(foobar$_(ctx)
|
|
59
|
+
equal(foobar$_(ctx)(), 1)
|
|
55
60
|
equal(foobar_(ctx), 1)
|
|
56
61
|
equal(add_count, 1)
|
|
57
62
|
equal(add_dep_(ctx), 2)
|
|
58
|
-
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)
|
|
63
|
+
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)(), 1)
|
|
59
64
|
foobar__set(ns_ctx__new(ctx__new(), ctx), 2)
|
|
60
|
-
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))
|
|
65
|
+
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))(), 2)
|
|
61
66
|
equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
|
|
62
|
-
equal(foobar$_(ctx)
|
|
67
|
+
equal(foobar$_(ctx)(), 2)
|
|
63
68
|
equal(foobar_(ctx), 2)
|
|
64
|
-
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)
|
|
69
|
+
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)(), 2)
|
|
65
70
|
equal(add_count, 2)
|
|
66
71
|
equal(add_dep_(ctx), 4)
|
|
67
72
|
})
|
|
@@ -79,25 +84,25 @@ test('be_sig_triple_|+be', ()=>{
|
|
|
79
84
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
80
85
|
const foobar$ =
|
|
81
86
|
sig_<number, { custom:string }>(
|
|
82
|
-
1
|
|
83
|
-
|
|
87
|
+
1,
|
|
88
|
+
[()=>add_count++])
|
|
84
89
|
foobar$.custom = 'custom-val'
|
|
85
90
|
return foobar$
|
|
86
91
|
}, { id: 'foobar', ns: 'test_ns' }))
|
|
87
92
|
equal(add_count, 0)
|
|
88
|
-
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))
|
|
93
|
+
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))(), 1)
|
|
89
94
|
equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 1)
|
|
90
|
-
equal(foobar$_(ctx)
|
|
95
|
+
equal(foobar$_(ctx)(), 1)
|
|
91
96
|
equal(foobar_(ctx), 1)
|
|
92
97
|
equal(add_count, 1)
|
|
93
|
-
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)
|
|
98
|
+
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)(), 1)
|
|
94
99
|
equal(foobar$_(ctx).custom, 'custom-val')
|
|
95
100
|
foobar__set(ns_ctx__new(ctx__new(), ctx), 2)
|
|
96
|
-
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))
|
|
101
|
+
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))(), 2)
|
|
97
102
|
equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
|
|
98
|
-
equal(foobar$_(ctx)
|
|
103
|
+
equal(foobar$_(ctx)(), 2)
|
|
99
104
|
equal(foobar_(ctx), 2)
|
|
100
|
-
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)
|
|
105
|
+
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)(), 2)
|
|
101
106
|
equal(foobar$_(ctx).custom, 'custom-val')
|
|
102
107
|
equal(add_count, 1)
|
|
103
108
|
})
|
|
@@ -122,22 +127,24 @@ test('ns_be_sig_triple_', ()=>{
|
|
|
122
127
|
type test_ctx = Expect<Equal<typeof ctx, wide_ctx_T<'test_ns'>>>
|
|
123
128
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
124
129
|
return 1
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
},
|
|
131
|
+
[
|
|
132
|
+
(ctx, foobar$)=>memo_(()=>{
|
|
133
|
+
add_count++
|
|
134
|
+
add_dep__set(ctx, add_count + foobar$())
|
|
135
|
+
})
|
|
136
|
+
])
|
|
130
137
|
equal(add_count, 0)
|
|
131
|
-
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))
|
|
138
|
+
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))(), 1)
|
|
132
139
|
equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 1)
|
|
133
|
-
equal(foobar$_(ctx)
|
|
140
|
+
equal(foobar$_(ctx)(), 1)
|
|
134
141
|
equal(foobar_(ctx), 1)
|
|
135
142
|
equal(add_count, 1)
|
|
136
143
|
equal(add_dep_(ctx), 2)
|
|
137
144
|
foobar__set(ns_ctx__new(ctx__new(), ctx), 2)
|
|
138
|
-
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))
|
|
145
|
+
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))(), 2)
|
|
139
146
|
equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
|
|
140
|
-
equal(foobar$_(ctx)
|
|
147
|
+
equal(foobar$_(ctx)(), 2)
|
|
141
148
|
equal(foobar_(ctx), 2)
|
|
142
149
|
equal(add_count, 2)
|
|
143
150
|
equal(add_dep_(ctx), 4)
|
|
@@ -163,21 +170,23 @@ test('id_be_sig_triple_', ()=>{
|
|
|
163
170
|
type test_ctx = Expect<Equal<typeof ctx, wide_ctx_T<''>>>
|
|
164
171
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
165
172
|
return 1
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
173
|
+
},
|
|
174
|
+
[
|
|
175
|
+
(ctx, foobar$)=>memo_(()=>{
|
|
176
|
+
add_count++
|
|
177
|
+
add_dep__set(ctx, add_count + foobar$())
|
|
178
|
+
})
|
|
179
|
+
])
|
|
171
180
|
equal(add_count, 0)
|
|
172
|
-
equal(foobar$_(ctx)
|
|
181
|
+
equal(foobar$_(ctx)(), 1)
|
|
173
182
|
equal(foobar_(ctx), 1)
|
|
174
183
|
equal(add_count, 1)
|
|
175
184
|
equal(add_dep_(ctx), 2)
|
|
176
|
-
equal((ctx.s[''].get('foobar')![0] as sig_T<number>)
|
|
185
|
+
equal((ctx.s[''].get('foobar')![0] as sig_T<number>)(), 1)
|
|
177
186
|
foobar__set(ctx, 2)
|
|
178
|
-
equal(foobar$_(ctx)
|
|
187
|
+
equal(foobar$_(ctx)(), 2)
|
|
179
188
|
equal(foobar_(ctx), 2)
|
|
180
|
-
equal((ctx.s[''].get('foobar')![0] as sig_T<number>)
|
|
189
|
+
equal((ctx.s[''].get('foobar')![0] as sig_T<number>)(), 2)
|
|
181
190
|
equal(add_count, 2)
|
|
182
191
|
equal(add_dep_(ctx), 4)
|
|
183
192
|
})
|
|
@@ -204,24 +213,26 @@ test('ns_id_be_sig_triple_', ()=>{
|
|
|
204
213
|
type test_ctx = Expect<Equal<typeof ctx, wide_ctx_T<'test_ns'>>>
|
|
205
214
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
206
215
|
return 1
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
216
|
+
}, [
|
|
217
|
+
(ctx, foobar$)=>memo_(()=>{
|
|
218
|
+
add_count++
|
|
219
|
+
add_dep__set(ctx, add_count + foobar$())
|
|
220
|
+
})
|
|
221
|
+
])
|
|
211
222
|
equal(add_count, 0)
|
|
212
|
-
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))
|
|
223
|
+
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))(), 1)
|
|
213
224
|
equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 1)
|
|
214
|
-
equal(foobar$_(ctx)
|
|
225
|
+
equal(foobar$_(ctx)(), 1)
|
|
215
226
|
equal(foobar_(ctx), 1)
|
|
216
227
|
equal(add_count, 1)
|
|
217
228
|
equal(add_dep_(ctx), 2)
|
|
218
|
-
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)
|
|
229
|
+
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)(), 1)
|
|
219
230
|
foobar__set(ns_ctx__new(ctx__new(), ctx), 2)
|
|
220
|
-
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))
|
|
231
|
+
equal(foobar$_(ns_ctx__new(ctx__new(), ctx))(), 2)
|
|
221
232
|
equal(foobar_(ns_ctx__new(ctx__new(), ctx)), 2)
|
|
222
|
-
equal(foobar$_(ctx)
|
|
233
|
+
equal(foobar$_(ctx)(), 2)
|
|
223
234
|
equal(foobar_(ctx), 2)
|
|
224
|
-
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)
|
|
235
|
+
equal((ctx.s.test_ns.get('foobar')![0] as sig_T<number>)(), 2)
|
|
225
236
|
equal(add_count, 2)
|
|
226
237
|
equal(add_dep_(ctx), 4)
|
|
227
238
|
})
|
package/all/event_log/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { be_sig_triple_ } from '../be_sig_triple/index.js'
|
|
1
|
+
import { be_sig_triple_, id_be_sig_triple_ } from '../be_sig_triple/index.js'
|
|
2
2
|
import { memo_ } from '../rmemo/index.js'
|
|
3
3
|
const [
|
|
4
4
|
event_log$_,
|
|
5
5
|
event_log_,
|
|
6
6
|
event_log__set,
|
|
7
|
-
] =
|
|
7
|
+
] = id_be_sig_triple_(
|
|
8
|
+
'event_log',
|
|
8
9
|
()=>[],
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
[
|
|
11
|
+
(ctx, event_log$)=>
|
|
12
|
+
memo_(()=>{
|
|
13
|
+
if (event_log$().length > event_log_limit_(ctx)) {
|
|
14
|
+
event_log$().splice(event_log$().length - event_log_limit_(ctx) + 1)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
])
|
|
16
18
|
export {
|
|
17
19
|
event_log$_,
|
|
18
20
|
event_log_,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { id_be_memo_pair_ } from '../be_memo_pair/index.js'
|
|
2
2
|
import { NODE_ENV_ } from '../NODE_ENV/index.js'
|
|
3
3
|
export const [
|
|
4
4
|
is_development$_,
|
|
5
5
|
is_development_,
|
|
6
|
-
] =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
] = id_be_memo_pair_(
|
|
7
|
+
'is_development',
|
|
8
|
+
ctx=>
|
|
9
|
+
NODE_ENV_(ctx) === 'dev'
|
|
10
|
+
|| NODE_ENV_(ctx) === 'development')
|
|
10
11
|
export { is_development$_ as is_development__ }
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { id_be_memo_pair_ } from '../be_memo_pair/index.js'
|
|
2
2
|
import { NODE_ENV_ } from '../NODE_ENV/index.js'
|
|
3
3
|
export const [
|
|
4
4
|
is_production$_,
|
|
5
5
|
is_production_,
|
|
6
|
-
] =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
] = id_be_memo_pair_(
|
|
7
|
+
'is_production',
|
|
8
|
+
ctx=>
|
|
9
|
+
NODE_ENV_(ctx) === 'prod'
|
|
10
|
+
|| NODE_ENV_(ctx) === 'production')
|
|
10
11
|
export {
|
|
11
12
|
is_production$_ as is_production__,
|
|
12
13
|
is_production$_ as b__is__production,
|
package/all/is_staging/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { id_be_memo_pair_ } from '../be_memo_pair/index.js'
|
|
2
2
|
import { NODE_ENV_ } from '../NODE_ENV/index.js'
|
|
3
3
|
export const [
|
|
4
4
|
is_staging$_,
|
|
5
5
|
is_staging_,
|
|
6
|
-
] =
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
] = id_be_memo_pair_(
|
|
7
|
+
'is_staging',
|
|
8
|
+
ctx=>
|
|
9
|
+
NODE_ENV_(ctx) === 'staging')
|
|
9
10
|
export {
|
|
10
11
|
is_staging$_ as is_staging__,
|
|
11
12
|
is_staging$_ as b__is__staging,
|
package/all/rmemo/index.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
/// <reference lib="es2021" />
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import type { wide_ctx_T } from '../be_/index.js'
|
|
3
|
+
export declare function memo_<val_T, E = unknown>(
|
|
4
|
+
def:memo_def_T<val_T, E>,
|
|
5
|
+
add_def_a1?:rmemo_add_def_T<val_T, E>[]
|
|
6
|
+
):memo_T<val_T, E>
|
|
7
|
+
export declare function sig_<val_T, E = unknown>(
|
|
8
|
+
init_val:val_T,
|
|
9
|
+
add_def_a1?:rmemo_add_def_T<val_T, E>[]
|
|
10
|
+
):sig_T<val_T, E>
|
|
11
|
+
export declare function memosig_<val_T, E = unknown>(
|
|
12
|
+
def:memo_def_T<val_T, E>,
|
|
13
|
+
add_def_a1?:rmemo_add_def_T<val_T, E>[]
|
|
14
|
+
):sig_T<val_T, E>
|
|
15
|
+
export declare function lock_memosig_<val_T, E = unknown>(
|
|
16
|
+
def:memo_def_T<val_T, E>,
|
|
17
|
+
add_def_a1?:rmemo_add_def_T<val_T, E>[]
|
|
18
|
+
):sig_T<val_T, E>
|
|
6
19
|
export declare function memo__bind<A extends unknown[], R, E = unknown>(
|
|
7
20
|
fn:(...arg_a:A)=>R
|
|
8
21
|
):memo__bind_T<A, R, E>
|
|
9
22
|
export type memo__bind_T<A extends unknown[], R, E = unknown> =
|
|
10
23
|
((...arg_a:A)=>R)&{
|
|
11
|
-
memo_<val_T>(
|
|
24
|
+
memo_<val_T>(
|
|
25
|
+
def:memo_def_T<val_T, E>,
|
|
26
|
+
add_def_a1?:rmemo_add_def_T<val_T, E>[]
|
|
27
|
+
):memo_T<val_T>
|
|
12
28
|
}
|
|
13
29
|
export declare function rmemo__on<val_T, E = unknown>(rmemo:rmemo_T<val_T, E>, off_fn?:(rmemo:rmemo_T<val_T, E>)=>unknown):void
|
|
14
30
|
export declare function rmemo__off<val_T, E = unknown>(rmemo:rmemo_T<val_T, E>):void
|
|
@@ -17,37 +33,31 @@ export declare function rmemo__add<val_T, listener_val_T, E = unknown>(
|
|
|
17
33
|
rmemo:rmemo_T<val_T, E>,
|
|
18
34
|
listener:(sig:sig_T<val_T, E>)=>listener_val_T
|
|
19
35
|
):()=>void
|
|
20
|
-
export declare function rmemo__unset(rmemo:rmemo_T<
|
|
36
|
+
export declare function rmemo__unset<T>(rmemo:rmemo_T<T>):void
|
|
21
37
|
export type rmemo_T<val_T, E = unknown> = memo_T<val_T, E>|sig_T<val_T, E>|lock_memosig_T<val_T, E>
|
|
22
38
|
export type rmemolike_T<val_T, E = unknown> = (()=>val_T)&E
|
|
23
39
|
export type circular_rmemo_T<E = unknown> =
|
|
24
40
|
(circular_memo_T|circular_sig_T|circular_lock_memosig_T)&E
|
|
25
41
|
export type memo_T<val_T, E = unknown> = (()=>val_T)&{
|
|
26
|
-
|
|
42
|
+
memo_<_val_T, E = unknown>(
|
|
43
|
+
def:memo_def_T<_val_T>,
|
|
44
|
+
add_def_a1?:rmemo_add_def_T<val_T, E>[]
|
|
45
|
+
):memo_T<_val_T, E>
|
|
46
|
+
val:val_T
|
|
27
47
|
readonly a?:rmemo_a_T
|
|
28
|
-
readonly
|
|
29
|
-
readonly
|
|
30
|
-
readonly t:rmemo_r_T[]
|
|
48
|
+
readonly b:rmemo_add_def_T<val_T, E>[]
|
|
49
|
+
readonly d:()=>val_T
|
|
31
50
|
readonly l:number
|
|
51
|
+
readonly r:rmemo_r_T[]
|
|
32
52
|
readonly u:rmemo_T<unknown>[]
|
|
33
|
-
readonly
|
|
34
|
-
readonly val:val_T
|
|
35
|
-
add<add_val_T>(add_def:rmemo_add_def_T<val_T, add_val_T>):memo_T<val_T, E>
|
|
36
|
-
memo_<_val_T, E = unknown>(def:memo_def_T<_val_T>):memo_T<_val_T, E>
|
|
53
|
+
readonly t:rmemo_T<unknown>[]
|
|
37
54
|
}&E
|
|
38
55
|
interface _circular_memo_T extends memo_T<_circular_memo_T> {
|
|
39
56
|
}
|
|
40
57
|
export type circular_memo_T<E = unknown> = _circular_memo_T&E
|
|
41
|
-
export type sig_T<val_T, E = unknown> =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
readonly f?:rmemo_f_T
|
|
45
|
-
readonly l:number
|
|
46
|
-
readonly t:rmemo_T<unknown>[]
|
|
47
|
-
readonly val:val_T
|
|
48
|
-
add<add_val_T>(fn:rmemo_add_def_T<val_T, add_val_T>):sig_T<val_T, E>
|
|
49
|
-
memo_<_val_T, E = unknown>(def:memo_def_T<_val_T>):memo_T<_val_T, E>
|
|
50
|
-
}&E
|
|
58
|
+
export type sig_T<val_T, E = unknown> = memo_T<val_T, E>&{
|
|
59
|
+
set(val:val_T):void
|
|
60
|
+
}
|
|
51
61
|
interface _circular_sig_T extends sig_T<_circular_sig_T> {
|
|
52
62
|
}
|
|
53
63
|
export type circular_sig_T<E = unknown> = _circular_memo_T&E
|
|
@@ -62,10 +72,11 @@ export type rmemo_val_T<sig_T> = sig_T extends { ():infer val_T }
|
|
|
62
72
|
: unknown
|
|
63
73
|
export type memo_def_T<val_T, E = unknown> = (sig:sig_T<val_T, E>)=>val_T
|
|
64
74
|
export type rmemo_a_T = unknown[]
|
|
65
|
-
export type rmemo_add_def_T<val_T,
|
|
66
|
-
export type
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
export type rmemo_add_def_T<val_T, E = unknown> = (sig:sig_T<val_T, E>)=>unknown
|
|
76
|
+
export type rmemo_r_T = WeakRef<rmemo_T<unknown>&{ readonly d?: ()=>rmemo_T<unknown> }>
|
|
77
|
+
export type be_rmemo_add_def_T<
|
|
78
|
+
val_T,
|
|
79
|
+
ns_T extends string,
|
|
80
|
+
E = unknown,
|
|
81
|
+
ctx_T extends wide_ctx_T<ns_T> = wide_ctx_T<ns_T>,
|
|
82
|
+
> = (ctx:ctx_T, sig:sig_T<val_T, E>)=>unknown
|
package/all/rmemo/index.js
CHANGED
|
@@ -7,93 +7,84 @@
|
|
|
7
7
|
let $ = globalThis.__rmemo__ ??= { q: new Set }
|
|
8
8
|
/**
|
|
9
9
|
* @param {memo_def_T}memo_def
|
|
10
|
-
* @param {rmemo_add_def_T}
|
|
10
|
+
* @param {rmemo_add_def_T[]}add_def_a1
|
|
11
11
|
* @returns {memo_T}
|
|
12
12
|
* @private
|
|
13
13
|
*/
|
|
14
|
-
export function memo_(memo_def,
|
|
14
|
+
export function memo_(memo_def, add_def_a1) {
|
|
15
15
|
/** @type {memo_T} */
|
|
16
16
|
let memo = ()=>{
|
|
17
|
-
'val' in memo || memo
|
|
17
|
+
'val' in memo || memo__run(memo)
|
|
18
18
|
if ($.c) {
|
|
19
|
-
if (!memo.
|
|
20
|
-
memo.
|
|
19
|
+
if (!memo.r.includes($.c.s ??= new WeakRef($.c))) {
|
|
20
|
+
memo.r.push($.c.s)
|
|
21
21
|
}
|
|
22
|
-
if ($.c.
|
|
22
|
+
if ($.c.l < memo.l + 1) $.c.l = memo.l + 1
|
|
23
23
|
// memo is called by $.c's conditional execution...next change to memo will notify $.c
|
|
24
|
-
$.c.
|
|
24
|
+
$.c.u.push(memo)
|
|
25
25
|
// prevent memo from GC while $.c still has a strong reference
|
|
26
|
-
if (!$.c.
|
|
26
|
+
if (!$.c.t.includes(memo)) $.c.t.push(memo)
|
|
27
27
|
}
|
|
28
28
|
return memo.val
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
memo
|
|
35
|
-
|
|
36
|
-
if (r?.s.includes(memo)) { // if added by $.c.f.s.push(memo), add to $.q
|
|
37
|
-
$.q.add(r)
|
|
38
|
-
}
|
|
39
|
-
return r
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
memo.val = val
|
|
43
|
-
if (!memo.a) {
|
|
44
|
-
memo.a = []
|
|
45
|
-
add_def_a.map(memo.add)
|
|
46
|
-
}
|
|
47
|
-
cur_refresh_loop:for (let cur_refresh of $.q) {
|
|
48
|
-
$.q.delete(cur_refresh)
|
|
49
|
-
for (let queue_refresh of $.q) {
|
|
50
|
-
if (cur_refresh.l > queue_refresh.l) {
|
|
51
|
-
$.q.add(cur_refresh)
|
|
52
|
-
continue cur_refresh_loop
|
|
53
|
-
}
|
|
30
|
+
memo.set = val=>{
|
|
31
|
+
if (memo.val !== val) {
|
|
32
|
+
memo.r = memo.r.filter(r=>{
|
|
33
|
+
r = r.deref()
|
|
34
|
+
if (r?.u.includes(memo)) { // if added by $.c.u.push(memo), add to $.q
|
|
35
|
+
$.q.add(r)
|
|
54
36
|
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
})
|
|
59
|
-
/**
|
|
60
|
-
* @param {rmemo_add_def_T}add_def
|
|
61
|
-
* @returns {memo_T}
|
|
62
|
-
*/
|
|
63
|
-
memo.add = add_def=>{
|
|
64
|
-
if (memo.a) {
|
|
65
|
-
let v = add_def(memo)
|
|
66
|
-
if (v instanceof Object) {
|
|
67
|
-
memo.a.push(v)
|
|
68
|
-
if (v.memo_) v()
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
add_def_a.push(add_def)
|
|
37
|
+
return r
|
|
38
|
+
})
|
|
72
39
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
40
|
+
memo.val = val
|
|
41
|
+
if (!memo.a) {
|
|
42
|
+
memo.a = []
|
|
43
|
+
add_def_a1.map(add_def=>{
|
|
44
|
+
let v = add_def(memo)
|
|
45
|
+
if (v instanceof Object) {
|
|
46
|
+
memo.a.push(v)
|
|
47
|
+
if (v.memo_) v()
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
cur_refresh_loop:for (let cur_memo of $.q) {
|
|
52
|
+
$.q.delete(cur_memo)
|
|
53
|
+
for (let queue_refresh of $.q) {
|
|
54
|
+
if (cur_memo.l > queue_refresh.l) {
|
|
55
|
+
$.q.add(cur_memo)
|
|
56
|
+
continue cur_refresh_loop
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
memo__run(cur_memo)
|
|
84
60
|
}
|
|
85
|
-
$.c = prev_memo // catch does not throw
|
|
86
61
|
}
|
|
87
|
-
memo.
|
|
88
|
-
memo.
|
|
89
|
-
memo.
|
|
62
|
+
memo.l = 0
|
|
63
|
+
memo.d = memo_def
|
|
64
|
+
memo.b = add_def_a1 ??= []
|
|
65
|
+
memo.r = []
|
|
66
|
+
memo.u = []
|
|
90
67
|
memo.t = []
|
|
68
|
+
memo.memo_ = memo_
|
|
91
69
|
return memo
|
|
92
70
|
}
|
|
93
71
|
export { memo_ as memosig_ }
|
|
72
|
+
/**
|
|
73
|
+
* @param {unknown}init_val
|
|
74
|
+
* @param {rmemo_add_def_T[]}add_def_a
|
|
75
|
+
* @returns {sig_T}
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
export function sig_(init_val, add_def_a) {
|
|
79
|
+
return memo_(sig=>
|
|
80
|
+
'val' in sig
|
|
81
|
+
? sig.val
|
|
82
|
+
: init_val,
|
|
83
|
+
add_def_a)
|
|
84
|
+
}
|
|
94
85
|
/**
|
|
95
86
|
* @param {memo_def_T}memo_def
|
|
96
|
-
* @param {rmemo_add_def_T}add_def_a
|
|
87
|
+
* @param {rmemo_add_def_T[]}add_def_a
|
|
97
88
|
* @returns {sig_T}
|
|
98
89
|
* @private
|
|
99
90
|
*/
|
|
@@ -105,37 +96,17 @@ export function lock_memosig_(memo_def, ...add_def_a) {
|
|
|
105
96
|
...add_def_a),
|
|
106
97
|
{
|
|
107
98
|
get(memo, prop) {
|
|
108
|
-
if (prop === '
|
|
109
|
-
return
|
|
110
|
-
memo
|
|
111
|
-
|
|
99
|
+
if (prop === 'set') {
|
|
100
|
+
return val=>{
|
|
101
|
+
memo.lock = 1
|
|
102
|
+
memo[prop](val)
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
105
|
return memo[prop]
|
|
115
106
|
},
|
|
116
|
-
set(memo, prop, val) {
|
|
117
|
-
if (prop === '_') {
|
|
118
|
-
memo.lock = 1
|
|
119
|
-
memo._ = val
|
|
120
|
-
}
|
|
121
|
-
return 1
|
|
122
|
-
}
|
|
123
107
|
})
|
|
124
108
|
return lock_memosig
|
|
125
109
|
}
|
|
126
|
-
/**
|
|
127
|
-
* @param {unknown}init_val
|
|
128
|
-
* @param {rmemo_add_def_T}add_def_a
|
|
129
|
-
* @returns {sig_T}
|
|
130
|
-
* @private
|
|
131
|
-
*/
|
|
132
|
-
export function sig_(init_val, ...add_def_a) {
|
|
133
|
-
return memo_(sig=>
|
|
134
|
-
'val' in sig
|
|
135
|
-
? sig.val
|
|
136
|
-
: init_val,
|
|
137
|
-
...add_def_a)
|
|
138
|
-
}
|
|
139
110
|
/**
|
|
140
111
|
* @param {(...arg_a:unknown[])=>unknown}fn
|
|
141
112
|
* @returns {((...arg_a:unknown[])=>unknown)&{ memo_: typeof memo_ }}
|
|
@@ -156,7 +127,7 @@ export function rmemo__on(rmemo, off_fn) {
|
|
|
156
127
|
if (rmemo.s?.d) {
|
|
157
128
|
rmemo.s.deref = rmemo.s.d
|
|
158
129
|
}
|
|
159
|
-
rmemo
|
|
130
|
+
memo__run(rmemo)
|
|
160
131
|
return rmemo
|
|
161
132
|
}
|
|
162
133
|
/**
|
|
@@ -198,11 +169,23 @@ export function rmemo__off__add(rmemo, off_fn) {
|
|
|
198
169
|
*/
|
|
199
170
|
export function rmemo__add(memo, add_def) {
|
|
200
171
|
let val
|
|
201
|
-
memo.
|
|
202
|
-
|
|
203
|
-
|
|
172
|
+
if (memo.a) {
|
|
173
|
+
val = add_def(memo)
|
|
174
|
+
if (val instanceof Object) {
|
|
175
|
+
memo.a.push(val)
|
|
176
|
+
if (val.memo_) val()
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
memo.b.push(()=>{
|
|
180
|
+
val = add_def(memo)
|
|
181
|
+
if (val instanceof Object) {
|
|
182
|
+
memo.a.push(val)
|
|
183
|
+
if (val.memo_) val()
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
}
|
|
204
187
|
return ()=>{
|
|
205
|
-
if (val
|
|
188
|
+
if (val?.memo_) rmemo__off(val)
|
|
206
189
|
if (val instanceof Object) memo.a.splice(memo.a.indexOf(val), 1)
|
|
207
190
|
}
|
|
208
191
|
}
|
|
@@ -212,3 +195,14 @@ export function rmemo__add(memo, add_def) {
|
|
|
212
195
|
export function rmemo__unset(rmemo) {
|
|
213
196
|
delete rmemo.val
|
|
214
197
|
}
|
|
198
|
+
function memo__run(memo) {
|
|
199
|
+
let prev_memo = $.c
|
|
200
|
+
$.c = memo
|
|
201
|
+
memo.u = [] // reset references in memo_def conditional execution path...see $.c.u.push(memo)
|
|
202
|
+
try {
|
|
203
|
+
memo.set(memo.d(memo))
|
|
204
|
+
} catch (err) {
|
|
205
|
+
console.error(err)
|
|
206
|
+
}
|
|
207
|
+
$.c = prev_memo // catch does not throw
|
|
208
|
+
}
|