ctx-core 5.13.0 → 5.14.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/package.json +4 -4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.14.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",
|
|
@@ -248,4 +248,4 @@
|
|
|
248
248
|
"limit": "116 B"
|
|
249
249
|
}
|
|
250
250
|
]
|
|
251
|
-
}
|
|
251
|
+
}
|