ctx-core 3.2.0 → 3.3.0
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/ctx/index.js +3 -6
- package/all/rmemo/index.js +10 -7
- package/all/rmemo/index.test.ts +22 -16
- package/package.json +15 -8
- package/rmemo/index.d.ts +2 -0
- package/rmemo/index.js +2 -0
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/ctx/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { flatten } from '../flatten/index.js'
|
|
2
|
-
import { isArray } from '../isArray/index.js'
|
|
3
|
-
const ctx_sym = Symbol.for('ctx')
|
|
4
1
|
/**
|
|
5
2
|
* @returns {import('../be_/index.js').MapCtx}
|
|
6
3
|
* @private
|
|
7
4
|
*/
|
|
8
5
|
export function ctx__new() {
|
|
9
|
-
return new Map([[
|
|
6
|
+
return new Map([[Symbol.for('ctx'), true]])
|
|
10
7
|
}
|
|
11
8
|
export { ctx__new as ctx_ }
|
|
12
9
|
/**
|
|
@@ -15,9 +12,9 @@ export { ctx__new as ctx_ }
|
|
|
15
12
|
* @private
|
|
16
13
|
*/
|
|
17
14
|
export function is_ctx_(val) {
|
|
18
|
-
if (!isArray(val)) return !!(val instanceof Map && val.get(
|
|
15
|
+
if (!Array.isArray(val)) return !!(val instanceof Map && val.get(Symbol.for('ctx')))
|
|
19
16
|
if (!val.length) return false
|
|
20
|
-
|
|
17
|
+
let flat__val = val.flat(Infinity)
|
|
21
18
|
for (let i = 0; i < flat__val.length; i++) {
|
|
22
19
|
if (!is_ctx_(flat__val[i])) return false
|
|
23
20
|
}
|
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,29 +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
|
|
40
|
+
let count = 0
|
|
41
41
|
let user$ = rsig_<{ id:string }|null>(
|
|
42
42
|
null,
|
|
43
43
|
async (_user$)=>{
|
|
44
|
-
|
|
44
|
+
count++
|
|
45
45
|
id$()
|
|
46
46
|
let user:{ id:string } = await new Promise(_resolve=>resolve = _resolve)
|
|
47
47
|
_user$(user)
|
|
48
48
|
})
|
|
49
|
-
|
|
49
|
+
equal(count, 0)
|
|
50
50
|
equal(user$(), null)
|
|
51
|
-
equal(
|
|
51
|
+
equal(count, 1)
|
|
52
52
|
resolve!(user0)
|
|
53
53
|
await sleep(0)
|
|
54
|
-
equal(
|
|
54
|
+
equal(count, 1)
|
|
55
55
|
equal(user$(), user0)
|
|
56
|
-
equal(
|
|
56
|
+
equal(count, 1)
|
|
57
57
|
id$('id-1')
|
|
58
|
-
equal(
|
|
58
|
+
equal(count, 2)
|
|
59
59
|
equal(user$(), user0)
|
|
60
60
|
resolve!(user1)
|
|
61
61
|
await sleep(0)
|
|
62
|
-
equal(
|
|
62
|
+
equal(count, 2)
|
|
63
63
|
})
|
|
64
64
|
test('rsig_|async subsubscriber|case 2', async ()=>{
|
|
65
65
|
let a$ = rsig_(1)
|
|
@@ -122,9 +122,10 @@ test('prevents diamond dependency problem 1', ()=>{
|
|
|
122
122
|
let b$ = rmemo_(()=>a$().replace('a', 'b'))
|
|
123
123
|
let c$ = rmemo_(()=>a$().replace('a', 'c'))
|
|
124
124
|
let d$ = rmemo_(()=>a$().replace('a', 'd'))
|
|
125
|
-
|
|
125
|
+
rmemo_(()=>`${b$()}${c$()}${d$()}`,
|
|
126
126
|
combined$=>
|
|
127
|
-
values.push(combined$())
|
|
127
|
+
values.push(combined$())
|
|
128
|
+
).go()
|
|
128
129
|
deepStrictEqual(values, ['b0c0d0'])
|
|
129
130
|
store$(1)
|
|
130
131
|
store$(2)
|
|
@@ -138,9 +139,10 @@ test('prevents diamond dependency problem 2', ()=>{
|
|
|
138
139
|
let c$ = rmemo_(()=>b$().replace('b', 'c'))
|
|
139
140
|
let d$ = rmemo_(()=>c$().replace('c', 'd'))
|
|
140
141
|
let e$ = rmemo_(()=>d$().replace('d', 'e'))
|
|
141
|
-
|
|
142
|
+
rmemo_<string>(
|
|
142
143
|
()=>[a$(), e$()].join(''),
|
|
143
|
-
combined$=>values.push(combined$())
|
|
144
|
+
combined$=>values.push(combined$())
|
|
145
|
+
).go()
|
|
144
146
|
deepStrictEqual(values, ['a0e0'])
|
|
145
147
|
store$(1)
|
|
146
148
|
deepStrictEqual(values, ['a0e0', 'a1e1'])
|
|
@@ -154,7 +156,8 @@ test('prevents diamond dependency problem 3', ()=>{
|
|
|
154
156
|
let d$ = rmemo_(()=>c$().replace('c', 'd'))
|
|
155
157
|
rmemo_<string>(
|
|
156
158
|
()=>`${a$()}${b$()}${c$()}${d$()}`,
|
|
157
|
-
combined$=>values.push(combined$())
|
|
159
|
+
combined$=>values.push(combined$())
|
|
160
|
+
).go()
|
|
158
161
|
deepStrictEqual(values, ['a0b0c0d0'])
|
|
159
162
|
store$(1)
|
|
160
163
|
deepStrictEqual(values, ['a0b0c0d0', 'a1b1c1d1'])
|
|
@@ -176,10 +179,12 @@ test('autosubscribe: prevents diamond dependency problem 4 (complex)', ()=>{
|
|
|
176
179
|
let g$ = rmemo_(()=>`g${f$()}`)
|
|
177
180
|
rmemo_(
|
|
178
181
|
()=>e$(),
|
|
179
|
-
combined1$=>values.push(combined1$())
|
|
182
|
+
combined1$=>values.push(combined1$())
|
|
183
|
+
).go()
|
|
180
184
|
rmemo_(
|
|
181
185
|
()=>[e$(), g$()].join(''),
|
|
182
|
-
combined2$=>values.push(combined2$())
|
|
186
|
+
combined2$=>values.push(combined2$())
|
|
187
|
+
).go()
|
|
183
188
|
deepStrictEqual(values, ['eca0b0da0', 'eca0b0da0gfeca0b0da0'])
|
|
184
189
|
store1$(1)
|
|
185
190
|
store2$(2)
|
|
@@ -229,7 +234,8 @@ test('prevents diamond dependency problem 6', ()=>{
|
|
|
229
234
|
let c$ = rmemo_(()=>b$().replace('b', 'c'))
|
|
230
235
|
rmemo_(
|
|
231
236
|
()=>`${a$()}${c$()}`,
|
|
232
|
-
combined$=>values.push(combined$())
|
|
237
|
+
combined$=>values.push(combined$())
|
|
238
|
+
).go()
|
|
233
239
|
deepStrictEqual(values, ['a0c0'])
|
|
234
240
|
store1$(1)
|
|
235
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.3.0",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -125,25 +125,32 @@
|
|
|
125
125
|
"sideEffects": false,
|
|
126
126
|
"size-limit": [
|
|
127
127
|
{
|
|
128
|
-
"name": "
|
|
128
|
+
"name": "be_",
|
|
129
129
|
"import": {
|
|
130
130
|
"./be": "{ be_ }"
|
|
131
131
|
},
|
|
132
|
-
"limit": "
|
|
132
|
+
"limit": "398 B"
|
|
133
133
|
},
|
|
134
134
|
{
|
|
135
|
-
"name": "
|
|
135
|
+
"name": "rmemo_",
|
|
136
136
|
"import": {
|
|
137
137
|
"./rmemo": "{ rmemo_ }"
|
|
138
138
|
},
|
|
139
|
-
"limit": "
|
|
139
|
+
"limit": "358 B"
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
|
-
"name": "
|
|
142
|
+
"name": "rmemo_ signal_",
|
|
143
143
|
"import": {
|
|
144
|
-
"./rmemo": "{ rsig_ }"
|
|
144
|
+
"./rmemo": "{ rsig_, rmemo_ }"
|
|
145
145
|
},
|
|
146
|
-
"limit": "
|
|
146
|
+
"limit": "387 B"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"name": "rmemo_ signal_ be_ ctx__new",
|
|
150
|
+
"import": {
|
|
151
|
+
"./rmemo": "{ rsig_, rmemo_, be_, ctx__new }"
|
|
152
|
+
},
|
|
153
|
+
"limit": "771 B"
|
|
147
154
|
}
|
|
148
155
|
],
|
|
149
156
|
"scripts": {
|
package/rmemo/index.d.ts
CHANGED
package/rmemo/index.js
CHANGED