ctx-core 4.8.2 → 4.9.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_memo_pair/index.d.ts +3 -3
- package/all/be_memo_pair/index.js +5 -7
- package/all/be_memo_pair/index.test.ts +8 -1
- package/all/be_memosig_triple/index.d.ts +26 -0
- package/all/be_memosig_triple/index.js +21 -0
- package/all/be_memosig_triple/index.test.ts +144 -0
- package/all/be_sig_triple/index.d.ts +1 -1
- package/all/be_sig_triple/index.js +4 -7
- package/all/be_sig_triple/index.test.ts +4 -1
- package/all/rmemo/index.d.ts +1 -0
- package/all/rmemo/index.js +27 -30
- package/all/rmemo/index.test.ts +19 -1
- package/all/weak_r/index.js +12 -7
- package/package.json +6 -6
- package/rmemo/index.d.ts +1 -1
- package/rmemo/index.js +1 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { Be,
|
|
1
|
+
import type { Be, be_config_T, Ctx } from '../be_/index.js'
|
|
2
2
|
import type { memo_T, sig_T } from '../rmemo/index.js'
|
|
3
3
|
export declare function be_memo_pair_<
|
|
4
4
|
val_T,
|
|
5
5
|
_memo_T extends memo_T<val_T> = memo_T<val_T>,
|
|
6
6
|
ctx_T extends Ctx = Ctx
|
|
7
|
-
>(be:
|
|
7
|
+
>(be:Be<_memo_T, ctx_T>):be_memo_pair_T<val_T, _memo_T, ctx_T>
|
|
8
8
|
export declare function be_memo_pair_<
|
|
9
9
|
val_T,
|
|
10
10
|
_memo_T extends memo_T<val_T> = memo_T<val_T>,
|
|
11
11
|
ctx_T extends Ctx = Ctx
|
|
12
12
|
>(
|
|
13
|
-
rmemo__new:
|
|
13
|
+
rmemo__new:(ctx:Ctx, memo:_memo_T&{ _:val_T })=>val_T,
|
|
14
14
|
...subscriber_a_THEN_config:
|
|
15
15
|
|[...((ctx:Ctx, memosig:sig_T<val_T>)=>unknown)[]]
|
|
16
16
|
|[...((ctx:Ctx, memosig:sig_T<val_T>)=>unknown)[], config:be_config_T]
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
+
/// <reference types="../be_/index.d.ts" />
|
|
2
|
+
/// <reference types="../rmemo/index.d.ts" />
|
|
3
|
+
/// <reference types="./index.d.ts" />
|
|
1
4
|
import { be_ } from '../be_/index.js'
|
|
2
5
|
import { memo_ } from '../rmemo/index.js'
|
|
3
|
-
/** @typedef {import('../be_/index.d.ts').Be} */
|
|
4
|
-
/** @typedef {import('../be_/index.d.ts').be__val__new_T} */
|
|
5
|
-
/** @typedef {import('../be_/index.d.ts').be_config_T} */
|
|
6
|
-
/** @typedef {import('../rmemo/index.d.ts').rmemo_subscriber_T} */
|
|
7
|
-
/** @typedef {import('./index.d.ts').be_memo_pair_T} */
|
|
8
6
|
/**
|
|
9
7
|
* @param {Be|be__val__new_T<unknown>}be_OR_val__new
|
|
10
8
|
* @param {rmemo_subscriber_T[]|[...rmemo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
|
|
@@ -18,14 +16,14 @@ export function be_memo_pair_(
|
|
|
18
16
|
let config =
|
|
19
17
|
typeof subscriber_a_THEN_config[subscriber_a_THEN_config.length - 1] === 'object'
|
|
20
18
|
? subscriber_a_THEN_config.pop()
|
|
21
|
-
:
|
|
19
|
+
: 0
|
|
22
20
|
/** @type {Be} */
|
|
23
21
|
let be =
|
|
24
22
|
be_OR_val__new.is_be
|
|
25
23
|
? be_OR_val__new
|
|
26
24
|
: be_(ctx=>
|
|
27
25
|
memo_(
|
|
28
|
-
|
|
26
|
+
memo=>be_OR_val__new(ctx, memo),
|
|
29
27
|
...subscriber_a_THEN_config.map(subscriber=>
|
|
30
28
|
memo=>subscriber(ctx, memo))),
|
|
31
29
|
config)
|
|
@@ -15,13 +15,20 @@ test('be_memo_pair_', ()=>{
|
|
|
15
15
|
const [
|
|
16
16
|
foobar$_,
|
|
17
17
|
foobar_,
|
|
18
|
-
] = be_memo_pair_(
|
|
18
|
+
] = be_memo_pair_<number, sig_T<number>&{ count:number }>((_ctx, foobar$)=>{
|
|
19
|
+
equal(_ctx, ctx)
|
|
20
|
+
foobar$.count = (foobar$.count ||= 0) + 1
|
|
21
|
+
return base_(ctx) + 1
|
|
22
|
+
})
|
|
19
23
|
const ctx = ctx__new()
|
|
24
|
+
equal(foobar$_(ctx).count, undefined)
|
|
20
25
|
equal(foobar$_(ctx)._, 2)
|
|
21
26
|
equal(foobar_(ctx), 2)
|
|
27
|
+
equal(foobar$_(ctx).count, 1)
|
|
22
28
|
base__set(ctx, 2)
|
|
23
29
|
equal(foobar$_(ctx)._, 3)
|
|
24
30
|
equal(foobar_(ctx), 3)
|
|
31
|
+
equal(foobar$_(ctx).count, 2)
|
|
25
32
|
})
|
|
26
33
|
test('be_memo_pair_|+id|+is_source_|+oninit|+subscriber_a', ()=>{
|
|
27
34
|
const ctx = ctx__new()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Be, be_config_T, Ctx } from '../be_/index.js'
|
|
2
|
+
import type { rmemo_val_T, sig_T } from '../rmemo/index.js'
|
|
3
|
+
export declare function be_memosig_triple_<
|
|
4
|
+
val_T,
|
|
5
|
+
_sig_T extends sig_T<val_T> = sig_T<val_T>,
|
|
6
|
+
ctx_T extends Ctx = Ctx
|
|
7
|
+
>(be:Be<_sig_T, ctx_T>):be_memosig_triple_T<val_T, _sig_T, ctx_T>
|
|
8
|
+
export declare function be_memosig_triple_<
|
|
9
|
+
val_T,
|
|
10
|
+
_sig_T extends sig_T<val_T> = sig_T<val_T>,
|
|
11
|
+
ctx_T extends Ctx = Ctx
|
|
12
|
+
>(
|
|
13
|
+
rmemo__new:(ctx:Ctx, memosig:_sig_T)=>val_T,
|
|
14
|
+
...subscriber_a_THEN_config:
|
|
15
|
+
|[...((ctx:Ctx, sig:_sig_T)=>unknown)[]]
|
|
16
|
+
|[...((ctx:Ctx, sig:_sig_T)=>unknown)[], config:be_config_T]
|
|
17
|
+
):be_memosig_triple_T<val_T, _sig_T, ctx_T>
|
|
18
|
+
export type be_memosig_triple_T<
|
|
19
|
+
val_T,
|
|
20
|
+
_sig_T extends sig_T<val_T> = sig_T<val_T>,
|
|
21
|
+
ctx_T extends Ctx = Ctx
|
|
22
|
+
> = [
|
|
23
|
+
Be<_sig_T>,
|
|
24
|
+
(ctx:ctx_T)=>val_T,
|
|
25
|
+
(ctx:ctx_T, val:rmemo_val_T<_sig_T>)=>void
|
|
26
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="../be_/index.d.ts" />
|
|
2
|
+
/// <reference types="../be_sig_triple/index.d.ts" />
|
|
3
|
+
/// <reference types="../rmemo/index.d.ts" />
|
|
4
|
+
/// <reference types="./index.d.ts" />
|
|
5
|
+
import { be_memo_pair_ } from '../be_memo_pair'
|
|
6
|
+
/**
|
|
7
|
+
* @param {Be<sig_T>|be__val__new_T<unknown>}be_OR_val__new
|
|
8
|
+
* @param {rmemo_subscriber_T[]|[...rmemo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
|
|
9
|
+
* @returns {be_memosig_triple_T}
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export function be_memosig_triple_(...arg_a) {
|
|
13
|
+
/** @type {be_sig_triple_T} */
|
|
14
|
+
let memo_pair = be_memo_pair_(...arg_a)
|
|
15
|
+
return [
|
|
16
|
+
...memo_pair,
|
|
17
|
+
(ctx, val)=>{
|
|
18
|
+
memo_pair[0](ctx)._ = val
|
|
19
|
+
},
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { be_ } from '../be_/index.js'
|
|
4
|
+
import { be_sig_triple_ } from '../be_sig_triple/index.js'
|
|
5
|
+
import { ctx__new } from '../ctx/index.js'
|
|
6
|
+
import { memosig_, type sig_T } from '../rmemo/index.js'
|
|
7
|
+
import { be_memosig_triple_ } from './index.js'
|
|
8
|
+
test('be_memosig_triple_', ()=>{
|
|
9
|
+
const [
|
|
10
|
+
,
|
|
11
|
+
base_,
|
|
12
|
+
base__set,
|
|
13
|
+
] = be_sig_triple_(()=>1)
|
|
14
|
+
const [
|
|
15
|
+
foobar$_,
|
|
16
|
+
foobar_,
|
|
17
|
+
foobar__set,
|
|
18
|
+
] = be_memosig_triple_<number, sig_T<number>&{
|
|
19
|
+
count:number
|
|
20
|
+
}>((_ctx, foobar$)=>{
|
|
21
|
+
equal(_ctx, ctx)
|
|
22
|
+
foobar$.count = (foobar$.count ||= 0) + 1
|
|
23
|
+
return base_(ctx) + 1
|
|
24
|
+
})
|
|
25
|
+
const ctx = ctx__new()
|
|
26
|
+
equal(foobar$_(ctx).count, undefined)
|
|
27
|
+
equal(foobar$_(ctx)._, 2)
|
|
28
|
+
equal(foobar_(ctx), 2)
|
|
29
|
+
equal(foobar$_(ctx).count, 1)
|
|
30
|
+
foobar__set(ctx, 5)
|
|
31
|
+
equal(foobar$_(ctx)._, 5)
|
|
32
|
+
equal(foobar_(ctx), 5)
|
|
33
|
+
equal(foobar$_(ctx).count, 1)
|
|
34
|
+
base__set(ctx, 2)
|
|
35
|
+
equal(foobar$_(ctx)._, 3)
|
|
36
|
+
equal(foobar_(ctx), 3)
|
|
37
|
+
equal(foobar$_(ctx).count, 2)
|
|
38
|
+
})
|
|
39
|
+
test('be_memosig_triple_|+id|+is_source_', ()=>{
|
|
40
|
+
const ctx = ctx__new()
|
|
41
|
+
let subscriber_count = 0
|
|
42
|
+
const [
|
|
43
|
+
,
|
|
44
|
+
base_,
|
|
45
|
+
base__set,
|
|
46
|
+
] = be_sig_triple_(
|
|
47
|
+
()=>1,
|
|
48
|
+
{ is_source_: map_ctx=>map_ctx === ctx })
|
|
49
|
+
const [
|
|
50
|
+
,
|
|
51
|
+
subscriber_dep_,
|
|
52
|
+
subscriber_dep__set
|
|
53
|
+
] = be_sig_triple_(()=>1,
|
|
54
|
+
{ is_source_: map_ctx=>map_ctx === ctx })
|
|
55
|
+
const [
|
|
56
|
+
foobar$_,
|
|
57
|
+
foobar_,
|
|
58
|
+
foobar__set,
|
|
59
|
+
] = be_memosig_triple_(
|
|
60
|
+
ctx=>
|
|
61
|
+
base_(ctx) + 1,
|
|
62
|
+
(ctx, foobar$)=>{
|
|
63
|
+
subscriber_count++
|
|
64
|
+
subscriber_dep__set(ctx, subscriber_count + foobar$())
|
|
65
|
+
},
|
|
66
|
+
{ id: 'foobar', is_source_: map_ctx=>map_ctx === ctx })
|
|
67
|
+
equal(subscriber_count, 0)
|
|
68
|
+
equal(foobar$_([ctx__new(), ctx])._, 2)
|
|
69
|
+
equal(foobar_([ctx__new(), ctx]), 2)
|
|
70
|
+
equal(foobar$_(ctx)._, 2)
|
|
71
|
+
equal(foobar_(ctx), 2)
|
|
72
|
+
equal(subscriber_count, 1)
|
|
73
|
+
equal((ctx.get('foobar') as sig_T<number>)._, 2)
|
|
74
|
+
equal(subscriber_dep_(ctx), 3)
|
|
75
|
+
foobar__set([ctx__new(), ctx], 5)
|
|
76
|
+
equal(foobar$_([ctx__new(), ctx])._, 5)
|
|
77
|
+
equal(foobar_([ctx__new(), ctx]), 5)
|
|
78
|
+
equal(foobar$_(ctx)._, 5)
|
|
79
|
+
equal(foobar_(ctx), 5)
|
|
80
|
+
equal((ctx.get('foobar') as sig_T<number>)._, 5)
|
|
81
|
+
equal(subscriber_count, 2)
|
|
82
|
+
equal(subscriber_dep_(ctx), 7)
|
|
83
|
+
base__set(ctx, 2)
|
|
84
|
+
equal(foobar$_([ctx__new(), ctx])._, 3)
|
|
85
|
+
equal(foobar_([ctx__new(), ctx]), 3)
|
|
86
|
+
equal(foobar$_(ctx)._, 3)
|
|
87
|
+
equal(foobar_(ctx), 3)
|
|
88
|
+
equal(subscriber_count, 3)
|
|
89
|
+
equal((ctx.get('foobar') as sig_T<number>)._, 3)
|
|
90
|
+
equal(subscriber_dep_(ctx), 6)
|
|
91
|
+
})
|
|
92
|
+
test('be_memosig_triple_|+be', ()=>{
|
|
93
|
+
const ctx = ctx__new()
|
|
94
|
+
let subscriber_count = 0
|
|
95
|
+
const [
|
|
96
|
+
,
|
|
97
|
+
base_,
|
|
98
|
+
base__set,
|
|
99
|
+
] = be_sig_triple_(()=>1,
|
|
100
|
+
{ is_source_: map_ctx=>map_ctx === ctx })
|
|
101
|
+
const [
|
|
102
|
+
foobar$_,
|
|
103
|
+
foobar_,
|
|
104
|
+
foobar__set,
|
|
105
|
+
] = be_memosig_triple_<number, custom_sig_T>(
|
|
106
|
+
be_(ctx=>{
|
|
107
|
+
const foobar$ =
|
|
108
|
+
memosig_(()=>base_(ctx) + 1,
|
|
109
|
+
foobar$=>{
|
|
110
|
+
foobar$()
|
|
111
|
+
subscriber_count++
|
|
112
|
+
}) as custom_sig_T
|
|
113
|
+
foobar$.custom = 'custom-val'
|
|
114
|
+
return foobar$
|
|
115
|
+
}, { id: 'foobar', is_source_: map_ctx=>map_ctx === ctx }))
|
|
116
|
+
equal(subscriber_count, 0)
|
|
117
|
+
equal(foobar$_([ctx__new(), ctx])._, 2)
|
|
118
|
+
equal(foobar_([ctx__new(), ctx]), 2)
|
|
119
|
+
equal(foobar$_(ctx)._, 2)
|
|
120
|
+
equal(foobar_(ctx), 2)
|
|
121
|
+
equal(subscriber_count, 1)
|
|
122
|
+
equal((ctx.get('foobar') as sig_T<number>)._, 2)
|
|
123
|
+
equal(foobar$_(ctx).custom, 'custom-val')
|
|
124
|
+
foobar__set(ctx, 5)
|
|
125
|
+
equal(foobar$_([ctx__new(), ctx])._, 5)
|
|
126
|
+
equal(foobar_([ctx__new(), ctx]), 5)
|
|
127
|
+
equal(foobar$_(ctx)._, 5)
|
|
128
|
+
equal(foobar_(ctx), 5)
|
|
129
|
+
equal(subscriber_count, 2)
|
|
130
|
+
equal((ctx.get('foobar') as sig_T<number>)._, 5)
|
|
131
|
+
equal(foobar$_(ctx).custom, 'custom-val')
|
|
132
|
+
base__set([ctx__new(), ctx], 2)
|
|
133
|
+
equal(foobar$_([ctx__new(), ctx])._, 3)
|
|
134
|
+
equal(foobar_([ctx__new(), ctx]), 3)
|
|
135
|
+
equal(foobar$_(ctx)._, 3)
|
|
136
|
+
equal(foobar_(ctx), 3)
|
|
137
|
+
equal((ctx.get('foobar') as sig_T<number>)._, 3)
|
|
138
|
+
equal(foobar$_(ctx).custom, 'custom-val')
|
|
139
|
+
equal(subscriber_count, 3)
|
|
140
|
+
})
|
|
141
|
+
test.run()
|
|
142
|
+
type custom_sig_T = sig_T<number>&{
|
|
143
|
+
custom:string
|
|
144
|
+
}
|
|
@@ -10,7 +10,7 @@ export declare function be_sig_triple_<
|
|
|
10
10
|
_sig_T extends sig_T<val_T> = sig_T<val_T>,
|
|
11
11
|
ctx_T extends Ctx = Ctx
|
|
12
12
|
>(
|
|
13
|
-
val__new:(ctx:Ctx
|
|
13
|
+
val__new:(ctx:Ctx)=>val_T,
|
|
14
14
|
...subscriber_a_THEN_config:
|
|
15
15
|
|[...((ctx:Ctx, sig:_sig_T)=>unknown)[]]
|
|
16
16
|
|[...((ctx:Ctx, sig:_sig_T)=>unknown)[], config:be_config_T]
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
/// <reference types="../be_/index.d.ts" />
|
|
2
|
+
/// <reference types="../rmemo/index.d.ts" />
|
|
3
|
+
/// <reference types="./index.d.ts" />
|
|
1
4
|
import { be_ } from '../be_/index.js'
|
|
2
5
|
import { sig_ } from '../rmemo/index.js'
|
|
3
|
-
/** @typedef {import('../be_/index.d.ts').Be} */
|
|
4
|
-
/** @typedef {import('../be_/index.d.ts').be__val__new_T} */
|
|
5
|
-
/** @typedef {import('../be_/index.d.ts').be_config_T} */
|
|
6
|
-
/** @typedef {import('../rmemo/index.d.ts').sig_T} */
|
|
7
|
-
/** @typedef {import('../rmemo/index.d.ts').rmemo_subscriber_T} */
|
|
8
|
-
/** @typedef {import('./index.d.ts').be_sig_triple_T} */
|
|
9
6
|
/**
|
|
10
7
|
* @param {Be<sig_T>|be__val__new_T<unknown>}be_OR_val__new
|
|
11
8
|
* @param {rmemo_subscriber_T[]|[...rmemo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
|
|
@@ -19,7 +16,7 @@ export function be_sig_triple_(
|
|
|
19
16
|
let config =
|
|
20
17
|
typeof subscriber_a_THEN_config[subscriber_a_THEN_config.length - 1] === 'object'
|
|
21
18
|
? subscriber_a_THEN_config.pop()
|
|
22
|
-
:
|
|
19
|
+
: 0
|
|
23
20
|
/** @type {Be<sig_T>} */
|
|
24
21
|
let be =
|
|
25
22
|
be_OR_val__new.is_be
|
package/all/rmemo/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare function memosig_<val_T>(
|
|
|
10
10
|
def:rmemo_def_T<val_T>,
|
|
11
11
|
...subscriber_a:rmemo_subscriber_T<val_T>[]
|
|
12
12
|
):sig_T<val_T>
|
|
13
|
+
// TODO: lock_memosig_
|
|
13
14
|
export type rmemo_T<val_T> = memo_T<val_T>|sig_T<val_T>
|
|
14
15
|
export type memo_T<val_T> = (()=>val_T)&{
|
|
15
16
|
readonly _:val_T
|
package/all/rmemo/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/** @typedef {import('./index.d.ts').memo_T} */
|
|
3
|
-
/** @typedef {import('./index.d.ts').rmemo_subscriber_T} */
|
|
4
|
-
/** @typedef {import('./index.d.ts').sig_T} */
|
|
1
|
+
/// <reference types="./index.d.ts" />
|
|
5
2
|
/** @type {WeakRef<memo_T>} */
|
|
6
3
|
let cur_memo
|
|
7
4
|
/** @type {Set<()=>unknown>} */
|
|
@@ -30,30 +27,36 @@ export function memo_(rmemo_def, ...subscriber_a) {
|
|
|
30
27
|
Object.defineProperty(memo, '_', {
|
|
31
28
|
get: memo,
|
|
32
29
|
set: val=>{
|
|
33
|
-
let
|
|
34
|
-
memo.val
|
|
35
|
-
|
|
36
|
-
// val is available for other purposes
|
|
37
|
-
let run_queue = !queue.size
|
|
30
|
+
let run_queue
|
|
31
|
+
if (memo.val !== val) {
|
|
32
|
+
run_queue = !queue.size
|
|
38
33
|
memo.memor = memo.memor.filter(r=>{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
queue.add(val)
|
|
34
|
+
r = r.deref()
|
|
35
|
+
if (r && ~r.s.indexOf(memo)) { // if conditional r refresh calls this r_memo, add to queue
|
|
36
|
+
queue.add(r)
|
|
43
37
|
}
|
|
44
|
-
return
|
|
38
|
+
return r
|
|
45
39
|
})
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
}
|
|
41
|
+
memo.val = val
|
|
42
|
+
if (!memo.b) {
|
|
43
|
+
// add reference to subscribers to prevent GC
|
|
44
|
+
memo.b = subscriber_a.map(subscriber=>
|
|
45
|
+
memo_(()=>subscriber(memo)))
|
|
46
|
+
for (let s of memo.b) {
|
|
47
|
+
s()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (run_queue) {
|
|
51
|
+
cur_refresh_loop:for (let cur_refresh of queue) {
|
|
52
|
+
queue.delete(cur_refresh)
|
|
53
|
+
for (let queue_refresh of queue) {
|
|
54
|
+
if (cur_refresh.l > queue_refresh.l) {
|
|
55
|
+
queue.add(cur_refresh)
|
|
56
|
+
continue cur_refresh_loop
|
|
54
57
|
}
|
|
55
|
-
cur_refresh()
|
|
56
58
|
}
|
|
59
|
+
cur_refresh()
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
},
|
|
@@ -68,13 +71,6 @@ export function memo_(rmemo_def, ...subscriber_a) {
|
|
|
68
71
|
console.error(err)
|
|
69
72
|
}
|
|
70
73
|
cur_memo = prev_memo // finally is not necessary...catch does not throw
|
|
71
|
-
// add reference to subscribers to prevent GC
|
|
72
|
-
memo.b ||=
|
|
73
|
-
subscriber_a.map(subscriber=>
|
|
74
|
-
memo_(subscriber$=>(
|
|
75
|
-
subscriber(memo),
|
|
76
|
-
subscriber$
|
|
77
|
-
))())
|
|
78
74
|
}
|
|
79
75
|
memo.f.l = 0
|
|
80
76
|
memo.f.s = []
|
|
@@ -97,3 +93,4 @@ export function sig_(init_val, ...subscriber_a) {
|
|
|
97
93
|
},
|
|
98
94
|
...subscriber_a)
|
|
99
95
|
}
|
|
96
|
+
// TODO: lock_memosig_
|
package/all/rmemo/index.test.ts
CHANGED
|
@@ -153,12 +153,30 @@ test('sig_|undefined', ()=>{
|
|
|
153
153
|
equal(sig(), undefined)
|
|
154
154
|
equal(memo(), undefined)
|
|
155
155
|
})
|
|
156
|
+
test('sig_|subscriber|notified if sig is set before read', ()=>{
|
|
157
|
+
let count = 0
|
|
158
|
+
let subscriber__num:number|undefined = undefined
|
|
159
|
+
const num$ = sig_<number|undefined>(
|
|
160
|
+
undefined,
|
|
161
|
+
num$=>{
|
|
162
|
+
count++
|
|
163
|
+
subscriber__num = num$()
|
|
164
|
+
})
|
|
165
|
+
equal(count, 0)
|
|
166
|
+
equal(subscriber__num, undefined)
|
|
167
|
+
num$._ = 1
|
|
168
|
+
equal(count, 1)
|
|
169
|
+
equal(subscriber__num, 1)
|
|
170
|
+
num$()
|
|
171
|
+
equal(count, 1)
|
|
172
|
+
equal(subscriber__num, 1)
|
|
173
|
+
})
|
|
156
174
|
test('sig_|subscriber|sets sig', ()=>{
|
|
157
175
|
const base$ = sig_(0)
|
|
158
176
|
let count = 0
|
|
159
177
|
const num$ = sig_(
|
|
160
178
|
0,
|
|
161
|
-
async
|
|
179
|
+
async num$=>{
|
|
162
180
|
count++
|
|
163
181
|
num$._ = base$() + 1
|
|
164
182
|
})
|
package/all/weak_r/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { assign } from '../assign/index.js'
|
|
|
3
3
|
const { get } = Reflect
|
|
4
4
|
const add_strong_sym = Symbol('add_strong')
|
|
5
5
|
const delete_strong_sym = Symbol('delete_strong')
|
|
6
|
+
let _undefined
|
|
6
7
|
/**
|
|
7
8
|
* @param {object}[back_o]
|
|
8
9
|
* @returns {object}
|
|
@@ -24,12 +25,16 @@ export function weak_r_(back_o = {}) {
|
|
|
24
25
|
if ((value === null || value === void 0 ? void 0 : value.deref) && !strong_set.has(prop)) {
|
|
25
26
|
value = value.deref()
|
|
26
27
|
}
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
return (
|
|
29
|
+
value === _undefined
|
|
30
|
+
? _undefined
|
|
31
|
+
: {
|
|
32
|
+
configurable: true,
|
|
33
|
+
enumerable: true,
|
|
34
|
+
value,
|
|
35
|
+
writable: true
|
|
36
|
+
}
|
|
37
|
+
)
|
|
33
38
|
},
|
|
34
39
|
get(back_ctx, prop) {
|
|
35
40
|
const uw_val = get(back_ctx, prop)
|
|
@@ -61,7 +66,7 @@ export { strong__call as ref_strong }
|
|
|
61
66
|
*/
|
|
62
67
|
export function strong__assign(obj, prop, val) {
|
|
63
68
|
strong__call(obj, prop)
|
|
64
|
-
if (val !==
|
|
69
|
+
if (val !== _undefined) {
|
|
65
70
|
assign(obj, {
|
|
66
71
|
[prop]: val
|
|
67
72
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.1",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"devDependencies": {
|
|
108
108
|
"@arethetypeswrong/cli": "^0.13.2",
|
|
109
109
|
"@size-limit/preset-small-lib": "^11.0.0",
|
|
110
|
-
"@types/node": "^20.10.
|
|
110
|
+
"@types/node": "^20.10.3",
|
|
111
111
|
"@types/sinon": "^17.0.2",
|
|
112
112
|
"c8": "^8.0.1",
|
|
113
113
|
"check-dts": "^0.7.2",
|
|
@@ -150,28 +150,28 @@
|
|
|
150
150
|
"import": {
|
|
151
151
|
"./rmemo": "{ memo_ }"
|
|
152
152
|
},
|
|
153
|
-
"limit": "
|
|
153
|
+
"limit": "338 B"
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
156
|
"name": "memo_ sig_",
|
|
157
157
|
"import": {
|
|
158
158
|
"./rmemo": "{ sig_, memo_ }"
|
|
159
159
|
},
|
|
160
|
-
"limit": "
|
|
160
|
+
"limit": "354 B"
|
|
161
161
|
},
|
|
162
162
|
{
|
|
163
163
|
"name": "memo_ sig_ be_ ctx_",
|
|
164
164
|
"import": {
|
|
165
165
|
"./rmemo": "{ sig_, memo_, be_, ctx_ }"
|
|
166
166
|
},
|
|
167
|
-
"limit": "
|
|
167
|
+
"limit": "506 B"
|
|
168
168
|
},
|
|
169
169
|
{
|
|
170
170
|
"name": "memo_ sig_ be_ ctx_ be_memo_pair_ be_sig_triple_",
|
|
171
171
|
"import": {
|
|
172
172
|
"./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
|
|
173
173
|
},
|
|
174
|
-
"limit": "
|
|
174
|
+
"limit": "602 B"
|
|
175
175
|
}
|
|
176
176
|
],
|
|
177
177
|
"scripts": {
|
package/rmemo/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { sig__set_ as set_ } from '../all/rmemo/index.js'
|
|
2
1
|
export * from '../all/be_/index.js'
|
|
3
2
|
export * from '../all/be_memo_pair/index.js'
|
|
3
|
+
export * from '../all/be_memosig_triple/index.js'
|
|
4
4
|
export * from '../all/be_sig_triple/index.js'
|
|
5
5
|
export * from '../all/ctx/index.js'
|
|
6
6
|
export * from '../all/rmemo/index.js'
|
package/rmemo/index.js
CHANGED