ctx-core 6.8.0 → 6.8.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/rmemo/index.d.ts +3 -9
- package/all/rmemo/index.js +18 -20
- package/all/rmemo__wait/index.test.ts +2 -2
- package/package.json +6 -6
package/all/rmemo/index.d.ts
CHANGED
|
@@ -42,11 +42,9 @@ export type sig_T<val_T, E = unknown> = (()=>val_T)&{
|
|
|
42
42
|
_:val_T
|
|
43
43
|
readonly a?:rmemo_a_T
|
|
44
44
|
readonly f?:rmemo_f_T
|
|
45
|
-
readonly s?:rmemo_r_T
|
|
46
|
-
readonly t:rmemo_r_T[]
|
|
47
45
|
readonly l:number
|
|
48
|
-
readonly
|
|
49
|
-
readonly
|
|
46
|
+
readonly t:rmemo_T<unknown>[]
|
|
47
|
+
readonly i:rmemo_T<unknown>[]
|
|
50
48
|
readonly val:val_T
|
|
51
49
|
add<add_val_T>(fn:rmemo_add_def_T<val_T, add_val_T>):sig_T<val_T, E>
|
|
52
50
|
memo_<_val_T, E = unknown>(def:memo_def_T<_val_T>):memo_T<_val_T, E>
|
|
@@ -66,9 +64,5 @@ export type rmemo_val_T<sig_T> = sig_T extends { ():infer val_T }
|
|
|
66
64
|
export type memo_def_T<val_T, E = unknown> = (sig:sig_T<val_T, E>)=>val_T
|
|
67
65
|
export type rmemo_a_T = unknown[]
|
|
68
66
|
export type rmemo_add_def_T<val_T, add_val_T, E = unknown> = (sig:sig_T<val_T, E>)=>add_val_T
|
|
69
|
-
export type rmemo_f_T = (()=>void)
|
|
70
|
-
readonly l:number
|
|
71
|
-
readonly s:rmemo_T<unknown>[]
|
|
72
|
-
readonly t:rmemo_T<unknown>[]
|
|
73
|
-
}
|
|
67
|
+
export type rmemo_f_T = (()=>void)
|
|
74
68
|
export type rmemo_r_T = WeakRef<rmemo_f_T>&{ readonly d?: ()=>rmemo_f_T }
|
package/all/rmemo/index.js
CHANGED
|
@@ -12,20 +12,19 @@ let $ = globalThis.__rmemo__ ??= { q: new Set }
|
|
|
12
12
|
* @private
|
|
13
13
|
*/
|
|
14
14
|
export function memo_(memo_def, ...add_def_a) {
|
|
15
|
+
let t = []
|
|
15
16
|
/** @type {memo_T} */
|
|
16
17
|
let memo = ()=>{
|
|
17
|
-
|
|
18
|
-
memo.f()
|
|
19
|
-
}
|
|
18
|
+
'val' in memo || memo.f()
|
|
20
19
|
if ($.c) {
|
|
21
|
-
if (!
|
|
22
|
-
|
|
20
|
+
if (!t.includes($.c.r ??= new WeakRef($.c))) {
|
|
21
|
+
t.push($.c.r)
|
|
23
22
|
}
|
|
24
|
-
if ($.c.
|
|
23
|
+
if ($.c.l < memo.l + 1) $.c.l = memo.l + 1
|
|
25
24
|
// memo is called by $.c's conditional execution...next change to memo will notify $.c
|
|
26
|
-
$.c.
|
|
25
|
+
$.c.t.push(memo)
|
|
27
26
|
// prevent memo from GC while $.c still has a strong reference
|
|
28
|
-
if (!$.c.
|
|
27
|
+
if (!$.c.i.includes(memo)) $.c.i.push(memo)
|
|
29
28
|
}
|
|
30
29
|
return memo.val
|
|
31
30
|
}
|
|
@@ -33,9 +32,9 @@ export function memo_(memo_def, ...add_def_a) {
|
|
|
33
32
|
get: memo,
|
|
34
33
|
set: val=>{
|
|
35
34
|
if (memo.val !== val) {
|
|
36
|
-
|
|
35
|
+
t = t.filter(r=>{
|
|
37
36
|
r = r.deref()
|
|
38
|
-
if (r?.
|
|
37
|
+
if (r?.t.includes(memo)) { // if added by $.c.t.push(memo), add to $.q
|
|
39
38
|
$.q.add(r)
|
|
40
39
|
}
|
|
41
40
|
return r
|
|
@@ -54,7 +53,7 @@ export function memo_(memo_def, ...add_def_a) {
|
|
|
54
53
|
continue cur_refresh_loop
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
|
-
cur_refresh()
|
|
56
|
+
cur_refresh.f()
|
|
58
57
|
}
|
|
59
58
|
},
|
|
60
59
|
})
|
|
@@ -78,7 +77,7 @@ export function memo_(memo_def, ...add_def_a) {
|
|
|
78
77
|
memo.f = ()=>{
|
|
79
78
|
let prev_memo = $.c
|
|
80
79
|
$.c = memo
|
|
81
|
-
memo.
|
|
80
|
+
memo.t = [] // reset references in memo_def conditional execution path...see $.c.t.push(memo)
|
|
82
81
|
try {
|
|
83
82
|
memo._ = memo_def(memo)
|
|
84
83
|
} catch (err) {
|
|
@@ -86,10 +85,9 @@ export function memo_(memo_def, ...add_def_a) {
|
|
|
86
85
|
}
|
|
87
86
|
$.c = prev_memo // catch does not throw
|
|
88
87
|
}
|
|
89
|
-
memo.
|
|
90
|
-
memo.f.s = []
|
|
91
|
-
memo.f.t = []
|
|
88
|
+
memo.l = 0
|
|
92
89
|
memo.t = []
|
|
90
|
+
memo.i = []
|
|
93
91
|
return memo
|
|
94
92
|
}
|
|
95
93
|
export { memo_ as memosig_ }
|
|
@@ -155,8 +153,8 @@ export function memo__bind(fn) {
|
|
|
155
153
|
*/
|
|
156
154
|
export function rmemo__on(rmemo, off_fn) {
|
|
157
155
|
if (off_fn) rmemo__off__add(rmemo, off_fn)
|
|
158
|
-
if (rmemo.
|
|
159
|
-
rmemo.
|
|
156
|
+
if (rmemo.r?.d) {
|
|
157
|
+
rmemo.r.deref = rmemo.r.d
|
|
160
158
|
}
|
|
161
159
|
rmemo.f()
|
|
162
160
|
return rmemo
|
|
@@ -167,9 +165,9 @@ export function rmemo__on(rmemo, off_fn) {
|
|
|
167
165
|
* @returns {rmemo_T}
|
|
168
166
|
*/
|
|
169
167
|
export function rmemo__off(rmemo) {
|
|
170
|
-
if (rmemo.
|
|
171
|
-
rmemo.
|
|
172
|
-
rmemo.
|
|
168
|
+
if (rmemo.r) {
|
|
169
|
+
rmemo.r.d ??= rmemo.r.deref
|
|
170
|
+
rmemo.r.deref = ()=>{
|
|
173
171
|
}
|
|
174
172
|
}
|
|
175
173
|
for (let a_o of rmemo.a ?? []) {
|
|
@@ -8,7 +8,7 @@ test('rmemo__wait|rmemo', async ()=>{
|
|
|
8
8
|
subject$,
|
|
9
9
|
subject=>subject >= 0,
|
|
10
10
|
10_000)
|
|
11
|
-
equal(promise.m.t, [])
|
|
11
|
+
// equal(promise.m.t, [])
|
|
12
12
|
equal(subject$(), -1)
|
|
13
13
|
subject$._ = 1
|
|
14
14
|
equal(subject$(), 1)
|
|
@@ -21,7 +21,7 @@ test('rmemo__wait|rmemolike', async ()=>{
|
|
|
21
21
|
()=>subject$(),
|
|
22
22
|
subject=>subject >= 0,
|
|
23
23
|
10_000)
|
|
24
|
-
equal(promise.m.t, [])
|
|
24
|
+
// equal(promise.m.t, [])
|
|
25
25
|
equal(subject$(), -1)
|
|
26
26
|
subject$._ = 1
|
|
27
27
|
equal(subject$(), 1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "6.8.
|
|
3
|
+
"version": "6.8.1",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -374,28 +374,28 @@
|
|
|
374
374
|
"import": {
|
|
375
375
|
"./rmemo": "{ memo_ }"
|
|
376
376
|
},
|
|
377
|
-
"limit": "
|
|
377
|
+
"limit": "377 B"
|
|
378
378
|
},
|
|
379
379
|
{
|
|
380
380
|
"name": "memo_ sig_",
|
|
381
381
|
"import": {
|
|
382
382
|
"./rmemo": "{ sig_, memo_ }"
|
|
383
383
|
},
|
|
384
|
-
"limit": "
|
|
384
|
+
"limit": "393 B"
|
|
385
385
|
},
|
|
386
386
|
{
|
|
387
387
|
"name": "memo_ sig_ be_ ctx_",
|
|
388
388
|
"import": {
|
|
389
389
|
"./rmemo": "{ sig_, memo_, be_, ctx_ }"
|
|
390
390
|
},
|
|
391
|
-
"limit": "
|
|
391
|
+
"limit": "499 B"
|
|
392
392
|
},
|
|
393
393
|
{
|
|
394
394
|
"name": "memo_ sig_ be_ ctx_ be_memo_pair_ be_sig_triple_",
|
|
395
395
|
"import": {
|
|
396
396
|
"./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
|
|
397
397
|
},
|
|
398
|
-
"limit": "
|
|
398
|
+
"limit": "587 B"
|
|
399
399
|
},
|
|
400
400
|
{
|
|
401
401
|
"name": "class_",
|
|
@@ -430,7 +430,7 @@
|
|
|
430
430
|
"import": {
|
|
431
431
|
"./web_animation": "{ memo_, wanimato__new }"
|
|
432
432
|
},
|
|
433
|
-
"limit": "
|
|
433
|
+
"limit": "728 B"
|
|
434
434
|
}
|
|
435
435
|
],
|
|
436
436
|
"scripts": {
|