ctx-core 3.3.3 → 4.0.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/README.md +3 -0
- package/all/all_union_a/index.js +1 -1
- package/all/andand_or/index.js +1 -1
- package/all/andandfn/index.js +2 -2
- package/all/arg_i0_a/index.js +1 -1
- package/all/bad_credentials/index.js +1 -1
- package/all/be/index.d.ts +2 -2
- package/all/be/index.js +3 -4
- package/all/be_/index.d.ts +35 -53
- package/all/be_/index.js +22 -54
- package/all/be_/index.test.ts +19 -20
- package/all/be_rmemo_pair/index.d.ts +21 -0
- package/all/be_rmemo_pair/index.js +25 -0
- package/all/be_rmemo_pair/index.test.ts +66 -0
- package/all/be_rsig_triple/index.d.ts +22 -0
- package/all/be_rsig_triple/index.js +28 -0
- package/all/be_rsig_triple/index.test.ts +52 -0
- package/all/call_assign/index.js +1 -1
- package/all/compose/index.js +1 -1
- package/all/each/index.js +1 -1
- package/all/eql_fn_a/index.js +1 -1
- package/all/fetch__template_pair/index.js +1 -1
- package/all/filter/index.js +1 -1
- package/all/http_error/index.js +1 -1
- package/all/idx_filter/index.js +2 -2
- package/all/idx_key_r/index.js +4 -4
- package/all/index.d.ts +3 -3
- package/all/index.js +3 -3
- package/all/invalid_argument/index.js +1 -1
- package/all/invalid_state/index.js +1 -1
- package/all/map/index.js +1 -1
- package/all/missing_argument/index.js +1 -1
- package/all/o_a_present/index.js +1 -1
- package/all/or/index.js +2 -2
- package/all/rc_be/index.d.ts +2 -5
- package/all/rc_be/index.js +5 -7
- package/all/rc_be_/index.d.ts +5 -8
- package/all/rc_be_/index.js +6 -15
- package/all/reduce/index.js +1 -1
- package/all/reject/index.js +1 -1
- package/all/response_o/index.js +1 -1
- package/all/rmemo/index.d.ts +8 -2
- package/all/rmemo/index.js +24 -24
- package/all/sort/index.js +1 -1
- package/all/sort_idx_a/index.js +1 -1
- package/all/sort_val_a/index.js +1 -1
- package/all/sort_val_a__transition_idx_a/index.js +3 -3
- package/all/union_by/index.js +1 -1
- package/all/weak_r/index.js +1 -1
- package/all/zip_with/index.js +1 -1
- package/be/index.d.ts +0 -2
- package/be/index.js +0 -2
- package/object/index.d.ts +0 -2
- package/object/index.js +0 -2
- package/package.json +6 -6
- package/rmemo/index.d.ts +2 -0
- package/rmemo/index.js +2 -0
- package/all/be_arg_triple/index.d.ts +0 -21
- package/all/be_arg_triple/index.js +0 -41
- package/all/be_prop_pair/index.d.ts +0 -36
- package/all/be_prop_pair/index.js +0 -54
- package/all/be_prop_pair/index.test.ts +0 -137
- package/be/index.test.ts +0 -251
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -107,14 +107,14 @@
|
|
|
107
107
|
"devDependencies": {
|
|
108
108
|
"@arethetypeswrong/cli": "^0.13.1",
|
|
109
109
|
"@size-limit/preset-small-lib": "^11.0.0",
|
|
110
|
-
"@types/node": "^20.9.
|
|
110
|
+
"@types/node": "^20.9.2",
|
|
111
111
|
"@types/sinon": "^17.0.1",
|
|
112
112
|
"c8": "^8.0.1",
|
|
113
113
|
"check-dts": "^0.7.2",
|
|
114
114
|
"sinon": "^17.0.1",
|
|
115
115
|
"size-limit": "^11.0.0",
|
|
116
116
|
"ts-node": "^10.9.1",
|
|
117
|
-
"tsx": "^4.1.
|
|
117
|
+
"tsx": "^4.1.4",
|
|
118
118
|
"typescript": "next",
|
|
119
119
|
"uvu": "^0.5.6"
|
|
120
120
|
},
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"import": {
|
|
130
130
|
"./be": "{ be_ }"
|
|
131
131
|
},
|
|
132
|
-
"limit": "
|
|
132
|
+
"limit": "367 B"
|
|
133
133
|
},
|
|
134
134
|
{
|
|
135
135
|
"name": "rmemo_",
|
|
@@ -143,14 +143,14 @@
|
|
|
143
143
|
"import": {
|
|
144
144
|
"./rmemo": "{ rsig_, rmemo_ }"
|
|
145
145
|
},
|
|
146
|
-
"limit": "
|
|
146
|
+
"limit": "381 B"
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
149
|
"name": "rmemo_ signal_ be_ ctx_",
|
|
150
150
|
"import": {
|
|
151
151
|
"./rmemo": "{ rsig_, rmemo_, be_, ctx_ }"
|
|
152
152
|
},
|
|
153
|
-
"limit": "
|
|
153
|
+
"limit": "731 B"
|
|
154
154
|
}
|
|
155
155
|
],
|
|
156
156
|
"scripts": {
|
package/rmemo/index.d.ts
CHANGED
package/rmemo/index.js
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { be__params_T, Ctx } from '../be_/index.js'
|
|
2
|
-
export declare function be_arg_triple__new<
|
|
3
|
-
val_T,
|
|
4
|
-
ctx_T extends Ctx = Ctx,
|
|
5
|
-
>(...arg_a:be_arg_triple__new__arg_a_T<val_T, ctx_T>):be_arg_triple_T<val_T, ctx_T>
|
|
6
|
-
export type be_arg_triple_T<
|
|
7
|
-
val_T,
|
|
8
|
-
ctx_T extends Ctx = Ctx
|
|
9
|
-
> = [
|
|
10
|
-
id:string|null,
|
|
11
|
-
val__new:(ctx:ctx_T)=>val_T,
|
|
12
|
-
be__params:be__params_T
|
|
13
|
-
]
|
|
14
|
-
export type be_arg_triple__new__arg_a_T<
|
|
15
|
-
val_T,
|
|
16
|
-
ctx_T extends Ctx = Ctx,
|
|
17
|
-
> =
|
|
18
|
-
|[be__params?:be__params_T]
|
|
19
|
-
|[id:string|null|undefined, be__params?:be__params_T]
|
|
20
|
-
|[val__new:(ctx:ctx_T)=>val_T, be__params?:be__params_T]
|
|
21
|
-
|[id?:string|null|undefined, val__new?:((ctx:ctx_T)=>val_T), be__params?:be__params_T]
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/** @typedef {import('../be_/index.d.ts').Ctx}Ctx */
|
|
2
|
-
/** @typedef {import('../be_/index.d.ts').be__params_T}be__params_T */
|
|
3
|
-
/** @typedef {import('../be_arg_triple/index.d.ts').be_arg_triple_T}be_arg_triple_T */
|
|
4
|
-
/** @typedef {import('../be_arg_triple/index.d.ts').be_arg_triple__new__arg_a_T}be_arg_triple__new__arg_a_T */
|
|
5
|
-
/**
|
|
6
|
-
* @param {be_arg_triple__new__arg_a_T}arg_a
|
|
7
|
-
* @returns {be_arg_triple_T}
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
export function be_arg_triple__new(...arg_a) {
|
|
11
|
-
/** @type {string|null|undefined} */
|
|
12
|
-
let id
|
|
13
|
-
/** @type {((ctx:Ctx)=>V)|undefined} */
|
|
14
|
-
let val__new
|
|
15
|
-
/** @type {be__params_T|undefined} */
|
|
16
|
-
let be__params
|
|
17
|
-
if (arg_a.length === 3) {
|
|
18
|
-
[id, val__new, be__params] = arg_a
|
|
19
|
-
} else if (arg_a.length === 2) {
|
|
20
|
-
if (typeof arg_a[0] === 'function') {
|
|
21
|
-
val__new = arg_a[0]
|
|
22
|
-
be__params = arg_a[1]
|
|
23
|
-
} else {
|
|
24
|
-
id = arg_a[0]
|
|
25
|
-
if (typeof arg_a[1] === 'function') {
|
|
26
|
-
val__new = arg_a[1]
|
|
27
|
-
} else {
|
|
28
|
-
be__params = arg_a[1]
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
} else if (arg_a.length === 1) {
|
|
32
|
-
if (typeof arg_a[0] === 'function') {
|
|
33
|
-
val__new = arg_a[0]
|
|
34
|
-
} else if (typeof arg_a[0] === 'object') {
|
|
35
|
-
be__params = arg_a[0]
|
|
36
|
-
} else {
|
|
37
|
-
id = arg_a[0]
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return [id, val__new, be__params]
|
|
41
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { be__params_T, Ctx } from '../be_/index.js'
|
|
2
|
-
export declare function be_prop_pair_<
|
|
3
|
-
Val extends NonNullable<unknown>,
|
|
4
|
-
ctx_T extends Ctx = Ctx
|
|
5
|
-
>(
|
|
6
|
-
be__params?:be__params_T
|
|
7
|
-
):be_prop_pair_T<Val, ctx_T>
|
|
8
|
-
export declare function be_prop_pair_<
|
|
9
|
-
Val extends NonNullable<unknown>,
|
|
10
|
-
ctx_T extends Ctx = Ctx
|
|
11
|
-
>(
|
|
12
|
-
id:string|null|undefined,
|
|
13
|
-
be__params?:be__params_T
|
|
14
|
-
):be_prop_pair_T<Val, ctx_T>
|
|
15
|
-
export declare function be_prop_pair_<
|
|
16
|
-
Val extends NonNullable<unknown>,
|
|
17
|
-
ctx_T extends Ctx = Ctx
|
|
18
|
-
>(
|
|
19
|
-
val__new:(ctx:ctx_T)=>Val,
|
|
20
|
-
be__params?:be__params_T
|
|
21
|
-
):be_prop_pair_T<Val, ctx_T>
|
|
22
|
-
export declare function be_prop_pair_<
|
|
23
|
-
Val extends NonNullable<unknown>,
|
|
24
|
-
ctx_T extends Ctx = Ctx
|
|
25
|
-
>(
|
|
26
|
-
id?:string|null|undefined,
|
|
27
|
-
val__new?:((ctx:ctx_T)=>Val),
|
|
28
|
-
be__params?:be__params_T
|
|
29
|
-
):be_prop_pair_T<Val, ctx_T>
|
|
30
|
-
export type be_prop_pair_T<
|
|
31
|
-
Val extends NonNullable<unknown>,
|
|
32
|
-
ctx_T extends Ctx = Ctx
|
|
33
|
-
> = [
|
|
34
|
-
(ctx:ctx_T)=>Val,
|
|
35
|
-
(ctx:ctx_T, val:Val)=>void
|
|
36
|
-
]
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { be_, ctx__set } from '../be_/index.js'
|
|
2
|
-
/** @typedef {import('../be_/index.d.ts').be__params_T}be__params_T */
|
|
3
|
-
/** @typedef {import('../be_/index.d.ts').Ctx}Ctx */
|
|
4
|
-
/** @typedef {import('../be_prop_pair/index.d.ts').be_prop_pair_T}be_prop_pair_T */
|
|
5
|
-
/**
|
|
6
|
-
* @param {string|null|undefined|((ctx:Ctx)=>unknown)|be__params_T}[id_OR_val__new_OR_be__params]
|
|
7
|
-
* @param {((ctx:Ctx)=>unknown)|be__params_T}val__new_OR_be__params
|
|
8
|
-
* @param {be__params_T}[be__params]
|
|
9
|
-
* @returns {be_prop_pair_T}
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
export function be_prop_pair_(
|
|
13
|
-
id_OR_val__new_OR_be__params,
|
|
14
|
-
val__new_OR_be__params,
|
|
15
|
-
be__params
|
|
16
|
-
) {
|
|
17
|
-
/** @type {string} */
|
|
18
|
-
let id
|
|
19
|
-
/** @type {(ctx:Ctx)=>unknown} */
|
|
20
|
-
let val__new
|
|
21
|
-
if (typeof id_OR_val__new_OR_be__params === 'function') {
|
|
22
|
-
val__new_OR_be__params = id_OR_val__new_OR_be__params
|
|
23
|
-
} else if (typeof id_OR_val__new_OR_be__params === 'object') {
|
|
24
|
-
be__params = id_OR_val__new_OR_be__params
|
|
25
|
-
} else {
|
|
26
|
-
id = id_OR_val__new_OR_be__params
|
|
27
|
-
}
|
|
28
|
-
if (typeof val__new_OR_be__params === 'function') {
|
|
29
|
-
val__new = val__new_OR_be__params
|
|
30
|
-
} else if (!be__params) {
|
|
31
|
-
be__params = val__new_OR_be__params
|
|
32
|
-
}
|
|
33
|
-
if (!val__new) {
|
|
34
|
-
val__new = ()=>null
|
|
35
|
-
}
|
|
36
|
-
const _be_ =
|
|
37
|
-
(be__params && be__params.be_)
|
|
38
|
-
?? be_
|
|
39
|
-
const val_ =
|
|
40
|
-
id
|
|
41
|
-
? _be_(id, val__new, be__params)
|
|
42
|
-
: _be_(val__new, be__params)
|
|
43
|
-
function val__set(ctx, val) {
|
|
44
|
-
ctx__set(
|
|
45
|
-
ctx,
|
|
46
|
-
val_,
|
|
47
|
-
val,
|
|
48
|
-
be__params && be__params.is_source_)
|
|
49
|
-
}
|
|
50
|
-
return [
|
|
51
|
-
val_,
|
|
52
|
-
val__set
|
|
53
|
-
]
|
|
54
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { test } from 'uvu'
|
|
2
|
-
import { equal } from 'uvu/assert'
|
|
3
|
-
import { be_, type MapCtx } from '../be_/index.js'
|
|
4
|
-
import { be_prop_pair_ } from '../be_prop_pair/index.js'
|
|
5
|
-
import { ctx__new } from '../ctx/index.js'
|
|
6
|
-
test('be_prop_pair_|+base_name|+atom__new|+be__params', ()=>{
|
|
7
|
-
const ctx = ctx__new()
|
|
8
|
-
const is_source_ = (map_ctx:MapCtx)=>map_ctx === ctx
|
|
9
|
-
let custom__be__called = false
|
|
10
|
-
const custom__be_ = ((...argv:Parameters<typeof be_>)=>{
|
|
11
|
-
custom__be__called = true
|
|
12
|
-
return be_(...argv)
|
|
13
|
-
}) as typeof be_
|
|
14
|
-
const [
|
|
15
|
-
foobar_,
|
|
16
|
-
foobar__set,
|
|
17
|
-
] = be_prop_pair_(
|
|
18
|
-
'foobar',
|
|
19
|
-
()=>1,
|
|
20
|
-
{
|
|
21
|
-
is_source_,
|
|
22
|
-
be_: custom__be_,
|
|
23
|
-
}
|
|
24
|
-
)
|
|
25
|
-
equal(custom__be__called, true)
|
|
26
|
-
equal(foobar_([ctx__new(), ctx]), 1)
|
|
27
|
-
foobar__set([ctx__new(), ctx], 2)
|
|
28
|
-
equal(foobar_([ctx__new(), ctx]), 2)
|
|
29
|
-
})
|
|
30
|
-
test('be_prop_pair_|+base_name|+atom__new|-be__params', ()=>{
|
|
31
|
-
const ctx = ctx__new()
|
|
32
|
-
const [
|
|
33
|
-
foobar_,
|
|
34
|
-
foobar__set,
|
|
35
|
-
] = be_prop_pair_(
|
|
36
|
-
'foobar',
|
|
37
|
-
()=>1,
|
|
38
|
-
)
|
|
39
|
-
equal(foobar_(ctx), 1)
|
|
40
|
-
foobar__set(ctx, 2)
|
|
41
|
-
equal(foobar_(ctx), 2)
|
|
42
|
-
})
|
|
43
|
-
test('be_prop_pair_|+base_name|-atom__new|+be__params', ()=>{
|
|
44
|
-
const ctx = ctx__new()
|
|
45
|
-
const is_source_ = (map_ctx:MapCtx)=>map_ctx === ctx
|
|
46
|
-
let custom__be__called = false
|
|
47
|
-
const custom__be_ = ((...argv:Parameters<typeof be_>)=>{
|
|
48
|
-
custom__be__called = true
|
|
49
|
-
return be_(...argv)
|
|
50
|
-
}) as typeof be_
|
|
51
|
-
const [
|
|
52
|
-
foobar_,
|
|
53
|
-
foobar__set,
|
|
54
|
-
] = be_prop_pair_('foobar', {
|
|
55
|
-
is_source_,
|
|
56
|
-
be_: custom__be_,
|
|
57
|
-
})
|
|
58
|
-
equal(custom__be__called, true)
|
|
59
|
-
equal(foobar_([ctx__new(), ctx]), null)
|
|
60
|
-
foobar__set([ctx__new(), ctx], 2)
|
|
61
|
-
equal(foobar_([ctx__new(), ctx]), 2)
|
|
62
|
-
})
|
|
63
|
-
test('be_prop_pair_|+base_name|-atom__new|-be__params', ()=>{
|
|
64
|
-
const [
|
|
65
|
-
foobar_,
|
|
66
|
-
foobar__set,
|
|
67
|
-
] = be_prop_pair_('foobar')
|
|
68
|
-
const ctx = ctx__new()
|
|
69
|
-
equal(foobar_(ctx), null)
|
|
70
|
-
foobar__set(ctx, 2)
|
|
71
|
-
equal(foobar_(ctx), 2)
|
|
72
|
-
})
|
|
73
|
-
test('be_prop_pair_|-base_name|+atom__new|+be__params', ()=>{
|
|
74
|
-
const ctx = ctx__new()
|
|
75
|
-
const is_source_ = (map_ctx:MapCtx)=>map_ctx === ctx
|
|
76
|
-
let custom__be__called = false
|
|
77
|
-
const custom__be_ = ((...argv:Parameters<typeof be_>)=>{
|
|
78
|
-
custom__be__called = true
|
|
79
|
-
return be_(...argv)
|
|
80
|
-
}) as typeof be_
|
|
81
|
-
const [
|
|
82
|
-
foobar_,
|
|
83
|
-
foobar__set,
|
|
84
|
-
] = be_prop_pair_(
|
|
85
|
-
undefined,
|
|
86
|
-
()=>1,
|
|
87
|
-
{
|
|
88
|
-
is_source_,
|
|
89
|
-
be_: custom__be_,
|
|
90
|
-
})
|
|
91
|
-
equal(custom__be__called, true)
|
|
92
|
-
equal(foobar_([ctx__new(), ctx]), 1)
|
|
93
|
-
foobar__set([ctx__new(), ctx], 2)
|
|
94
|
-
equal(foobar_([ctx__new(), ctx]), 2)
|
|
95
|
-
})
|
|
96
|
-
test('be_prop_pair_|-base_name|+atom__new|-be__params', ()=>{
|
|
97
|
-
const [
|
|
98
|
-
foobar_,
|
|
99
|
-
foobar__set,
|
|
100
|
-
] = be_prop_pair_(undefined, ()=>
|
|
101
|
-
1)
|
|
102
|
-
const ctx = ctx__new()
|
|
103
|
-
equal(foobar_(ctx), 1)
|
|
104
|
-
foobar__set(ctx, 2)
|
|
105
|
-
equal(foobar_(ctx), 2)
|
|
106
|
-
})
|
|
107
|
-
test('be_prop_pair_|-base_name|-atom__new|+be__params', ()=>{
|
|
108
|
-
const ctx = ctx__new()
|
|
109
|
-
const is_source_ = (map_ctx:MapCtx)=>map_ctx === ctx
|
|
110
|
-
let custom__be__called = false
|
|
111
|
-
const custom__be_ = ((...argv:Parameters<typeof be_>)=>{
|
|
112
|
-
custom__be__called = true
|
|
113
|
-
return be_(...argv)
|
|
114
|
-
}) as typeof be_
|
|
115
|
-
const [
|
|
116
|
-
foobar_,
|
|
117
|
-
foobar__set,
|
|
118
|
-
] = be_prop_pair_({
|
|
119
|
-
is_source_,
|
|
120
|
-
be_: custom__be_,
|
|
121
|
-
})
|
|
122
|
-
equal(custom__be__called, true)
|
|
123
|
-
equal(foobar_([ctx__new(), ctx]), null)
|
|
124
|
-
foobar__set([ctx__new(), ctx], 2)
|
|
125
|
-
equal(foobar_([ctx__new(), ctx]), 2)
|
|
126
|
-
})
|
|
127
|
-
test('be_prop_pair_|-base_name|-atom__new|-be__params', ()=>{
|
|
128
|
-
const [
|
|
129
|
-
foobar_,
|
|
130
|
-
foobar__set,
|
|
131
|
-
] = be_prop_pair_()
|
|
132
|
-
const ctx = ctx__new()
|
|
133
|
-
equal(foobar_(ctx), null)
|
|
134
|
-
foobar__set(ctx, 2)
|
|
135
|
-
equal(foobar_(ctx), 2)
|
|
136
|
-
})
|
|
137
|
-
test.run()
|
package/be/index.test.ts
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import { test } from 'uvu'
|
|
2
|
-
import { equal } from 'uvu/assert'
|
|
3
|
-
import {
|
|
4
|
-
be_,
|
|
5
|
-
be__delete,
|
|
6
|
-
be__has_,
|
|
7
|
-
be__has__ctx_,
|
|
8
|
-
be__set,
|
|
9
|
-
be__val_,
|
|
10
|
-
type Ctx,
|
|
11
|
-
ctx__delete,
|
|
12
|
-
ctx__new,
|
|
13
|
-
ctx__set,
|
|
14
|
-
type MapCtx
|
|
15
|
-
} from '../be/index.js'
|
|
16
|
-
test('be_|Map', ()=>{
|
|
17
|
-
const ctx = ctx__new()
|
|
18
|
-
let incrementer_num = 0
|
|
19
|
-
const incrementer = ()=>++incrementer_num
|
|
20
|
-
const root_ = be_('root_', ()=>incrementer())
|
|
21
|
-
const child_ = be_('child_', ctx=>root_(ctx) + incrementer())
|
|
22
|
-
const child1_ = be_('child1_', ctx=>root_(ctx) + child_(ctx))
|
|
23
|
-
equal(root_(ctx), 1)
|
|
24
|
-
equal(ctx.get('root_'), 1)
|
|
25
|
-
equal(child_(ctx), 3)
|
|
26
|
-
equal(ctx.get('child_'), 3)
|
|
27
|
-
equal(child1_(ctx), 4)
|
|
28
|
-
equal(ctx.get('child1_'), 4)
|
|
29
|
-
})
|
|
30
|
-
test('be_|simple array', ()=>{
|
|
31
|
-
const ctx0 = ctx__new()
|
|
32
|
-
const ctx1 = ctx__new()
|
|
33
|
-
const ctx = [ctx0, ctx1]
|
|
34
|
-
const root_ = be_('root_', ()=>1)
|
|
35
|
-
equal(root_(ctx1), 1)
|
|
36
|
-
equal(root_(ctx), 1)
|
|
37
|
-
equal(ctx0.has(root_), false)
|
|
38
|
-
equal(ctx1.has(root_), true)
|
|
39
|
-
const child_ = be_('child_', ctx=>root_(ctx) + 1)
|
|
40
|
-
equal(child_(ctx), 2)
|
|
41
|
-
equal(ctx0.has(child_), true)
|
|
42
|
-
equal(ctx1.has(child_), false)
|
|
43
|
-
})
|
|
44
|
-
test('be_|nested array', ()=>{
|
|
45
|
-
const ctx0 = ctx__new()
|
|
46
|
-
const ctx1 = ctx__new()
|
|
47
|
-
const ctx2 = ctx__new()
|
|
48
|
-
const ctx3 = ctx__new()
|
|
49
|
-
const ctx = [[[ctx0], ctx1], [ctx2, ctx3]]
|
|
50
|
-
const root_ = be_('root_', ()=>1)
|
|
51
|
-
equal(root_(ctx3), 1)
|
|
52
|
-
equal(root_(ctx), 1)
|
|
53
|
-
equal(ctx0.has(root_), false)
|
|
54
|
-
equal(ctx1.has(root_), false)
|
|
55
|
-
equal(ctx2.has(root_), false)
|
|
56
|
-
equal(ctx3.has(root_), true)
|
|
57
|
-
const child_ = be_('child_', ctx=>root_(ctx) + 1)
|
|
58
|
-
equal(child_(ctx), 2)
|
|
59
|
-
equal(ctx0.has(child_), true)
|
|
60
|
-
equal(ctx1.has(child_), false)
|
|
61
|
-
equal(ctx2.has(child_), false)
|
|
62
|
-
equal(ctx3.has(child_), false)
|
|
63
|
-
})
|
|
64
|
-
test('be_|is_source_', ()=>{
|
|
65
|
-
const ctx0 = ctx__new()
|
|
66
|
-
const ctx1 = ctx__new()
|
|
67
|
-
ctx1.set('matching', true)
|
|
68
|
-
const ctx = [ctx0, ctx1]
|
|
69
|
-
const be__ctx_a:Ctx[] = []
|
|
70
|
-
const root_ = be_('root_', ctx=>{
|
|
71
|
-
be__ctx_a.push(ctx)
|
|
72
|
-
return 1
|
|
73
|
-
}, {
|
|
74
|
-
is_source_(map_ctx) {
|
|
75
|
-
return !!map_ctx.get('matching')
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
equal(root_(ctx), 1)
|
|
79
|
-
equal(be__ctx_a, [[ctx0, ctx1]])
|
|
80
|
-
equal(ctx0.has(root_), false)
|
|
81
|
-
equal(ctx1.has(root_), true)
|
|
82
|
-
})
|
|
83
|
-
test('be_|Ctx generic type', ()=>{
|
|
84
|
-
const valid_ctx = ctx__new() as test_ctx_T
|
|
85
|
-
const val_ = be_<boolean, test_ctx_T>('val_', ()=>true)
|
|
86
|
-
val_(valid_ctx)
|
|
87
|
-
// val_(ctx_()) // type error
|
|
88
|
-
})
|
|
89
|
-
test('be_|Ctx|NestedMapCtx', ()=>{
|
|
90
|
-
const ctx0 = ctx__new()
|
|
91
|
-
const ctx1 = ctx__new()
|
|
92
|
-
ctx1.set('matching', true)
|
|
93
|
-
const ctx = [ctx0, ctx1]
|
|
94
|
-
const nested__ctx_ = be_<Ctx>('nested__ctx_', ctx=>[ctx])
|
|
95
|
-
equal(nested__ctx_(ctx), [[ctx0, ctx1]])
|
|
96
|
-
})
|
|
97
|
-
test('be__set', ()=>{
|
|
98
|
-
const ctx0 = ctx__new()
|
|
99
|
-
const val_ = be_<number|undefined>('val_', ()=>undefined, {
|
|
100
|
-
is_source_: map_ctx=>map_ctx === ctx0
|
|
101
|
-
})
|
|
102
|
-
be__set(val_, ctx0, 1)
|
|
103
|
-
equal(val_(ctx0), 1)
|
|
104
|
-
const ctx1 = ctx__new()
|
|
105
|
-
const ctx_a = [ctx1, ctx0]
|
|
106
|
-
be__set(val_, ctx_a, 2)
|
|
107
|
-
equal(val_(ctx0), 2)
|
|
108
|
-
equal(val_(ctx_a), 2)
|
|
109
|
-
equal(ctx1.has(val_), false)
|
|
110
|
-
})
|
|
111
|
-
test('ctx__set', ()=>{
|
|
112
|
-
const ctx0 = ctx__new()
|
|
113
|
-
ctx__set(ctx0, 'key', 1)
|
|
114
|
-
equal(ctx0.get('key'), 1)
|
|
115
|
-
const ctx1 = ctx__new()
|
|
116
|
-
const ctx_a = [ctx1, ctx0]
|
|
117
|
-
ctx__set(ctx_a, 'key', 2,
|
|
118
|
-
(map_ctx:MapCtx)=>map_ctx.get('key') != null)
|
|
119
|
-
equal(ctx0.get('key'), 2)
|
|
120
|
-
equal(ctx1.has('key'), false)
|
|
121
|
-
})
|
|
122
|
-
test('be__delete', ()=>{
|
|
123
|
-
const ctx0 = ctx__new()
|
|
124
|
-
const val_ = be_<boolean>('val_', ()=>true)
|
|
125
|
-
be__delete(val_, ctx0)
|
|
126
|
-
equal(ctx0.has(val_), false)
|
|
127
|
-
equal(ctx0.has('val_'), false)
|
|
128
|
-
equal(val_(ctx0), true)
|
|
129
|
-
equal(ctx0.get(val_), true)
|
|
130
|
-
equal(ctx0.get('val_'), true)
|
|
131
|
-
be__delete(val_, ctx0)
|
|
132
|
-
equal(ctx0.has(val_), false)
|
|
133
|
-
equal(ctx0.has('val_'), false)
|
|
134
|
-
const ctx1 = ctx__new()
|
|
135
|
-
const nested__ctx = [ctx0, ctx1]
|
|
136
|
-
equal(val_(ctx0), true)
|
|
137
|
-
equal(val_(ctx1), true)
|
|
138
|
-
equal(val_(nested__ctx), true)
|
|
139
|
-
equal(ctx0.get('val_'), true)
|
|
140
|
-
equal(ctx1.get('val_'), true)
|
|
141
|
-
be__delete(val_, nested__ctx)
|
|
142
|
-
equal(ctx0.has(val_), false)
|
|
143
|
-
equal(ctx0.has('val_'), false)
|
|
144
|
-
equal(ctx1.has(val_), false)
|
|
145
|
-
equal(ctx1.has('val_'), false)
|
|
146
|
-
})
|
|
147
|
-
test('ctx__delete|id', ()=>{
|
|
148
|
-
const ctx0 = ctx__new()
|
|
149
|
-
ctx__delete(ctx0, 'key')
|
|
150
|
-
equal(ctx0.has('key'), false)
|
|
151
|
-
ctx0.set('key', true)
|
|
152
|
-
equal(ctx0.get('key'), true)
|
|
153
|
-
ctx__delete(ctx0, 'key')
|
|
154
|
-
equal(ctx0.has('key'), false)
|
|
155
|
-
const ctx1 = ctx__new()
|
|
156
|
-
const nested__ctx = [ctx0, ctx1]
|
|
157
|
-
ctx0.set('key', true)
|
|
158
|
-
ctx1.set('key', true)
|
|
159
|
-
equal(ctx0.get('key'), true)
|
|
160
|
-
equal(ctx1.get('key'), true)
|
|
161
|
-
ctx__delete(nested__ctx, 'key')
|
|
162
|
-
equal(ctx0.has('key'), false)
|
|
163
|
-
equal(ctx1.has('key'), false)
|
|
164
|
-
})
|
|
165
|
-
test('ctx__delete|be', ()=>{
|
|
166
|
-
const ctx0 = ctx__new()
|
|
167
|
-
const num_ = be_(()=>1)
|
|
168
|
-
ctx__delete(ctx0, num_)
|
|
169
|
-
equal(ctx0.has(num_), false)
|
|
170
|
-
num_(ctx0)
|
|
171
|
-
equal(ctx0.has(num_), true)
|
|
172
|
-
ctx__delete(ctx0, num_)
|
|
173
|
-
equal(ctx0.has(num_), false)
|
|
174
|
-
num_(ctx0)
|
|
175
|
-
equal(ctx0.has(num_), true)
|
|
176
|
-
ctx__delete(ctx0, num_)
|
|
177
|
-
equal(ctx0.has(num_), false)
|
|
178
|
-
const ctx1 = ctx__new()
|
|
179
|
-
ctx1.set('ctx1', true)
|
|
180
|
-
const nested__ctx = [ctx0, ctx1]
|
|
181
|
-
num_(ctx0)
|
|
182
|
-
num_(ctx1)
|
|
183
|
-
equal(ctx0.has(num_), true)
|
|
184
|
-
equal(ctx1.has(num_), true)
|
|
185
|
-
ctx__delete(nested__ctx, num_)
|
|
186
|
-
equal(ctx0.has(num_), false)
|
|
187
|
-
equal(ctx1.has(num_), false)
|
|
188
|
-
num_(ctx0)
|
|
189
|
-
num_(ctx1)
|
|
190
|
-
equal(ctx0.has(num_), true)
|
|
191
|
-
equal(ctx1.has(num_), true)
|
|
192
|
-
ctx__delete(nested__ctx, num_)
|
|
193
|
-
equal(ctx0.has(num_), false)
|
|
194
|
-
equal(ctx1.has(num_), false)
|
|
195
|
-
const is_source__num_ =
|
|
196
|
-
be_(()=>1,
|
|
197
|
-
{ is_source_: ctx=>!!ctx.get('ctx1') })
|
|
198
|
-
is_source__num_(nested__ctx)
|
|
199
|
-
equal(ctx0.has(is_source__num_), false)
|
|
200
|
-
equal(ctx1.has(is_source__num_), true)
|
|
201
|
-
ctx__delete(nested__ctx, is_source__num_)
|
|
202
|
-
equal(ctx0.has(is_source__num_), false)
|
|
203
|
-
equal(ctx1.has(is_source__num_), false)
|
|
204
|
-
is_source__num_(nested__ctx)
|
|
205
|
-
equal(ctx0.has(is_source__num_), false)
|
|
206
|
-
equal(ctx1.has(is_source__num_), true)
|
|
207
|
-
ctx__delete(nested__ctx, is_source__num_)
|
|
208
|
-
equal(ctx0.has(is_source__num_), false)
|
|
209
|
-
equal(ctx1.has(is_source__num_), false)
|
|
210
|
-
})
|
|
211
|
-
test('be__has_', ()=>{
|
|
212
|
-
const ctx0 = ctx__new()
|
|
213
|
-
ctx__delete(ctx0, 'key')
|
|
214
|
-
equal(be__has_('key', ctx0), false)
|
|
215
|
-
ctx0.set('key', true)
|
|
216
|
-
equal(be__has_('key', ctx0), true)
|
|
217
|
-
ctx__delete(ctx0, 'key')
|
|
218
|
-
equal(be__has_('key', ctx0), false)
|
|
219
|
-
const ctx1 = ctx__new()
|
|
220
|
-
const nested__ctx = [ctx0, ctx1]
|
|
221
|
-
ctx1.set('key', true)
|
|
222
|
-
equal(be__has_('key', nested__ctx), true)
|
|
223
|
-
})
|
|
224
|
-
test('be__has__ctx_', ()=>{
|
|
225
|
-
const ctx0 = ctx__new()
|
|
226
|
-
ctx__delete(ctx0, 'key')
|
|
227
|
-
equal(be__has__ctx_('key', ctx0), null)
|
|
228
|
-
ctx0.set('key', true)
|
|
229
|
-
equal(be__has__ctx_('key', ctx0), ctx0)
|
|
230
|
-
ctx__delete(ctx0, 'key')
|
|
231
|
-
equal(be__has__ctx_('key', ctx0), null)
|
|
232
|
-
const ctx1 = ctx__new()
|
|
233
|
-
const nested__ctx = [ctx0, ctx1]
|
|
234
|
-
ctx1.set('key', true)
|
|
235
|
-
equal(be__has__ctx_('key', nested__ctx), ctx1)
|
|
236
|
-
})
|
|
237
|
-
test('be__val_', ()=>{
|
|
238
|
-
const ctx = ctx__new()
|
|
239
|
-
const val_ = be_<boolean>('val_', ()=>true)
|
|
240
|
-
equal(val_(ctx), true)
|
|
241
|
-
equal(ctx.get(val_), true)
|
|
242
|
-
equal(be__val_(val_, ctx), true)
|
|
243
|
-
be__set(val_, ctx, false)
|
|
244
|
-
equal(val_(ctx), false)
|
|
245
|
-
equal(be__val_(val_, ctx), false)
|
|
246
|
-
})
|
|
247
|
-
test.run()
|
|
248
|
-
declare const test_ctx_sym:unique symbol
|
|
249
|
-
type test_ctx_T = Ctx&{
|
|
250
|
-
[test_ctx_sym]:any
|
|
251
|
-
}
|