ctx-core 4.9.0 → 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/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/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.9.
|
|
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": {
|