ctx-core 4.9.1 → 4.10.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/rmemo/index.d.ts +2 -0
- package/all/rmemo/index.js +20 -0
- package/all/rmemo/index.test.ts +27 -1
- package/package.json +5 -5
package/all/rmemo/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare function memosig_<val_T>(
|
|
|
11
11
|
...subscriber_a:rmemo_subscriber_T<val_T>[]
|
|
12
12
|
):sig_T<val_T>
|
|
13
13
|
// TODO: lock_memosig_
|
|
14
|
+
export declare function on(rmemo:rmemo_T<unknown>):void
|
|
15
|
+
export declare function off(rmemo:rmemo_T<unknown>):void
|
|
14
16
|
export type rmemo_T<val_T> = memo_T<val_T>|sig_T<val_T>
|
|
15
17
|
export type memo_T<val_T> = (()=>val_T)&{
|
|
16
18
|
readonly _:val_T
|
package/all/rmemo/index.js
CHANGED
|
@@ -94,3 +94,23 @@ export function sig_(init_val, ...subscriber_a) {
|
|
|
94
94
|
...subscriber_a)
|
|
95
95
|
}
|
|
96
96
|
// TODO: lock_memosig_
|
|
97
|
+
/**
|
|
98
|
+
* Call the rmemo & enable updates from it's parents.
|
|
99
|
+
* @param {rmemo_T}rmemo
|
|
100
|
+
*/
|
|
101
|
+
export function on(rmemo) {
|
|
102
|
+
if (rmemo.r?.d) {
|
|
103
|
+
rmemo.r.deref = rmemo.r.d
|
|
104
|
+
}
|
|
105
|
+
rmemo.f()
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Disable updates from the rmemo's parents.
|
|
109
|
+
* @param {rmemo_T}rmemo
|
|
110
|
+
*/
|
|
111
|
+
export function off(rmemo) {
|
|
112
|
+
if (rmemo.r) {
|
|
113
|
+
rmemo.r.d ||= rmemo.r.deref
|
|
114
|
+
rmemo.r.deref = ()=>{}
|
|
115
|
+
}
|
|
116
|
+
}
|
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 { memo_, type memo_T, memosig_, sig_ } from './index.js'
|
|
7
|
+
import { memo_, type memo_T, memosig_, off, on, sig_ } from './index.js'
|
|
8
8
|
test('memo_|static value', ()=>{
|
|
9
9
|
let count = 0
|
|
10
10
|
const memo = memo_(()=>{
|
|
@@ -410,4 +410,30 @@ test('computes initial value when argument is undefined', ()=>{
|
|
|
410
410
|
equal(one$(), undefined)
|
|
411
411
|
equal(two$(), false)
|
|
412
412
|
})
|
|
413
|
+
test('.on + .off', ()=>{
|
|
414
|
+
const base$ = sig_(1)
|
|
415
|
+
let count = 0
|
|
416
|
+
const memo$ = memo_(()=>{
|
|
417
|
+
count++
|
|
418
|
+
return base$() + 10
|
|
419
|
+
})
|
|
420
|
+
equal(memo$(), 11)
|
|
421
|
+
equal(count, 1)
|
|
422
|
+
base$._ = 2
|
|
423
|
+
equal(memo$(), 12)
|
|
424
|
+
equal(count, 2)
|
|
425
|
+
off(memo$)
|
|
426
|
+
base$._ = 3
|
|
427
|
+
equal(memo$(), 12)
|
|
428
|
+
equal(count, 2)
|
|
429
|
+
on(memo$)
|
|
430
|
+
equal(memo$(), 13)
|
|
431
|
+
equal(count, 3)
|
|
432
|
+
off(memo$)
|
|
433
|
+
on(memo$)
|
|
434
|
+
equal(count, 4)
|
|
435
|
+
base$._ = 4
|
|
436
|
+
equal(memo$(), 14)
|
|
437
|
+
equal(count, 5)
|
|
438
|
+
})
|
|
413
439
|
test.run()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"./package.json": "./package.json"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
|
-
"@arethetypeswrong/cli": "^0.13.
|
|
108
|
+
"@arethetypeswrong/cli": "^0.13.3",
|
|
109
109
|
"@size-limit/preset-small-lib": "^11.0.0",
|
|
110
110
|
"@types/node": "^20.10.3",
|
|
111
111
|
"@types/sinon": "^17.0.2",
|
|
@@ -150,14 +150,14 @@
|
|
|
150
150
|
"import": {
|
|
151
151
|
"./rmemo": "{ memo_ }"
|
|
152
152
|
},
|
|
153
|
-
"limit": "
|
|
153
|
+
"limit": "340 B"
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
156
|
"name": "memo_ sig_",
|
|
157
157
|
"import": {
|
|
158
158
|
"./rmemo": "{ sig_, memo_ }"
|
|
159
159
|
},
|
|
160
|
-
"limit": "
|
|
160
|
+
"limit": "355 B"
|
|
161
161
|
},
|
|
162
162
|
{
|
|
163
163
|
"name": "memo_ sig_ be_ ctx_",
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
"import": {
|
|
172
172
|
"./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
|
|
173
173
|
},
|
|
174
|
-
"limit": "
|
|
174
|
+
"limit": "600 B"
|
|
175
175
|
}
|
|
176
176
|
],
|
|
177
177
|
"scripts": {
|