ctx-core 3.1.0 → 3.2.2
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_/debug.js +25 -0
- package/all/be_/index.js +4 -16
- package/all/rmemo/index.d.ts +13 -6
- package/all/rmemo/index.js +10 -7
- package/all/rmemo/index.test.ts +22 -8
- package/package.json +5 -5
package/all/be_/debug.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { be_ } from './index.js'
|
|
2
|
+
export function be__debug() {
|
|
3
|
+
be_.argv__debug = argv__ctx=>{
|
|
4
|
+
if (!argv__ctx) {
|
|
5
|
+
throw new Error(`be: no Ctx`)
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
be_.source__debug = ctx=>{
|
|
9
|
+
if (!ctx) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`be: ${String(id)}: no is_source_ returns true`)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
be_.pending__debug = pending=>{
|
|
15
|
+
if (pending.get(be)) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`be_: ${
|
|
18
|
+
String(id)
|
|
19
|
+
}: circular:\n${pending.values().map(pending_value=>
|
|
20
|
+
typeof pending_value === 'string'
|
|
21
|
+
? pending_value
|
|
22
|
+
: 'Function').join('\n')}`)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
package/all/be_/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { globalThis__prop__ensure } from '../globalThis__prop__ensure/index.js'
|
|
2
|
+
export * from './debug.js'
|
|
2
3
|
let be_M_is_source_ = globalThis.be_M_is_source_ ||= new WeakMap()
|
|
3
4
|
/** @typedef {import('./index.d.ts').Be}Be */
|
|
4
5
|
/** @typedef {import('./index.d.ts').Ctx}Ctx */
|
|
@@ -66,9 +67,7 @@ export function be_(
|
|
|
66
67
|
expired_ = be__params.expired_
|
|
67
68
|
}
|
|
68
69
|
let be = (argv__ctx, params)=>{
|
|
69
|
-
|
|
70
|
-
throw new Error(`be: no Ctx`)
|
|
71
|
-
}
|
|
70
|
+
be_.argv__debug?.(argv__ctx)
|
|
72
71
|
let saved__val = be__val_(be, argv__ctx)
|
|
73
72
|
if (
|
|
74
73
|
!params?.force
|
|
@@ -78,24 +77,13 @@ export function be_(
|
|
|
78
77
|
return saved__val
|
|
79
78
|
}
|
|
80
79
|
let ctx = source__map_ctx_(argv__ctx, is_source_)
|
|
81
|
-
|
|
82
|
-
throw new Error(
|
|
83
|
-
`be: ${String(id)}: no is_source_ returns true`)
|
|
84
|
-
}
|
|
80
|
+
be_.source__debug?.(ctx)
|
|
85
81
|
let pending = ctx.get(Symbol.for('pending'))
|
|
86
82
|
if (!pending) {
|
|
87
83
|
pending = new Map
|
|
88
84
|
ctx.set(Symbol.for('pending'), pending)
|
|
89
85
|
}
|
|
90
|
-
|
|
91
|
-
throw new Error(
|
|
92
|
-
`be_: ${
|
|
93
|
-
String(id)
|
|
94
|
-
}: circular:\n${pending.values().map(pending_value=>
|
|
95
|
-
typeof pending_value === 'string'
|
|
96
|
-
? pending_value
|
|
97
|
-
: 'Function').join('\n')}`)
|
|
98
|
-
}
|
|
86
|
+
be_.pending__debug?.(pending)
|
|
99
87
|
pending.set(be, id || be)
|
|
100
88
|
let val = val__new ? val__new(argv__ctx, be, params) : null
|
|
101
89
|
ctx.set(be, val)
|
package/all/rmemo/index.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
export declare function rmemo_<val_T>(
|
|
2
2
|
def:rmemo_def_T<val_T>,
|
|
3
3
|
...subscriber_a:rmemo_subscriber_T<val_T>[]
|
|
4
|
-
):
|
|
4
|
+
):read_rmemo_T<val_T>
|
|
5
5
|
export declare function rsig_<val_T>(
|
|
6
6
|
init_val:val_T,
|
|
7
7
|
...subscriber_a:rmemo_subscriber_T<val_T>[]
|
|
8
|
-
):
|
|
9
|
-
export type rmemo_T<val_T> =
|
|
10
|
-
export type
|
|
11
|
-
export type
|
|
8
|
+
):readwrite_rmemo_T<val_T>
|
|
9
|
+
export type rmemo_T<val_T> = readwrite_rmemo_T<val_T>|read_rmemo_T<val_T>
|
|
10
|
+
export type readwrite_rmemo_T<val_T> = ((val?:val_T)=>val_T)&rmemo_o_T<val_T>
|
|
11
|
+
export type read_rmemo_T<val_T> = (()=>val_T)&read_rmemo_o_T<val_T>
|
|
12
|
+
export type rmemo_def_T<val_T> = (rmemo:readwrite_rmemo_T<val_T>)=>val_T
|
|
13
|
+
export type rmemo_subscriber_T<val_T> = (rmemo:readwrite_rmemo_T<val_T>)=>unknown
|
|
12
14
|
export type rmemo_o_T<val_T> = {
|
|
13
15
|
_:val_T
|
|
14
|
-
|
|
16
|
+
go():unknown
|
|
17
|
+
onset(val:val_T):unknown
|
|
18
|
+
refresh():val_T
|
|
19
|
+
}&read_rmemo_o_T<val_T>
|
|
20
|
+
export type read_rmemo_o_T<val_T> = {
|
|
21
|
+
readonly _:val_T
|
|
15
22
|
go():unknown
|
|
16
23
|
onset(val:val_T):unknown
|
|
17
24
|
refresh():val_T
|
package/all/rmemo/index.js
CHANGED
|
@@ -21,13 +21,15 @@ export function rmemo_(_f, ...subscriber_a) {
|
|
|
21
21
|
rmemo$._rS = new Set
|
|
22
22
|
rmemo$.go = ()=>(rmemo$(), rmemo$)
|
|
23
23
|
rmemo$.onset = ()=>0
|
|
24
|
+
let c = 0
|
|
24
25
|
Object.defineProperty(rmemo$, '_', {
|
|
25
26
|
get() {
|
|
26
27
|
if (!_a.length) {
|
|
27
28
|
let prev_ref = cur_ref
|
|
28
29
|
cur_ref = _r
|
|
29
30
|
try {
|
|
30
|
-
_a[0] = _f(rmemo$)
|
|
31
|
+
// _a[0] = _f(rmemo$)
|
|
32
|
+
rmemo$._ = _f(rmemo$)
|
|
31
33
|
} finally {
|
|
32
34
|
cur_ref = prev_ref
|
|
33
35
|
}
|
|
@@ -49,14 +51,17 @@ export function rmemo_(_f, ...subscriber_a) {
|
|
|
49
51
|
}
|
|
50
52
|
})
|
|
51
53
|
rmemo$.refresh = val=>{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (length) {
|
|
54
|
+
if (val !== _a[0]) {
|
|
55
|
+
_a[0] = val
|
|
56
|
+
rmemo$.onset(val)
|
|
56
57
|
let run_queue = !queue[0]
|
|
57
58
|
for (let ref of rmemo$._rS) {
|
|
58
59
|
if (!~queue.indexOf(ref)) queue.push(ref)
|
|
59
60
|
}
|
|
61
|
+
if (!rmemo$._sa) {
|
|
62
|
+
rmemo$._sa = subscriber_a.map(subscriber=>
|
|
63
|
+
rmemo_(()=>subscriber(rmemo$)).go())
|
|
64
|
+
}
|
|
60
65
|
if (run_queue) {
|
|
61
66
|
for (let ref; ref = queue.shift();) {
|
|
62
67
|
if (queue.some(_ref=>ref.l > _ref.l)) {
|
|
@@ -69,8 +74,6 @@ export function rmemo_(_f, ...subscriber_a) {
|
|
|
69
74
|
}
|
|
70
75
|
return rmemo$
|
|
71
76
|
}
|
|
72
|
-
rmemo$._sa = subscriber_a.map(subscriber=>
|
|
73
|
-
rmemo_(()=>subscriber(rmemo$)).go())
|
|
74
77
|
return rmemo$
|
|
75
78
|
}
|
|
76
79
|
/**
|
package/all/rmemo/index.test.ts
CHANGED
|
@@ -37,21 +37,29 @@ test('rsig_|async subsubscriber|case 1', async ()=>{
|
|
|
37
37
|
let user0 = { id: 'id-0' }
|
|
38
38
|
let user1 = { id: 'id-1' }
|
|
39
39
|
let id$ = rsig_('id-0')
|
|
40
|
+
let count = 0
|
|
40
41
|
let user$ = rsig_<{ id:string }|null>(
|
|
41
42
|
null,
|
|
42
43
|
async (_user$)=>{
|
|
44
|
+
count++
|
|
43
45
|
id$()
|
|
44
46
|
let user:{ id:string } = await new Promise(_resolve=>resolve = _resolve)
|
|
45
47
|
_user$(user)
|
|
46
48
|
})
|
|
49
|
+
equal(count, 0)
|
|
47
50
|
equal(user$(), null)
|
|
51
|
+
equal(count, 1)
|
|
48
52
|
resolve!(user0)
|
|
49
53
|
await sleep(0)
|
|
54
|
+
equal(count, 1)
|
|
50
55
|
equal(user$(), user0)
|
|
56
|
+
equal(count, 1)
|
|
51
57
|
id$('id-1')
|
|
58
|
+
equal(count, 2)
|
|
52
59
|
equal(user$(), user0)
|
|
53
60
|
resolve!(user1)
|
|
54
61
|
await sleep(0)
|
|
62
|
+
equal(count, 2)
|
|
55
63
|
})
|
|
56
64
|
test('rsig_|async subsubscriber|case 2', async ()=>{
|
|
57
65
|
let a$ = rsig_(1)
|
|
@@ -114,9 +122,10 @@ test('prevents diamond dependency problem 1', ()=>{
|
|
|
114
122
|
let b$ = rmemo_(()=>a$().replace('a', 'b'))
|
|
115
123
|
let c$ = rmemo_(()=>a$().replace('a', 'c'))
|
|
116
124
|
let d$ = rmemo_(()=>a$().replace('a', 'd'))
|
|
117
|
-
|
|
125
|
+
rmemo_(()=>`${b$()}${c$()}${d$()}`,
|
|
118
126
|
combined$=>
|
|
119
|
-
values.push(combined$())
|
|
127
|
+
values.push(combined$())
|
|
128
|
+
).go()
|
|
120
129
|
deepStrictEqual(values, ['b0c0d0'])
|
|
121
130
|
store$(1)
|
|
122
131
|
store$(2)
|
|
@@ -130,9 +139,10 @@ test('prevents diamond dependency problem 2', ()=>{
|
|
|
130
139
|
let c$ = rmemo_(()=>b$().replace('b', 'c'))
|
|
131
140
|
let d$ = rmemo_(()=>c$().replace('c', 'd'))
|
|
132
141
|
let e$ = rmemo_(()=>d$().replace('d', 'e'))
|
|
133
|
-
|
|
142
|
+
rmemo_<string>(
|
|
134
143
|
()=>[a$(), e$()].join(''),
|
|
135
|
-
combined$=>values.push(combined$())
|
|
144
|
+
combined$=>values.push(combined$())
|
|
145
|
+
).go()
|
|
136
146
|
deepStrictEqual(values, ['a0e0'])
|
|
137
147
|
store$(1)
|
|
138
148
|
deepStrictEqual(values, ['a0e0', 'a1e1'])
|
|
@@ -146,7 +156,8 @@ test('prevents diamond dependency problem 3', ()=>{
|
|
|
146
156
|
let d$ = rmemo_(()=>c$().replace('c', 'd'))
|
|
147
157
|
rmemo_<string>(
|
|
148
158
|
()=>`${a$()}${b$()}${c$()}${d$()}`,
|
|
149
|
-
combined$=>values.push(combined$())
|
|
159
|
+
combined$=>values.push(combined$())
|
|
160
|
+
).go()
|
|
150
161
|
deepStrictEqual(values, ['a0b0c0d0'])
|
|
151
162
|
store$(1)
|
|
152
163
|
deepStrictEqual(values, ['a0b0c0d0', 'a1b1c1d1'])
|
|
@@ -168,10 +179,12 @@ test('autosubscribe: prevents diamond dependency problem 4 (complex)', ()=>{
|
|
|
168
179
|
let g$ = rmemo_(()=>`g${f$()}`)
|
|
169
180
|
rmemo_(
|
|
170
181
|
()=>e$(),
|
|
171
|
-
combined1$=>values.push(combined1$())
|
|
182
|
+
combined1$=>values.push(combined1$())
|
|
183
|
+
).go()
|
|
172
184
|
rmemo_(
|
|
173
185
|
()=>[e$(), g$()].join(''),
|
|
174
|
-
combined2$=>values.push(combined2$())
|
|
186
|
+
combined2$=>values.push(combined2$())
|
|
187
|
+
).go()
|
|
175
188
|
deepStrictEqual(values, ['eca0b0da0', 'eca0b0da0gfeca0b0da0'])
|
|
176
189
|
store1$(1)
|
|
177
190
|
store2$(2)
|
|
@@ -221,7 +234,8 @@ test('prevents diamond dependency problem 6', ()=>{
|
|
|
221
234
|
let c$ = rmemo_(()=>b$().replace('b', 'c'))
|
|
222
235
|
rmemo_(
|
|
223
236
|
()=>`${a$()}${c$()}`,
|
|
224
|
-
combined$=>values.push(combined$())
|
|
237
|
+
combined$=>values.push(combined$())
|
|
238
|
+
).go()
|
|
225
239
|
deepStrictEqual(values, ['a0c0'])
|
|
226
240
|
store1$(1)
|
|
227
241
|
deepStrictEqual(values, ['a0c0', 'a1c0'])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.2",
|
|
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.1.
|
|
117
|
+
"tsx": "^4.1.3",
|
|
118
118
|
"typescript": "next",
|
|
119
119
|
"uvu": "^0.5.6"
|
|
120
120
|
},
|
|
@@ -129,21 +129,21 @@
|
|
|
129
129
|
"import": {
|
|
130
130
|
"./be": "{ be_ }"
|
|
131
131
|
},
|
|
132
|
-
"limit": "
|
|
132
|
+
"limit": "398 B"
|
|
133
133
|
},
|
|
134
134
|
{
|
|
135
135
|
"name": "rmemo",
|
|
136
136
|
"import": {
|
|
137
137
|
"./rmemo": "{ rmemo_ }"
|
|
138
138
|
},
|
|
139
|
-
"limit": "
|
|
139
|
+
"limit": "358 B"
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
142
|
"name": "rmemo signal",
|
|
143
143
|
"import": {
|
|
144
144
|
"./rmemo": "{ rsig_ }"
|
|
145
145
|
},
|
|
146
|
-
"limit": "
|
|
146
|
+
"limit": "385 B"
|
|
147
147
|
}
|
|
148
148
|
],
|
|
149
149
|
"scripts": {
|