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.
- package/all/be_lock_memosig_triple/index.d.ts +7 -5
- package/all/be_lock_memosig_triple/index.js +12 -11
- package/all/be_lock_memosig_triple/index.test.ts +11 -10
- package/all/be_memo_pair/index.d.ts +6 -4
- package/all/be_memo_pair/index.js +12 -10
- package/all/be_memo_pair/index.test.ts +13 -13
- package/all/be_memosig_triple/index.d.ts +6 -4
- package/all/be_memosig_triple/index.test.ts +14 -13
- package/all/be_sig_triple/index.d.ts +9 -7
- package/all/be_sig_triple/index.js +12 -10
- package/all/be_sig_triple/index.test.ts +8 -6
- package/all/is_development/index.js +2 -1
- package/all/is_production/index.js +2 -1
- package/all/rmemo/index.d.ts +17 -23
- package/all/rmemo/index.js +57 -41
- package/all/rmemo/index.test.ts +65 -55
- package/all/waitfor/index.test.ts +5 -5
- package/package.json +5 -5
- package/rmemo/index.d.ts +2 -2
- package/rmemo/index.js +2 -2
|
@@ -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
|
-
|
|
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 {
|
|
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
|
-
|
|
15
|
+
config
|
|
16
16
|
) {
|
|
17
|
-
let
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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_(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
14
|
+
config
|
|
15
15
|
) {
|
|
16
|
-
let
|
|
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
|
-
|
|
25
|
-
memo=>
|
|
26
|
-
|
|
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
|
-
|
|
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'>(
|
|
59
|
-
(ctx,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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_(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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<
|
|
22
|
+
ctx_T extends Ctx = Ctx_wide_T<ns_T>
|
|
25
23
|
> = [
|
|
26
|
-
ctx__be_T<ctx_T, _sig_T,
|
|
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 {
|
|
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
|
-
|
|
14
|
+
config
|
|
15
15
|
) {
|
|
16
|
-
let
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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_(
|
|
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'
|
|
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'
|
|
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__,
|
package/all/rmemo/index.d.ts
CHANGED
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
/// <reference lib="es2021" />
|
|
2
|
-
export declare function memo_<val_T>(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
):
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
package/all/rmemo/index.js
CHANGED
|
@@ -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 {
|
|
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, ...
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
43
|
-
memo.
|
|
44
|
-
|
|
40
|
+
if (!memo.a) {
|
|
41
|
+
memo.a = []
|
|
42
|
+
add_def_a.map(memo.add)
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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 //
|
|
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 {
|
|
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
|
-
|
|
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 {
|
|
117
|
+
* @param {rmemo_add_T[]}add_a
|
|
102
118
|
* @returns {sig_T}
|
|
103
119
|
* @private
|
|
104
120
|
*/
|
|
105
|
-
export function sig_(init_val, ...
|
|
106
|
-
return memo_(sig=>
|
|
107
|
-
|
|
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
|
|
136
|
-
* The
|
|
137
|
-
* Returns an "off" function which deactivates the reactive
|
|
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}
|
|
154
|
+
* @param {()=>unknown}add_def
|
|
140
155
|
* @returns {()=>void}
|
|
141
156
|
*/
|
|
142
|
-
export function
|
|
143
|
-
let
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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(
|
|
149
|
-
memo.
|
|
164
|
+
rmemo__off(pair[0])
|
|
165
|
+
memo.a.splice(memo.a.indexOf(pair), 1)
|
|
150
166
|
}
|
|
151
167
|
}
|
package/all/rmemo/index.test.ts
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
-
|
|
178
|
-
|
|
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$.
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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>(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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_(
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
426
|
-
|
|
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('
|
|
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 =
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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.
|
|
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": "
|
|
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": "
|
|
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": "
|
|
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": "
|
|
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,
|
|
2
|
-
export { rmemo__off as off, rmemo__on as on,
|
|
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,
|
|
2
|
-
export { rmemo__off as off, rmemo__on as on,
|
|
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'
|