ctx-core 5.13.0 → 5.15.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/index.d.ts +3 -3
- package/all/be/index.test.ts +21 -0
- package/all/be_/index.js +7 -0
- package/all/be_/index.test.ts +9 -3
- package/all/rmemo/index.d.ts +2 -0
- package/all/rmemo/index.js +2 -6
- package/all/rmemo/index.test.ts +8 -0
- package/package.json +7 -7
package/all/be/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { be__val__new_T, be_config_T, Ctx, Ctx_wide_T } from '../be_/index.js'
|
|
2
2
|
export declare function be<
|
|
3
|
-
|
|
3
|
+
val_T extends NonNullable<unknown>,
|
|
4
4
|
ns_T extends string = '',
|
|
5
5
|
ctx_T extends Ctx = Ctx_wide_T<ns_T>
|
|
6
6
|
>(
|
|
7
7
|
ctx:ctx_T,
|
|
8
|
-
val_:be__val__new_T<
|
|
8
|
+
val_:be__val__new_T<val_T, ns_T, ctx_T>,
|
|
9
9
|
config:be_config_T<ns_T>
|
|
10
|
-
):
|
|
10
|
+
):val_T
|
|
11
11
|
export { be as b, }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { be_ } from '../be_/index.js'
|
|
4
|
+
import { ctx__new } from '../ctx/index.js'
|
|
5
|
+
import { be } from './index.js'
|
|
6
|
+
test('be|s|BeMap', ()=>{
|
|
7
|
+
const ctx = ctx__new()
|
|
8
|
+
let incrementer_num = 0
|
|
9
|
+
const incrementer = ()=>++incrementer_num
|
|
10
|
+
const root_ = be_(()=>
|
|
11
|
+
incrementer(),
|
|
12
|
+
{ id: 'root_' })
|
|
13
|
+
const child = be(ctx, ctx=>
|
|
14
|
+
root_(ctx) + incrementer(),
|
|
15
|
+
{ id: 'child_' })
|
|
16
|
+
equal(root_(ctx), 1)
|
|
17
|
+
equal(ctx.s[''].get('root_')![0], 1)
|
|
18
|
+
equal(child, 3)
|
|
19
|
+
equal(ctx.s[''].get('child_')![0], 3)
|
|
20
|
+
})
|
|
21
|
+
test.run()
|
package/all/be_/index.js
CHANGED
|
@@ -132,6 +132,12 @@ export function be_map__find(be_or_id, ctx, ns = be_or_id.ns ?? '') {
|
|
|
132
132
|
export function be__val_(be_or_id, ctx, ns) {
|
|
133
133
|
return be_map__find(be_or_id, ctx, ns)?.get?.(be_or_id.id ?? be_or_id)?.[0]
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* @param {be__val__new_T}val__new
|
|
137
|
+
* @param {be_config_T}config
|
|
138
|
+
* @returns {Be}
|
|
139
|
+
* @private
|
|
140
|
+
*/
|
|
135
141
|
export function ondelete_be_(val__new, config) {
|
|
136
142
|
let be = be_(val__new, config)
|
|
137
143
|
let ondelete_cb_a = []
|
|
@@ -140,6 +146,7 @@ export function ondelete_be_(val__new, config) {
|
|
|
140
146
|
for (let ondelete_cb of ondelete_cb_a) {
|
|
141
147
|
ondelete_cb(...state)
|
|
142
148
|
}
|
|
149
|
+
ondelete_cb_a = []
|
|
143
150
|
}
|
|
144
151
|
return be
|
|
145
152
|
}
|
package/all/be_/index.test.ts
CHANGED
|
@@ -22,9 +22,9 @@ import {
|
|
|
22
22
|
globalThis__be_,
|
|
23
23
|
ondelete_be_
|
|
24
24
|
} from '../be_/index.js'
|
|
25
|
-
import {
|
|
25
|
+
import { ctx__new, ns_ctx__new } from '../ctx/index.js'
|
|
26
26
|
import { tempfile_path_ } from '../tempfile_path/index.js'
|
|
27
|
-
import { Equal, Expect } from '../test/index.js'
|
|
27
|
+
import type { Equal, Expect } from '../test/index.js'
|
|
28
28
|
test.after(()=>{
|
|
29
29
|
delete (globalThis as { root_be?:Be<unknown> }).root_be
|
|
30
30
|
})
|
|
@@ -165,7 +165,7 @@ test('be_|Ctx generic type', ()=>{
|
|
|
165
165
|
{ id: 'val_', ns: 'test_ns' })
|
|
166
166
|
val_(valid_ctx)
|
|
167
167
|
// @ts-expect-error TS2322
|
|
168
|
-
throws(()=>val_(
|
|
168
|
+
throws(()=>val_(ctx__new()))
|
|
169
169
|
})
|
|
170
170
|
test('be_|Ctx|ns', ()=>{
|
|
171
171
|
const ctx0 = ctx__new()
|
|
@@ -425,6 +425,12 @@ test('ondelete_be_', ()=>{
|
|
|
425
425
|
ctx__delete(ctx, be)
|
|
426
426
|
equal(ondelete0_arg_aa, [[1, ctx, be]])
|
|
427
427
|
equal(ondelete1_arg_aa, [[1, ctx, be]])
|
|
428
|
+
equal(be(ctx), 1)
|
|
429
|
+
equal(ondelete0_arg_aa, [[1, ctx, be]])
|
|
430
|
+
equal(ondelete1_arg_aa, [[1, ctx, be]])
|
|
431
|
+
ctx__delete(ctx, be)
|
|
432
|
+
equal(ondelete0_arg_aa, [[1, ctx, be], [1, ctx, be]])
|
|
433
|
+
equal(ondelete1_arg_aa, [[1, ctx, be], [1, ctx, be]])
|
|
428
434
|
})
|
|
429
435
|
test('ctx__clear', ()=>{
|
|
430
436
|
const ondelete0_arg_aa:[val:number, ctx:Ctx, be:Be<number, ''|'test_ns'>][] = []
|
package/all/rmemo/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export type memo_T<val_T> = (()=>val_T)&{
|
|
|
25
25
|
readonly val:val_T
|
|
26
26
|
r?:WeakRef<()=>val_T>
|
|
27
27
|
memor:WeakRef<()=>val_T>[]
|
|
28
|
+
b?:[unknown, memo_T<unknown>][]
|
|
28
29
|
}
|
|
29
30
|
export interface circular_memo_T extends memo_T<circular_memo_T> {}
|
|
30
31
|
export type sig_T<val_T> = (()=>val_T)&{
|
|
@@ -32,6 +33,7 @@ export type sig_T<val_T> = (()=>val_T)&{
|
|
|
32
33
|
readonly val:val_T
|
|
33
34
|
r?:WeakRef<()=>val_T>
|
|
34
35
|
memor:WeakRef<()=>val_T>[]
|
|
36
|
+
b?:[unknown, memo_T<unknown>][]
|
|
35
37
|
}
|
|
36
38
|
export interface circular_sig_T extends sig_T<circular_sig_T> {}
|
|
37
39
|
export type lock_memosig_T<val_T> = sig_T<val_T>&{
|
package/all/rmemo/index.js
CHANGED
|
@@ -40,12 +40,8 @@ export function memo_(memo_def, ...subscriber_a) {
|
|
|
40
40
|
}
|
|
41
41
|
memo.val = val
|
|
42
42
|
if (!memo.b) {
|
|
43
|
-
|
|
44
|
-
memo.b =
|
|
45
|
-
memo_(()=>subscriber(memo)))
|
|
46
|
-
for (let s of memo.b) {
|
|
47
|
-
s()
|
|
48
|
-
}
|
|
43
|
+
memo.b = subscriber_a.map(subscriber=>memo_(()=>subscriber(memo)))
|
|
44
|
+
memo.b = memo.b.map(subscriber_memo=>[subscriber_memo(), subscriber_memo])
|
|
49
45
|
}
|
|
50
46
|
if (run_queue) {
|
|
51
47
|
cur_refresh_loop:for (let cur_refresh of queue) {
|
package/all/rmemo/index.test.ts
CHANGED
|
@@ -171,6 +171,14 @@ test('sig_|undefined', ()=>{
|
|
|
171
171
|
equal(sig(), undefined)
|
|
172
172
|
equal(memo(), undefined)
|
|
173
173
|
})
|
|
174
|
+
test('rmemo|subscriber|has strong refernce to the return value', ()=>{
|
|
175
|
+
const num$ = sig_<number|undefined>(
|
|
176
|
+
undefined,
|
|
177
|
+
()=>99)
|
|
178
|
+
equal(num$.b, undefined)
|
|
179
|
+
equal(num$(), undefined)
|
|
180
|
+
equal(num$.b![0][0], 99)
|
|
181
|
+
})
|
|
174
182
|
test('sig_|subscriber|notified if sig is set before read', ()=>{
|
|
175
183
|
let count = 0
|
|
176
184
|
let subscriber__num:number|undefined = undefined
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.15.0",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -145,9 +145,9 @@
|
|
|
145
145
|
"@arethetypeswrong/cli": "^0.13.5",
|
|
146
146
|
"@ctx-core/preprocess": "^0.1.0",
|
|
147
147
|
"@size-limit/preset-small-lib": "^11.0.1",
|
|
148
|
-
"@types/node": "^20.10.
|
|
148
|
+
"@types/node": "^20.10.7",
|
|
149
149
|
"@types/sinon": "^17.0.2",
|
|
150
|
-
"c8": "^
|
|
150
|
+
"c8": "^9.0.0",
|
|
151
151
|
"check-dts": "^0.7.2",
|
|
152
152
|
"esbuild": "^0.19.11",
|
|
153
153
|
"esmock": "^2.6.0",
|
|
@@ -210,28 +210,28 @@
|
|
|
210
210
|
"import": {
|
|
211
211
|
"./rmemo": "{ memo_ }"
|
|
212
212
|
},
|
|
213
|
-
"limit": "
|
|
213
|
+
"limit": "335 B"
|
|
214
214
|
},
|
|
215
215
|
{
|
|
216
216
|
"name": "memo_ sig_",
|
|
217
217
|
"import": {
|
|
218
218
|
"./rmemo": "{ sig_, memo_ }"
|
|
219
219
|
},
|
|
220
|
-
"limit": "
|
|
220
|
+
"limit": "353 B"
|
|
221
221
|
},
|
|
222
222
|
{
|
|
223
223
|
"name": "memo_ sig_ be_ ctx_",
|
|
224
224
|
"import": {
|
|
225
225
|
"./rmemo": "{ sig_, memo_, be_, ctx_ }"
|
|
226
226
|
},
|
|
227
|
-
"limit": "
|
|
227
|
+
"limit": "460 B"
|
|
228
228
|
},
|
|
229
229
|
{
|
|
230
230
|
"name": "memo_ sig_ be_ ctx_ be_memo_pair_ be_sig_triple_",
|
|
231
231
|
"import": {
|
|
232
232
|
"./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
|
|
233
233
|
},
|
|
234
|
-
"limit": "
|
|
234
|
+
"limit": "553 B"
|
|
235
235
|
},
|
|
236
236
|
{
|
|
237
237
|
"name": "uuid",
|