ctx-core 5.4.0 → 5.5.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/file_exists/index.js +3 -4
- package/all/rmemo/index.d.ts +1 -0
- package/all/rmemo/index.js +18 -0
- package/all/rmemo/index.test.ts +19 -1
- package/all/rmemo__wait/index.d.ts +5 -2
- package/all/rmemo__wait/index.js +11 -3
- package/all/rmemo__wait/index.test.ts +11 -16
- package/package.json +4 -4
- package/rmemo/index.d.ts +2 -0
- package/rmemo/index.js +2 -0
- package/tsconfig.json +0 -1
package/all/file_exists/index.js
CHANGED
|
@@ -8,11 +8,10 @@ import { waitfor } from '../waitfor/index.js'
|
|
|
8
8
|
export async function file_exists_(path) {
|
|
9
9
|
return (
|
|
10
10
|
(process_release_name ?? false)
|
|
11
|
-
&& import('node:fs/promises').then(({ access, constants })=>
|
|
12
|
-
|
|
11
|
+
&& import('node:fs/promises').then(({ access, constants })=>
|
|
12
|
+
access(path, constants.F_OK)
|
|
13
13
|
.then(()=>true)
|
|
14
|
-
.catch(()=>false)
|
|
15
|
-
}))
|
|
14
|
+
.catch(()=>false)))
|
|
16
15
|
}
|
|
17
16
|
export {
|
|
18
17
|
file_exists_ as path__exists_
|
package/all/rmemo/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare function lock_memosig_<val_T>(
|
|
|
17
17
|
):sig_T<val_T>
|
|
18
18
|
export declare function on(rmemo:rmemo_T<unknown>):void
|
|
19
19
|
export declare function off(rmemo:rmemo_T<unknown>):void
|
|
20
|
+
export declare function rmemo__subscribe(rmemo:rmemo_T<unknown>, listener:()=>unknown):()=>void
|
|
20
21
|
export type rmemo_T<val_T> = memo_T<val_T>|sig_T<val_T>|lock_memosig_T<val_T>
|
|
21
22
|
export type memo_T<val_T> = (()=>val_T)&{
|
|
22
23
|
readonly _:val_T
|
package/all/rmemo/index.js
CHANGED
|
@@ -135,3 +135,21 @@ export function off(rmemo) {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Bind reactive listener onto the given memo to prevent GC.
|
|
140
|
+
* The listener can autosubscribe to any rmemo.
|
|
141
|
+
* Returns an "off" function which deactivates the reactive listener & removes the GC binding from the given memo.
|
|
142
|
+
* @param {rmemo_T}memo
|
|
143
|
+
* @param {()=>unknown}listener
|
|
144
|
+
* @returns {()=>void}
|
|
145
|
+
*/
|
|
146
|
+
export function rmemo__subscribe(memo, listener) {
|
|
147
|
+
let listener_memo = memo_(()=>listener())
|
|
148
|
+
listener_memo()
|
|
149
|
+
memo.b ??= []
|
|
150
|
+
memo.b.push(listener_memo)
|
|
151
|
+
return ()=>{
|
|
152
|
+
off(listener_memo)
|
|
153
|
+
memo.b.splice(memo.b.indexOf(listener_memo), 1)
|
|
154
|
+
}
|
|
155
|
+
}
|
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_, off, on, sig_ } from './index.js'
|
|
7
|
+
import { lock_memosig_, memo_, type memo_T, memosig_, off, on, rmemo__subscribe, sig_ } from './index.js'
|
|
8
8
|
test('memo_|static value', ()=>{
|
|
9
9
|
let count = 0
|
|
10
10
|
const memo = memo_(()=>{
|
|
@@ -454,4 +454,22 @@ test('.on + .off', ()=>{
|
|
|
454
454
|
equal(memo$(), 14)
|
|
455
455
|
equal(count, 5)
|
|
456
456
|
})
|
|
457
|
+
test('rmemo__subscribe', ()=>{
|
|
458
|
+
const base$ = sig_(1)
|
|
459
|
+
let count = 0
|
|
460
|
+
const subscriber_base_a:number[] = []
|
|
461
|
+
const off = rmemo__subscribe(base$, ()=>{
|
|
462
|
+
count++
|
|
463
|
+
subscriber_base_a.push(base$())
|
|
464
|
+
})
|
|
465
|
+
equal(subscriber_base_a, [1])
|
|
466
|
+
equal(count, 1)
|
|
467
|
+
base$._ = 2
|
|
468
|
+
equal(subscriber_base_a, [1, 2])
|
|
469
|
+
equal(count, 2)
|
|
470
|
+
off()
|
|
471
|
+
base$._ = 3
|
|
472
|
+
equal(subscriber_base_a, [1, 2])
|
|
473
|
+
equal(count, 2)
|
|
474
|
+
})
|
|
457
475
|
test.run()
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { rmemo_T, rmemo_val_T } from '../rmemo/index.js'
|
|
1
|
+
import type { memo_T, rmemo_T, rmemo_val_T } from '../rmemo/index.js'
|
|
2
2
|
export declare function rmemo__wait<
|
|
3
3
|
_rmemo_T extends rmemo_T<unknown> = rmemo_T<unknown>
|
|
4
4
|
>(
|
|
5
5
|
memo:_rmemo_T,
|
|
6
6
|
condition_fn:(val:rmemo_val_T<_rmemo_T>)=>unknown,
|
|
7
7
|
timeout?:number
|
|
8
|
-
):Promise<rmemo_val_T<_rmemo_T
|
|
8
|
+
):Promise<rmemo_val_T<_rmemo_T>>&{
|
|
9
|
+
// prevent early usGC
|
|
10
|
+
m:memo_T<unknown>
|
|
11
|
+
}
|
package/all/rmemo__wait/index.js
CHANGED
|
@@ -10,12 +10,20 @@ import { memo_ } from '../rmemo/index.js'
|
|
|
10
10
|
* @returns {Promise<*>|Promise<unknown>}
|
|
11
11
|
*/
|
|
12
12
|
export function rmemo__wait(rmemo, condition_fn, timeout) {
|
|
13
|
+
let memo
|
|
13
14
|
const _subscribe_wait = new Promise(resolve=>{
|
|
14
|
-
memo_(()=>{
|
|
15
|
+
memo = memo_(()=>{
|
|
15
16
|
if (condition_fn(rmemo())) {
|
|
16
17
|
resolve(rmemo())
|
|
17
18
|
}
|
|
18
|
-
})
|
|
19
|
+
})
|
|
20
|
+
memo()
|
|
19
21
|
})
|
|
20
|
-
|
|
22
|
+
let promise =
|
|
23
|
+
isNumber_(timeout)
|
|
24
|
+
? promise_timeout(_subscribe_wait, timeout)
|
|
25
|
+
: _subscribe_wait
|
|
26
|
+
// prevent GC
|
|
27
|
+
promise.m = memo
|
|
28
|
+
return promise
|
|
21
29
|
}
|
|
@@ -3,21 +3,16 @@ import { equal } from 'uvu/assert'
|
|
|
3
3
|
import { sig_ } from '../rmemo/index.js'
|
|
4
4
|
import { rmemo__wait } from './index.js'
|
|
5
5
|
test('rmemo__wait', async ()=>{
|
|
6
|
-
const subject =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
subject$._ = 1
|
|
18
|
-
equal(subject, -1)
|
|
19
|
-
equal(subject$(), 1)
|
|
20
|
-
})
|
|
21
|
-
equal(subject, 1)
|
|
6
|
+
const subject$ = sig_(-1)
|
|
7
|
+
const promise = rmemo__wait(
|
|
8
|
+
subject$,
|
|
9
|
+
subject=>subject >= 0,
|
|
10
|
+
10_000)
|
|
11
|
+
equal(promise.m.memor, [])
|
|
12
|
+
equal(subject$(), -1)
|
|
13
|
+
subject$._ = 1
|
|
14
|
+
equal(subject$(), 1)
|
|
15
|
+
await promise
|
|
16
|
+
equal(subject$(), 1)
|
|
22
17
|
})
|
|
23
18
|
test.run()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -196,21 +196,21 @@
|
|
|
196
196
|
"import": {
|
|
197
197
|
"./rmemo": "{ sig_, memo_ }"
|
|
198
198
|
},
|
|
199
|
-
"limit": "
|
|
199
|
+
"limit": "352 B"
|
|
200
200
|
},
|
|
201
201
|
{
|
|
202
202
|
"name": "memo_ sig_ be_ ctx_",
|
|
203
203
|
"import": {
|
|
204
204
|
"./rmemo": "{ sig_, memo_, be_, ctx_ }"
|
|
205
205
|
},
|
|
206
|
-
"limit": "
|
|
206
|
+
"limit": "458 B"
|
|
207
207
|
},
|
|
208
208
|
{
|
|
209
209
|
"name": "memo_ sig_ be_ ctx_ be_memo_pair_ be_sig_triple_",
|
|
210
210
|
"import": {
|
|
211
211
|
"./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
|
|
212
212
|
},
|
|
213
|
-
"limit": "
|
|
213
|
+
"limit": "552 B"
|
|
214
214
|
}
|
|
215
215
|
],
|
|
216
216
|
"scripts": {
|
package/rmemo/index.d.ts
CHANGED
package/rmemo/index.js
CHANGED