ctx-core 5.14.0 → 5.16.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_lock_memosig_triple/index.d.ts +7 -5
- package/all/be_lock_memosig_triple/index.js +12 -11
- package/all/be_lock_memosig_triple/index.test.ts +18 -17
- package/all/be_memo_pair/index.d.ts +6 -4
- package/all/be_memo_pair/index.js +12 -10
- package/all/be_memo_pair/index.test.ts +13 -13
- package/all/be_memosig_triple/index.d.ts +6 -4
- package/all/be_memosig_triple/index.test.ts +14 -13
- package/all/be_sig_triple/index.d.ts +9 -7
- package/all/be_sig_triple/index.js +12 -10
- package/all/be_sig_triple/index.test.ts +8 -6
- package/all/is_development/index.js +2 -1
- package/all/is_production/index.js +2 -1
- package/all/rmemo/index.d.ts +17 -21
- package/all/rmemo/index.js +46 -44
- package/all/rmemo/index.test.ts +68 -50
- package/package.json +248 -249
- package/rmemo/index.d.ts +2 -2
- package/rmemo/index.js +2 -2
package/all/rmemo/index.test.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { deepStrictEqual } from 'node:assert'
|
|
|
4
4
|
import { test } from 'uvu'
|
|
5
5
|
import { equal } from 'uvu/assert'
|
|
6
6
|
import { sleep } from '../sleep/index.js'
|
|
7
|
-
import { lock_memosig_, memo_, type memo_T, memosig_, rmemo__off, rmemo__on,
|
|
7
|
+
import { lock_memosig_, memo_, type memo_T, memosig_, rmemo__off, rmemo__on, rmemo__add, sig_ } from './index.js'
|
|
8
8
|
test('memo_|static value', ()=>{
|
|
9
9
|
let count = 0
|
|
10
10
|
const memo = memo_(()=>{
|
|
@@ -171,15 +171,29 @@ test('sig_|undefined', ()=>{
|
|
|
171
171
|
equal(sig(), undefined)
|
|
172
172
|
equal(memo(), undefined)
|
|
173
173
|
})
|
|
174
|
+
test('rmemo|subscriber|has strong reference to the return value', ()=>{
|
|
175
|
+
const add_arg_aa:[memo_T<number|undefined>, number|undefined][] = []
|
|
176
|
+
const num$ = sig_<number|undefined>(
|
|
177
|
+
undefined
|
|
178
|
+
).add<number>((sig, old_val)=>{
|
|
179
|
+
add_arg_aa.push([sig, old_val])
|
|
180
|
+
return 99
|
|
181
|
+
})
|
|
182
|
+
equal(num$.a, undefined)
|
|
183
|
+
equal(add_arg_aa, [])
|
|
184
|
+
equal(num$(), undefined)
|
|
185
|
+
equal(num$.a![0][1], 99)
|
|
186
|
+
equal(add_arg_aa, [[num$, undefined]])
|
|
187
|
+
})
|
|
174
188
|
test('sig_|subscriber|notified if sig is set before read', ()=>{
|
|
175
189
|
let count = 0
|
|
176
190
|
let subscriber__num:number|undefined = undefined
|
|
177
191
|
const num$ = sig_<number|undefined>(
|
|
178
|
-
undefined
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
undefined
|
|
193
|
+
).add(num$=>{
|
|
194
|
+
count++
|
|
195
|
+
subscriber__num = num$()
|
|
196
|
+
})
|
|
183
197
|
equal(count, 0)
|
|
184
198
|
equal(subscriber__num, undefined)
|
|
185
199
|
num$._ = 1
|
|
@@ -193,11 +207,11 @@ test('sig_|subscriber|sets sig', ()=>{
|
|
|
193
207
|
const base$ = sig_(0)
|
|
194
208
|
let count = 0
|
|
195
209
|
const num$ = sig_(
|
|
196
|
-
0
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
210
|
+
0
|
|
211
|
+
).add(async num$=>{
|
|
212
|
+
count++
|
|
213
|
+
num$._ = base$() + 1
|
|
214
|
+
})
|
|
201
215
|
equal(count, 0)
|
|
202
216
|
equal(num$(), 1)
|
|
203
217
|
equal(count, 1)
|
|
@@ -212,13 +226,13 @@ test('sig_|async subsubscriber|case 1', async ()=>{
|
|
|
212
226
|
const id$ = sig_('id-0')
|
|
213
227
|
let count = 0
|
|
214
228
|
const user$ = sig_<{ id:string }|null>(
|
|
215
|
-
null
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
229
|
+
null
|
|
230
|
+
).add(async (_user$)=>{
|
|
231
|
+
count++
|
|
232
|
+
id$()
|
|
233
|
+
const user:{ id:string } = await new Promise(_resolve=>resolve = _resolve)
|
|
234
|
+
_user$._ = user
|
|
235
|
+
})
|
|
222
236
|
equal(count, 0)
|
|
223
237
|
equal(user$(), null)
|
|
224
238
|
equal(count, 1)
|
|
@@ -239,14 +253,15 @@ test('sig_|async subsubscriber|case 2', async ()=>{
|
|
|
239
253
|
const b$ = sig_(2)
|
|
240
254
|
const sleepCycles = 5
|
|
241
255
|
const taskArgumentsCalls:number[][] = []
|
|
242
|
-
const sum$ = sig_<null|number>(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
256
|
+
const sum$ = sig_<null|number>(
|
|
257
|
+
null
|
|
258
|
+
).add(async sum$=>{
|
|
259
|
+
taskArgumentsCalls.push([a$(), b$()])
|
|
260
|
+
for (let i = 0; i < sleepCycles; i++) {
|
|
261
|
+
await Promise.resolve()
|
|
262
|
+
}
|
|
263
|
+
sum$._ = a$() + b$()
|
|
264
|
+
})
|
|
250
265
|
equal(sum$(), null)
|
|
251
266
|
deepStrictEqual(taskArgumentsCalls, [[1, 2]])
|
|
252
267
|
a$._ = 10
|
|
@@ -295,10 +310,10 @@ test('prevents diamond dependency problem 1', ()=>{
|
|
|
295
310
|
const b$ = memo_(()=>a$().replace('a', 'b'))
|
|
296
311
|
const c$ = memo_(()=>a$().replace('a', 'c'))
|
|
297
312
|
const d$ = memo_(()=>a$().replace('a', 'd'))
|
|
298
|
-
memo_(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
313
|
+
memo_(
|
|
314
|
+
()=>`${b$()}${c$()}${d$()}`)
|
|
315
|
+
.add(combined$=>values.push(combined$()))
|
|
316
|
+
()
|
|
302
317
|
deepStrictEqual(values, ['b0c0d0'])
|
|
303
318
|
store$._ = 1
|
|
304
319
|
store$._ = 2
|
|
@@ -313,9 +328,9 @@ test('prevents diamond dependency problem 2', ()=>{
|
|
|
313
328
|
const d$ = memo_(()=>c$().replace('c', 'd'))
|
|
314
329
|
const e$ = memo_(()=>d$().replace('d', 'e'))
|
|
315
330
|
memo_<string>(
|
|
316
|
-
()=>[a$(), e$()].join('')
|
|
317
|
-
$=>values.push($())
|
|
318
|
-
|
|
331
|
+
()=>[a$(), e$()].join(''))
|
|
332
|
+
.add($=>values.push($()))
|
|
333
|
+
()
|
|
319
334
|
deepStrictEqual(values, ['a0e0'])
|
|
320
335
|
store$._ = 1
|
|
321
336
|
deepStrictEqual(values, ['a0e0', 'a1e1'])
|
|
@@ -328,9 +343,9 @@ test('prevents diamond dependency problem 3', ()=>{
|
|
|
328
343
|
const c$ = memo_(()=>b$().replace('b', 'c'))
|
|
329
344
|
const d$ = memo_(()=>c$().replace('c', 'd'))
|
|
330
345
|
memo_<string>(
|
|
331
|
-
()=>`${a$()}${b$()}${c$()}${d$()}
|
|
332
|
-
combined$=>values.push(combined$())
|
|
333
|
-
|
|
346
|
+
()=>`${a$()}${b$()}${c$()}${d$()}`)
|
|
347
|
+
.add(combined$=>values.push(combined$()))
|
|
348
|
+
()
|
|
334
349
|
deepStrictEqual(values, ['a0b0c0d0'])
|
|
335
350
|
store$._ = 1
|
|
336
351
|
deepStrictEqual(values, ['a0b0c0d0', 'a1b1c1d1'])
|
|
@@ -347,13 +362,13 @@ test('autosubscribe: prevents diamond dependency problem 4 (complex)', ()=>{
|
|
|
347
362
|
const f$ = memo_(()=>`f${e$()}`)
|
|
348
363
|
const g$ = memo_(()=>`g${f$()}`)
|
|
349
364
|
memo_(
|
|
350
|
-
()=>e$()
|
|
351
|
-
combined1$=>values.push(combined1$())
|
|
352
|
-
|
|
365
|
+
()=>e$())
|
|
366
|
+
.add(combined1$=>values.push(combined1$()))
|
|
367
|
+
()
|
|
353
368
|
memo_(
|
|
354
|
-
()=>[e$(), g$()].join('')
|
|
355
|
-
combined2$=>values.push(combined2$())
|
|
356
|
-
|
|
369
|
+
()=>[e$(), g$()].join(''))
|
|
370
|
+
.add(combined2$=>values.push(combined2$()))
|
|
371
|
+
()
|
|
357
372
|
deepStrictEqual(values, ['eca0b0da0', 'eca0b0da0gfeca0b0da0'])
|
|
358
373
|
store1$._ = 1
|
|
359
374
|
store2$._ = 2
|
|
@@ -400,9 +415,9 @@ test('prevents diamond dependency problem 6', ()=>{
|
|
|
400
415
|
const b$ = memo_(()=>`b${store2$()}`)
|
|
401
416
|
const c$ = memo_(()=>b$().replace('b', 'c'))
|
|
402
417
|
memo_(
|
|
403
|
-
()=>`${a$()}${c$()}
|
|
404
|
-
combined$=>values.push(combined$())
|
|
405
|
-
|
|
418
|
+
()=>`${a$()}${c$()}`)
|
|
419
|
+
.add(combined$=>values.push(combined$()))
|
|
420
|
+
()
|
|
406
421
|
deepStrictEqual(values, ['a0c0'])
|
|
407
422
|
store1$._ = 1
|
|
408
423
|
deepStrictEqual(values, ['a0c0', 'a1c0'])
|
|
@@ -413,9 +428,9 @@ test('prevents dependency listeners from being out of order', ()=>{
|
|
|
413
428
|
return `${base$()}a`
|
|
414
429
|
})
|
|
415
430
|
const values:string[] = []
|
|
416
|
-
const b$ = memo_(
|
|
417
|
-
|
|
418
|
-
|
|
431
|
+
const b$ = memo_(
|
|
432
|
+
()=>`${a$()}b`)
|
|
433
|
+
.add(b$=>values.push(b$()))
|
|
419
434
|
equal(b$(), '0ab')
|
|
420
435
|
deepStrictEqual(values, ['0ab'])
|
|
421
436
|
equal(a$(), '0a')
|
|
@@ -454,14 +469,17 @@ test('.rmemo__on + .rmemo__off', ()=>{
|
|
|
454
469
|
equal(memo$(), 14)
|
|
455
470
|
equal(count, 5)
|
|
456
471
|
})
|
|
457
|
-
test('
|
|
472
|
+
test('rmemo__add', ()=>{
|
|
458
473
|
const base$ = sig_(1)
|
|
459
474
|
let count = 0
|
|
460
475
|
const subscriber_base_a:number[] = []
|
|
461
|
-
const off =
|
|
476
|
+
const off = rmemo__add(base$, ()=>{
|
|
462
477
|
count++
|
|
463
478
|
subscriber_base_a.push(base$())
|
|
464
479
|
})
|
|
480
|
+
equal(subscriber_base_a, [])
|
|
481
|
+
equal(count, 0)
|
|
482
|
+
base$()
|
|
465
483
|
equal(subscriber_base_a, [1])
|
|
466
484
|
equal(count, 1)
|
|
467
485
|
base$._ = 2
|