ctx-core 4.7.0 → 4.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.js +14 -17
- package/all/rmemo/index.test.ts +16 -0
- package/package.json +6 -6
package/all/rmemo/index.js
CHANGED
|
@@ -13,13 +13,12 @@ let queue = new Set
|
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
15
15
|
export function memo_(rmemo_def, ...subscriber_a) {
|
|
16
|
-
let memor
|
|
17
16
|
let memo = ()=>{
|
|
18
17
|
if (!('val' in memo)) {
|
|
19
18
|
memo.f()
|
|
20
19
|
}
|
|
21
20
|
if (cur_memo) {
|
|
22
|
-
if (!~memor.indexOf(cur_memo.r ||= new WeakRef(cur_memo.f))) memor.push(cur_memo.r)
|
|
21
|
+
if (!~memo.memor.indexOf(cur_memo.r ||= new WeakRef(cur_memo.f))) memo.memor.push(cur_memo.r)
|
|
23
22
|
if (cur_memo.f.l < memo.f.l + 1) cur_memo.f.l = memo.f.l + 1
|
|
24
23
|
// conditional in r calls this r_memo
|
|
25
24
|
cur_memo.f.s.push(memo)
|
|
@@ -36,23 +35,14 @@ export function memo_(rmemo_def, ...subscriber_a) {
|
|
|
36
35
|
if (i !== val) {
|
|
37
36
|
// val is available for other purposes
|
|
38
37
|
let run_queue = !queue.size
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
memo.memor = memo.memor.filter(r=>{
|
|
39
|
+
// val is no longer used...saving bytes
|
|
41
40
|
val = r.deref() // val is no longer used...saving bytes
|
|
42
|
-
if (
|
|
43
|
-
memor.splice(i, 1)
|
|
44
|
-
} else if (~val.s.indexOf(memo)) { // if conditional r refresh calls this r_memo, add to queue
|
|
41
|
+
if (val && ~val.s.indexOf(memo)) { // if conditional r refresh calls this r_memo, add to queue
|
|
45
42
|
queue.add(val)
|
|
46
43
|
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
// add reference to subscribers to prevent GC
|
|
50
|
-
memo.b ||=
|
|
51
|
-
subscriber_a.map(subscriber=>
|
|
52
|
-
memo_(subscriber$=>(
|
|
53
|
-
subscriber(memo),
|
|
54
|
-
subscriber$
|
|
55
|
-
))())
|
|
44
|
+
return val
|
|
45
|
+
})
|
|
56
46
|
if (run_queue) {
|
|
57
47
|
cur_refresh_loop:for (let cur_refresh of queue) {
|
|
58
48
|
queue.delete(cur_refresh)
|
|
@@ -78,11 +68,18 @@ export function memo_(rmemo_def, ...subscriber_a) {
|
|
|
78
68
|
console.error(err)
|
|
79
69
|
}
|
|
80
70
|
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
|
+
))())
|
|
81
78
|
}
|
|
82
79
|
memo.f.l = 0
|
|
83
80
|
memo.f.s = []
|
|
84
81
|
memo.f.S = []
|
|
85
|
-
memo.memor =
|
|
82
|
+
memo.memor = []
|
|
86
83
|
return memo
|
|
87
84
|
}
|
|
88
85
|
export { memo_ as memosig_ }
|
package/all/rmemo/index.test.ts
CHANGED
|
@@ -153,6 +153,22 @@ test('sig_|undefined', ()=>{
|
|
|
153
153
|
equal(sig(), undefined)
|
|
154
154
|
equal(memo(), undefined)
|
|
155
155
|
})
|
|
156
|
+
test('sig_|subscriber|sets sig', ()=>{
|
|
157
|
+
const base$ = sig_(0)
|
|
158
|
+
let count = 0
|
|
159
|
+
const num$ = sig_(
|
|
160
|
+
0,
|
|
161
|
+
async (num$)=>{
|
|
162
|
+
count++
|
|
163
|
+
num$._ = base$() + 1
|
|
164
|
+
})
|
|
165
|
+
equal(count, 0)
|
|
166
|
+
equal(num$(), 1)
|
|
167
|
+
equal(count, 1)
|
|
168
|
+
base$._ = 5
|
|
169
|
+
equal(num$(), 6)
|
|
170
|
+
equal(count, 2)
|
|
171
|
+
})
|
|
156
172
|
test('sig_|async subsubscriber|case 1', async ()=>{
|
|
157
173
|
let resolve:(user:{ id:string })=>void
|
|
158
174
|
const user0 = { id: 'id-0' }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.1",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"sinon": "^17.0.1",
|
|
115
115
|
"size-limit": "^11.0.0",
|
|
116
116
|
"ts-node": "^10.9.1",
|
|
117
|
-
"tsx": "^4.
|
|
117
|
+
"tsx": "^4.6.0",
|
|
118
118
|
"typescript": "next",
|
|
119
119
|
"uvu": "^0.5.6"
|
|
120
120
|
},
|
|
@@ -150,28 +150,28 @@
|
|
|
150
150
|
"import": {
|
|
151
151
|
"./rmemo": "{ memo_ }"
|
|
152
152
|
},
|
|
153
|
-
"limit": "
|
|
153
|
+
"limit": "342 B"
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
156
|
"name": "memo_ sig_",
|
|
157
157
|
"import": {
|
|
158
158
|
"./rmemo": "{ sig_, memo_ }"
|
|
159
159
|
},
|
|
160
|
-
"limit": "
|
|
160
|
+
"limit": "357 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": "511 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": "607 B"
|
|
175
175
|
}
|
|
176
176
|
],
|
|
177
177
|
"scripts": {
|