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/README.md
CHANGED
package/all/all_union_a/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @typedef {import('../add/index.js').all_union_a_T}
|
|
1
|
+
/** @typedef {import('../add/index.js').all_union_a_T} */
|
|
2
2
|
/**
|
|
3
3
|
* @return {(a:all_union_a_T)=>all_union_a_T}
|
|
4
4
|
* @see {@link https://stackoverflow.com/questions/60131681/make-sure-array-has-all-types-from-a-union/75418615#75418615}
|
package/all/andand_or/index.js
CHANGED
package/all/andandfn/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @typedef {import('../andand/index.js').andand_key_T}
|
|
1
|
+
/** @typedef {import('../andand/index.js').andand_key_T} */
|
|
2
2
|
/**
|
|
3
3
|
* Applies `&&` to a chain of property name or function with return value from `obj`.
|
|
4
4
|
* @param {unknown}obj
|
|
@@ -24,7 +24,7 @@ export function andandfn(obj, ...name_a) {
|
|
|
24
24
|
return out_value
|
|
25
25
|
}
|
|
26
26
|
export { andandfn as andand__fn, }
|
|
27
|
-
/** @typedef {import('../andand/index.d.ts').andand_key_T}
|
|
27
|
+
/** @typedef {import('../andand/index.d.ts').andand_key_T} */
|
|
28
28
|
/**
|
|
29
29
|
* Returns a function that calls `andand_(obj, ...name_a)`
|
|
30
30
|
* @param {andand_key_T}name_a
|
package/all/arg_i0_a/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { slice_arg_spread_a_ } from '../slice_arg_spread_a/index.js'
|
|
2
|
-
/** @typedef {import('../slice_arg_spread_a_/index.js').slice_arg_spread_a__arg__T}
|
|
2
|
+
/** @typedef {import('../slice_arg_spread_a_/index.js').slice_arg_spread_a__arg__T} */
|
|
3
3
|
/**
|
|
4
4
|
* Returns a function that calls fn passing only the first argument.
|
|
5
5
|
* @param {slice_arg_spread_a__arg__T}fn
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assign } from '../assign/index.js'
|
|
2
2
|
import { HttpError } from '../http_error/index.js'
|
|
3
|
-
/** @typedef {import('./index.d.ts').argument__bad_credentials_error_o_T}
|
|
3
|
+
/** @typedef {import('./index.d.ts').argument__bad_credentials_error_o_T} */
|
|
4
4
|
export const bad_credentials__default__message = 'Unauthorized'
|
|
5
5
|
/**
|
|
6
6
|
* @param {string}[message]
|
package/all/be/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { be__val__new_T, Ctx } from '../be_/index.js'
|
|
2
2
|
export declare function be<
|
|
3
3
|
Out extends NonNullable<unknown>
|
|
4
|
-
>(ctx:Ctx,
|
|
4
|
+
>(ctx:Ctx, val_:be__val__new_T<Out>):Out
|
|
5
5
|
export { be as b, }
|
package/all/be/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { be_ } from '../be_/index.js'
|
|
2
2
|
/**
|
|
3
3
|
* @param {import('../be_/index.js').Ctx}ctx
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {import('../be_/index.js').be__val__T}val_
|
|
4
|
+
* @param {import('../be_/index.js').be__val__new_T}val_
|
|
6
5
|
* @returns {NonNullable<unknown>}
|
|
7
6
|
*/
|
|
8
|
-
export function be(ctx,
|
|
9
|
-
return be_(
|
|
7
|
+
export function be(ctx, val_) {
|
|
8
|
+
return be_(val_)(ctx)
|
|
10
9
|
}
|
|
11
10
|
export { be as b, }
|
package/all/be_/index.d.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
export declare const pending_symbol:unique symbol
|
|
2
2
|
export declare function globalThis__be_<
|
|
3
|
-
|
|
3
|
+
val_T,
|
|
4
4
|
ctx_T extends Ctx = Ctx
|
|
5
|
-
>(
|
|
6
|
-
val_:be__val__T<Val, ctx_T>,
|
|
7
|
-
be__params?:be__params_T
|
|
8
|
-
):Be<Val, ctx_T>
|
|
9
|
-
export declare function globalThis__be_<
|
|
10
|
-
Val,
|
|
11
|
-
ctx_T extends Ctx = Ctx
|
|
12
|
-
>(
|
|
13
|
-
id:string,
|
|
14
|
-
val_:be__val__T<Val, ctx_T>,
|
|
15
|
-
be__params?:be__params_T
|
|
16
|
-
):Be<Val, ctx_T>
|
|
5
|
+
>(val_:be__val__new_T<val_T, ctx_T>):Be<val_T, ctx_T>
|
|
17
6
|
/**
|
|
18
7
|
* Auto-memoization function for the Ctx.
|
|
19
8
|
*
|
|
@@ -21,20 +10,13 @@ export declare function globalThis__be_<
|
|
|
21
10
|
* otherwise it creates the value using the val_ factory function.
|
|
22
11
|
*/
|
|
23
12
|
export declare function be_<
|
|
24
|
-
|
|
13
|
+
val_T,
|
|
25
14
|
ctx_T extends Ctx = Ctx
|
|
26
|
-
>(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
):Be<Val, ctx_T>
|
|
30
|
-
export declare function be_<
|
|
31
|
-
Val,
|
|
15
|
+
>(val_:be__val__new_T<val_T, ctx_T>):Be<val_T, ctx_T>
|
|
16
|
+
export type be___T<
|
|
17
|
+
val_T,
|
|
32
18
|
ctx_T extends Ctx = Ctx
|
|
33
|
-
>
|
|
34
|
-
id:string,
|
|
35
|
-
val_:be__val__T<Val, ctx_T>,
|
|
36
|
-
be__params?:be__params_T
|
|
37
|
-
):Be<Val, ctx_T>
|
|
19
|
+
> = typeof be_<val_T, ctx_T>
|
|
38
20
|
export {
|
|
39
21
|
be_ as _be,
|
|
40
22
|
be_ as b_,
|
|
@@ -47,35 +29,35 @@ export declare function source__map_ctx_<
|
|
|
47
29
|
ctx_T extends Ctx = Ctx
|
|
48
30
|
>(ctx:Ctx, is_source_:is_source__T):MapCtx
|
|
49
31
|
export declare function be__set<
|
|
50
|
-
|
|
32
|
+
val_T,
|
|
51
33
|
ctx_T extends Ctx = Ctx
|
|
52
34
|
>(
|
|
53
|
-
be:Be<
|
|
35
|
+
be:Be<val_T>,
|
|
54
36
|
ctx:ctx_T,
|
|
55
|
-
val:
|
|
37
|
+
val:val_T
|
|
56
38
|
):void
|
|
57
39
|
export declare function ctx__set<
|
|
58
|
-
|
|
40
|
+
val_T,
|
|
59
41
|
ctx_T extends Ctx = Ctx
|
|
60
42
|
>(
|
|
61
43
|
ctx:ctx_T,
|
|
62
|
-
be_OR_id:Be<
|
|
63
|
-
val:
|
|
44
|
+
be_OR_id:Be<val_T>|string|symbol,
|
|
45
|
+
val:val_T,
|
|
64
46
|
is_source_?:is_source__T
|
|
65
47
|
):void
|
|
66
48
|
export declare function be__delete<
|
|
67
|
-
|
|
49
|
+
val_T,
|
|
68
50
|
ctx_T extends Ctx = Ctx
|
|
69
51
|
>(
|
|
70
|
-
be:Be<
|
|
52
|
+
be:Be<val_T>,
|
|
71
53
|
ctx:ctx_T
|
|
72
54
|
):void
|
|
73
55
|
export declare function ctx__delete<
|
|
74
|
-
|
|
56
|
+
val_T,
|
|
75
57
|
ctx_T extends Ctx = Ctx
|
|
76
58
|
>(
|
|
77
59
|
ctx:ctx_T,
|
|
78
|
-
be_OR_id:Be<
|
|
60
|
+
be_OR_id:Be<val_T>|string|symbol,
|
|
79
61
|
is_source_?:is_source__T
|
|
80
62
|
):void
|
|
81
63
|
export declare function be__has_<
|
|
@@ -85,40 +67,40 @@ export declare function be__has__ctx_<
|
|
|
85
67
|
ctx_T extends Ctx = Ctx
|
|
86
68
|
>(be_OR_id:Be<unknown>|string, ctx:ctx_T):MapCtx
|
|
87
69
|
export declare function be__val_<
|
|
88
|
-
|
|
70
|
+
val_T,
|
|
89
71
|
ctx_T extends Ctx = Ctx
|
|
90
|
-
>(be_OR_id:Be<
|
|
72
|
+
>(be_OR_id:Be<val_T>|string, ctx:ctx_T):val_T|unknown|null
|
|
91
73
|
export declare type MapCtx = Map<Be<unknown>|string|symbol, unknown>
|
|
92
74
|
export interface NestedMapCtx extends Array<NestedMapCtx|MapCtx> {
|
|
93
75
|
}
|
|
94
76
|
export type Ctx = MapCtx|NestedMapCtx
|
|
95
77
|
export declare type Be<
|
|
96
|
-
|
|
78
|
+
val_T,
|
|
97
79
|
ctx_T extends Ctx = Ctx
|
|
98
|
-
> = ((ctx:ctx_T, params?:be_params_T)=>
|
|
80
|
+
> = ((ctx:ctx_T, params?:be_params_T)=>val_T)&{
|
|
99
81
|
id?:string
|
|
82
|
+
}&{
|
|
83
|
+
config:(params:be__config_params_T)=>Be<val_T, ctx_T>
|
|
84
|
+
}
|
|
85
|
+
export type be__config_params_T = {
|
|
86
|
+
id?:string
|
|
87
|
+
expired_?:expired__T
|
|
88
|
+
is_source_?:is_source__T
|
|
100
89
|
}
|
|
101
90
|
export declare type be__return_T<
|
|
102
|
-
|
|
91
|
+
val_T,
|
|
103
92
|
ctx_T extends Ctx = Ctx
|
|
104
|
-
> = Be<
|
|
93
|
+
> = Be<val_T, ctx_T>
|
|
105
94
|
export declare type be_T<
|
|
106
|
-
|
|
95
|
+
val_T,
|
|
107
96
|
ctx_T extends Ctx = Ctx
|
|
108
|
-
> = Be<
|
|
109
|
-
export declare type
|
|
110
|
-
|
|
97
|
+
> = Be<val_T, ctx_T>
|
|
98
|
+
export declare type be__val__new_T<
|
|
99
|
+
val_T,
|
|
111
100
|
ctx_T extends Ctx = Ctx
|
|
112
|
-
> = (ctx:ctx_T, be:Be<
|
|
113
|
-
export interface be__params_T {
|
|
114
|
-
is_source_?:is_source__T
|
|
115
|
-
expired_?:expired__T
|
|
116
|
-
be_?:typeof be_
|
|
117
|
-
}
|
|
118
|
-
export type be__opts_T = be__params_T
|
|
101
|
+
> = (ctx:ctx_T, be:Be<val_T, ctx_T>, params?:be_params_T)=>val_T
|
|
119
102
|
export interface be_params_T {
|
|
120
103
|
force?:boolean
|
|
121
104
|
}
|
|
122
|
-
export type be_opts_T = be_params_T
|
|
123
105
|
export type is_source__T = (map_ctx:MapCtx, ctx:Ctx)=>boolean
|
|
124
106
|
export type expired__T = (ctx:Ctx)=>boolean
|
package/all/be_/index.js
CHANGED
|
@@ -1,82 +1,46 @@
|
|
|
1
1
|
import { globalThis__prop__ensure } from '../globalThis__prop__ensure/index.js'
|
|
2
2
|
export * from './debug.js'
|
|
3
3
|
let be_M_is_source_ = globalThis.be_M_is_source_ ||= new WeakMap()
|
|
4
|
-
/** @typedef {import('./index.d.ts').Be}
|
|
5
|
-
/** @typedef {import('./index.d.ts').
|
|
6
|
-
/** @typedef {import('./index.d.ts').
|
|
7
|
-
/** @typedef {import('./index.d.ts').
|
|
8
|
-
/** @typedef {import('./index.d.ts').
|
|
9
|
-
/** @typedef {import('./index.d.ts').is_source__T}
|
|
4
|
+
/** @typedef {import('./index.d.ts').Be} */
|
|
5
|
+
/** @typedef {import('./index.d.ts').be_} */
|
|
6
|
+
/** @typedef {import('./index.d.ts').Ctx} */
|
|
7
|
+
/** @typedef {import('./index.d.ts').MapCtx} */
|
|
8
|
+
/** @typedef {import('./index.d.ts').be__val__new_T} */
|
|
9
|
+
/** @typedef {import('./index.d.ts').is_source__T} */
|
|
10
10
|
/**
|
|
11
11
|
* Auto-memoization function for the Ctx.
|
|
12
12
|
* Memoized on globalThis to allow packages being loaded multiple times, which can happen during bundling.
|
|
13
13
|
*
|
|
14
14
|
* Returns a function to ensure that a member id_OR_val_ is defined on a ctx object,
|
|
15
15
|
* otherwise it creates the value using the val__OR_be__params factory function.
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {be__val__T|be__params_T}[val__OR_be__params]
|
|
18
|
-
* @param {be__params_T}[be__params]
|
|
16
|
+
* @param {be__val__new_T}val__new
|
|
19
17
|
* @returns {Be}
|
|
20
18
|
* @private
|
|
21
19
|
*/
|
|
22
|
-
export function globalThis__be_(
|
|
23
|
-
|
|
24
|
-
val__OR_be__params,
|
|
25
|
-
be__params
|
|
26
|
-
) {
|
|
27
|
-
return globalThis__prop__ensure(
|
|
28
|
-
Symbol.for(id_OR_val_),
|
|
29
|
-
()=>be_(
|
|
30
|
-
id_OR_val_,
|
|
31
|
-
val__OR_be__params,
|
|
32
|
-
be__params))
|
|
33
|
-
}
|
|
20
|
+
export function globalThis__be_(val__new) {
|
|
21
|
+
return globalThis__prop__ensure(Symbol.for(val__new), ()=>be_(val__new))}
|
|
34
22
|
/**
|
|
35
23
|
* Auto-memoization function for the Ctx.
|
|
36
24
|
*
|
|
37
25
|
* Returns a function to ensure that a member id is defined on a Ctx,
|
|
38
26
|
* otherwise it creates the value using the val_ factory function.
|
|
39
|
-
* @param {
|
|
40
|
-
* @param {be__val__T|be__params_T}[val__new_OR_be__params]
|
|
41
|
-
* @param {be__params_T}[be__params]
|
|
27
|
+
* @param {be__val__new_T}val__new
|
|
42
28
|
* @returns {Be}
|
|
43
29
|
* @private
|
|
44
30
|
*/
|
|
45
|
-
export function be_(
|
|
46
|
-
id_OR_val__new,
|
|
47
|
-
val__new_OR_be__params,
|
|
48
|
-
be__params
|
|
49
|
-
) {
|
|
50
|
-
/** @type {string} */
|
|
51
|
-
let id
|
|
52
|
-
/** @type {be__val__T} */
|
|
53
|
-
let val__new
|
|
54
|
-
/** @type {is_source__T} */
|
|
55
|
-
let is_source_
|
|
31
|
+
export function be_(val__new) {
|
|
56
32
|
/** @type {expired__T} */
|
|
57
33
|
let expired_
|
|
58
|
-
if (typeof id_OR_val__new === 'string') {
|
|
59
|
-
val__new = val__new_OR_be__params
|
|
60
|
-
id = id_OR_val__new
|
|
61
|
-
} else {
|
|
62
|
-
val__new = id_OR_val__new
|
|
63
|
-
be__params = val__new_OR_be__params
|
|
64
|
-
}
|
|
65
|
-
if (be__params) {
|
|
66
|
-
is_source_ = be__params.is_source_
|
|
67
|
-
expired_ = be__params.expired_
|
|
68
|
-
}
|
|
69
34
|
let be = (argv__ctx, params)=>{
|
|
70
35
|
be_.argv__debug?.(argv__ctx)
|
|
71
|
-
let saved__val = be__val_(be, argv__ctx)
|
|
72
36
|
if (
|
|
73
37
|
!params?.force
|
|
74
38
|
&& be__has_(be, argv__ctx)
|
|
75
39
|
&& !expired_?.(argv__ctx)
|
|
76
40
|
) {
|
|
77
|
-
return
|
|
41
|
+
return be__val_(be, argv__ctx)
|
|
78
42
|
}
|
|
79
|
-
let ctx = source__map_ctx_(argv__ctx,
|
|
43
|
+
let ctx = source__map_ctx_(argv__ctx, be_M_is_source_.get(be))
|
|
80
44
|
be_.source__debug?.(ctx)
|
|
81
45
|
let pending = ctx.get(Symbol.for('pending'))
|
|
82
46
|
if (!pending) {
|
|
@@ -84,17 +48,21 @@ export function be_(
|
|
|
84
48
|
ctx.set(Symbol.for('pending'), pending)
|
|
85
49
|
}
|
|
86
50
|
be_.pending__debug?.(pending)
|
|
87
|
-
pending.set(be, id || be)
|
|
51
|
+
pending.set(be, be.id || be)
|
|
88
52
|
let val = val__new ? val__new(argv__ctx, be, params) : null
|
|
89
53
|
ctx.set(be, val)
|
|
90
|
-
if (id) {
|
|
91
|
-
ctx.set(id, val)
|
|
54
|
+
if (be.id) {
|
|
55
|
+
ctx.set(be.id, val)
|
|
92
56
|
}
|
|
93
57
|
pending.delete(be)
|
|
94
58
|
return val
|
|
95
59
|
}
|
|
96
|
-
|
|
97
|
-
|
|
60
|
+
be.config = params=>{
|
|
61
|
+
be.id = params.id
|
|
62
|
+
expired_ = params.expired_
|
|
63
|
+
be_M_is_source_.set(be, params.is_source_)
|
|
64
|
+
return be
|
|
65
|
+
}
|
|
98
66
|
return be
|
|
99
67
|
}
|
|
100
68
|
export {
|
package/all/be_/index.test.ts
CHANGED
|
@@ -17,9 +17,9 @@ test('be_|Map', ()=>{
|
|
|
17
17
|
const ctx = ctx__new()
|
|
18
18
|
let incrementer_num = 0
|
|
19
19
|
const incrementer = ()=>++incrementer_num
|
|
20
|
-
const root_ = be_(
|
|
21
|
-
const child_ = be_(
|
|
22
|
-
const child1_ = be_(
|
|
20
|
+
const root_ = be_(()=>incrementer()).config({ id: 'root_' })
|
|
21
|
+
const child_ = be_(ctx=>root_(ctx) + incrementer()).config({ id: 'child_' })
|
|
22
|
+
const child1_ = be_(ctx=>root_(ctx) + child_(ctx)).config({ id: 'child1_' })
|
|
23
23
|
equal(root_(ctx), 1)
|
|
24
24
|
equal(ctx.get('root_'), 1)
|
|
25
25
|
equal(child_(ctx), 3)
|
|
@@ -31,12 +31,12 @@ test('be_|simple array', ()=>{
|
|
|
31
31
|
const ctx0 = ctx__new()
|
|
32
32
|
const ctx1 = ctx__new()
|
|
33
33
|
const ctx = [ctx0, ctx1]
|
|
34
|
-
const root_ = be_('root_'
|
|
34
|
+
const root_ = be_(()=>1).config({ id: 'root_' })
|
|
35
35
|
equal(root_(ctx1), 1)
|
|
36
36
|
equal(root_(ctx), 1)
|
|
37
37
|
equal(ctx0.has(root_), false)
|
|
38
38
|
equal(ctx1.has(root_), true)
|
|
39
|
-
const child_ = be_(
|
|
39
|
+
const child_ = be_(ctx=>root_(ctx) + 1).config({ id: 'child_' })
|
|
40
40
|
equal(child_(ctx), 2)
|
|
41
41
|
equal(ctx0.has(child_), true)
|
|
42
42
|
equal(ctx1.has(child_), false)
|
|
@@ -47,14 +47,14 @@ test('be_|nested array', ()=>{
|
|
|
47
47
|
const ctx2 = ctx__new()
|
|
48
48
|
const ctx3 = ctx__new()
|
|
49
49
|
const ctx = [[[ctx0], ctx1], [ctx2, ctx3]]
|
|
50
|
-
const root_ = be_('root_'
|
|
50
|
+
const root_ = be_(()=>1).config({ id: 'root_' })
|
|
51
51
|
equal(root_(ctx3), 1)
|
|
52
52
|
equal(root_(ctx), 1)
|
|
53
53
|
equal(ctx0.has(root_), false)
|
|
54
54
|
equal(ctx1.has(root_), false)
|
|
55
55
|
equal(ctx2.has(root_), false)
|
|
56
56
|
equal(ctx3.has(root_), true)
|
|
57
|
-
const child_ = be_(
|
|
57
|
+
const child_ = be_(ctx=>root_(ctx) + 1).config({ id: 'child_' })
|
|
58
58
|
equal(child_(ctx), 2)
|
|
59
59
|
equal(ctx0.has(child_), true)
|
|
60
60
|
equal(ctx1.has(child_), false)
|
|
@@ -67,13 +67,12 @@ test('be_|is_source_', ()=>{
|
|
|
67
67
|
ctx1.set('matching', true)
|
|
68
68
|
const ctx = [ctx0, ctx1]
|
|
69
69
|
const be__ctx_a:Ctx[] = []
|
|
70
|
-
const root_ = be_(
|
|
70
|
+
const root_ = be_(ctx=>{
|
|
71
71
|
be__ctx_a.push(ctx)
|
|
72
72
|
return 1
|
|
73
|
-
}
|
|
74
|
-
is_source_(
|
|
75
|
-
|
|
76
|
-
}
|
|
73
|
+
}).config({
|
|
74
|
+
is_source_: map_ctx=>!!map_ctx.get('matching'),
|
|
75
|
+
id: 'root_'
|
|
77
76
|
})
|
|
78
77
|
equal(root_(ctx), 1)
|
|
79
78
|
equal(be__ctx_a, [[ctx0, ctx1]])
|
|
@@ -82,7 +81,7 @@ test('be_|is_source_', ()=>{
|
|
|
82
81
|
})
|
|
83
82
|
test('be_|Ctx generic type', ()=>{
|
|
84
83
|
const valid_ctx = ctx__new() as test_ctx_T
|
|
85
|
-
const val_ = be_<boolean, test_ctx_T>('val_'
|
|
84
|
+
const val_ = be_<boolean, test_ctx_T>(()=>true).config({ id: 'val_' })
|
|
86
85
|
val_(valid_ctx)
|
|
87
86
|
// val_(ctx_()) // type error
|
|
88
87
|
})
|
|
@@ -91,13 +90,14 @@ test('be_|Ctx|NestedMapCtx', ()=>{
|
|
|
91
90
|
const ctx1 = ctx__new()
|
|
92
91
|
ctx1.set('matching', true)
|
|
93
92
|
const ctx = [ctx0, ctx1]
|
|
94
|
-
const nested__ctx_ = be_<Ctx>(
|
|
93
|
+
const nested__ctx_ = be_<Ctx>(ctx=>[ctx]).config({ id: 'nested__ctx_' })
|
|
95
94
|
equal(nested__ctx_(ctx), [[ctx0, ctx1]])
|
|
96
95
|
})
|
|
97
96
|
test('be__set', ()=>{
|
|
98
97
|
const ctx0 = ctx__new()
|
|
99
|
-
const val_ = be_<number|undefined>(
|
|
100
|
-
is_source_: map_ctx=>map_ctx === ctx0
|
|
98
|
+
const val_ = be_<number|undefined>(()=>undefined).config({
|
|
99
|
+
is_source_: map_ctx=>map_ctx === ctx0,
|
|
100
|
+
id: 'val_'
|
|
101
101
|
})
|
|
102
102
|
be__set(val_, ctx0, 1)
|
|
103
103
|
equal(val_(ctx0), 1)
|
|
@@ -121,7 +121,7 @@ test('ctx__set', ()=>{
|
|
|
121
121
|
})
|
|
122
122
|
test('be__delete', ()=>{
|
|
123
123
|
const ctx0 = ctx__new()
|
|
124
|
-
const val_ = be_<boolean>('val_'
|
|
124
|
+
const val_ = be_<boolean>(()=>true).config({ id: 'val_' })
|
|
125
125
|
be__delete(val_, ctx0)
|
|
126
126
|
equal(ctx0.has(val_), false)
|
|
127
127
|
equal(ctx0.has('val_'), false)
|
|
@@ -193,8 +193,7 @@ test('ctx__delete|be', ()=>{
|
|
|
193
193
|
equal(ctx0.has(num_), false)
|
|
194
194
|
equal(ctx1.has(num_), false)
|
|
195
195
|
const is_source__num_ =
|
|
196
|
-
be_(()=>1
|
|
197
|
-
{ is_source_: ctx=>!!ctx.get('ctx1') })
|
|
196
|
+
be_(()=>1).config({ is_source_: ctx=>!!ctx.get('ctx1') })
|
|
198
197
|
is_source__num_(nested__ctx)
|
|
199
198
|
equal(ctx0.has(is_source__num_), false)
|
|
200
199
|
equal(ctx1.has(is_source__num_), true)
|
|
@@ -236,7 +235,7 @@ test('be__has__ctx_', ()=>{
|
|
|
236
235
|
})
|
|
237
236
|
test('be__val_', ()=>{
|
|
238
237
|
const ctx = ctx__new()
|
|
239
|
-
const val_ = be_<boolean>('val_'
|
|
238
|
+
const val_ = be_<boolean>(()=>true).config({ id: 'val_' })
|
|
240
239
|
equal(val_(ctx), true)
|
|
241
240
|
equal(ctx.get(val_), true)
|
|
242
241
|
equal(be__val_(val_, ctx), true)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Be, be__config_params_T, be__val__new_T, Ctx } from '../be_/index.js'
|
|
2
|
+
import type { read_rmemo_T, rmemo_subscriber_T } from '../rmemo/index.js'
|
|
3
|
+
export declare function be_rmemo_pair_<
|
|
4
|
+
val_T,
|
|
5
|
+
rmemo_T extends read_rmemo_T<val_T> = read_rmemo_T<val_T>,
|
|
6
|
+
ctx_T extends Ctx = Ctx
|
|
7
|
+
>(
|
|
8
|
+
rmemo__new:be__val__new_T<val_T>,
|
|
9
|
+
...subscriber_a:rmemo_subscriber_T<rmemo_T>[]
|
|
10
|
+
):be_rmemo_pair_T<val_T, rmemo_T, ctx_T>
|
|
11
|
+
export type be_rmemo_pair_T<
|
|
12
|
+
val_T,
|
|
13
|
+
rmemo_T extends read_rmemo_T<val_T> = read_rmemo_T<val_T>,
|
|
14
|
+
ctx_T extends Ctx = Ctx
|
|
15
|
+
> = [
|
|
16
|
+
Be<rmemo_T, ctx_T>,
|
|
17
|
+
(ctx:ctx_T)=>val_T
|
|
18
|
+
]&{
|
|
19
|
+
config:(params:be__config_params_T)=>be_rmemo_pair_T<val_T, rmemo_T, ctx_T>
|
|
20
|
+
oninit:(fn:(ctx:Ctx, rmemo:rmemo_T)=>unknown)=>be_rmemo_pair_T<val_T, rmemo_T, ctx_T>
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { be_ } from '../be_/index.js'
|
|
2
|
+
import { rmemo_ } from '../rmemo/index.js'
|
|
3
|
+
/** @typedef {import('../be_/index.d.ts').be__val__new_T} */
|
|
4
|
+
/** @typedef {import('../rmemo/index.d.ts').rmemo_subscriber_T} */
|
|
5
|
+
/** @typedef {import('./index.d.ts').be_rmemo_pair_T} */
|
|
6
|
+
/**
|
|
7
|
+
* @param {be__val__new_T<unknown>}val__new
|
|
8
|
+
* @param {rmemo_subscriber_T[]}subscriber_a
|
|
9
|
+
* @returns {be_rmemo_pair_T}
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export function be_rmemo_pair_(val__new, ...subscriber_a) {
|
|
13
|
+
let oninit
|
|
14
|
+
const be_rmemo_pair = [
|
|
15
|
+
be_(ctx=>{
|
|
16
|
+
let rmemo = rmemo_(()=>val__new(ctx), ...subscriber_a)
|
|
17
|
+
oninit?.(ctx, rmemo)
|
|
18
|
+
return rmemo
|
|
19
|
+
}),
|
|
20
|
+
ctx=>be_rmemo_pair[0](ctx)._,
|
|
21
|
+
]
|
|
22
|
+
be_rmemo_pair.config = params=>(be_rmemo_pair[0].config(params), be_rmemo_pair)
|
|
23
|
+
be_rmemo_pair.oninit = _oninit=>(oninit = _oninit, be_rmemo_pair)
|
|
24
|
+
return be_rmemo_pair
|
|
25
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { be_rsig_triple_ } from '../be_rsig_triple/index.js'
|
|
4
|
+
import { ctx__new } from '../ctx/index.js'
|
|
5
|
+
import type { read_rmemo_T, readwrite_rmemo_T } from '../rmemo/index.js'
|
|
6
|
+
import { be_rmemo_pair_ } from './index.js'
|
|
7
|
+
test('be_rmemo_pair_', ()=>{
|
|
8
|
+
const [
|
|
9
|
+
base$_,
|
|
10
|
+
base_,
|
|
11
|
+
base__set,
|
|
12
|
+
] = be_rsig_triple_(()=>1)
|
|
13
|
+
const [
|
|
14
|
+
foobar$_,
|
|
15
|
+
foobar_,
|
|
16
|
+
] = be_rmemo_pair_(ctx=>base_(ctx) + 1)
|
|
17
|
+
const ctx = ctx__new()
|
|
18
|
+
equal(foobar$_(ctx)._, 2)
|
|
19
|
+
equal(foobar_(ctx), 2)
|
|
20
|
+
base__set(ctx, 2)
|
|
21
|
+
equal(foobar$_(ctx)._, 3)
|
|
22
|
+
equal(foobar_(ctx), 3)
|
|
23
|
+
})
|
|
24
|
+
test('be_rmemo_pair_|+id|+is_source_|+oninit|+subscriber_a', ()=>{
|
|
25
|
+
const ctx = ctx__new()
|
|
26
|
+
let subscriber_count = 0
|
|
27
|
+
const [
|
|
28
|
+
base$_,
|
|
29
|
+
base_,
|
|
30
|
+
base__set,
|
|
31
|
+
] = be_rsig_triple_(()=>1)
|
|
32
|
+
.config({ is_source_: map_ctx=>map_ctx === ctx })
|
|
33
|
+
const [
|
|
34
|
+
foobar$_,
|
|
35
|
+
foobar_,
|
|
36
|
+
] = be_rmemo_pair_<number, readwrite_rmemo_T<number>&{
|
|
37
|
+
custom:string
|
|
38
|
+
}>(ctx=>base_(ctx) + 1,
|
|
39
|
+
()=>subscriber_count++)
|
|
40
|
+
.config({
|
|
41
|
+
id: 'foobar',
|
|
42
|
+
is_source_: map_ctx=>map_ctx === ctx,
|
|
43
|
+
})
|
|
44
|
+
.oninit((_ctx, foobar$)=>{
|
|
45
|
+
if (Array.isArray(_ctx)) equal(_ctx[1], ctx)
|
|
46
|
+
else equal(_ctx, ctx)
|
|
47
|
+
foobar$.custom = 'custom-val'
|
|
48
|
+
})
|
|
49
|
+
equal(subscriber_count, 0)
|
|
50
|
+
equal(foobar$_([ctx__new(), ctx])._, 2)
|
|
51
|
+
equal(foobar_([ctx__new(), ctx]), 2)
|
|
52
|
+
equal(foobar$_(ctx)._, 2)
|
|
53
|
+
equal(foobar_(ctx), 2)
|
|
54
|
+
equal((ctx.get('foobar') as read_rmemo_T<number>)._, 2)
|
|
55
|
+
equal(foobar$_(ctx).custom, 'custom-val')
|
|
56
|
+
equal(subscriber_count, 1)
|
|
57
|
+
base__set(ctx, 2)
|
|
58
|
+
equal(foobar$_([ctx__new(), ctx])._, 3)
|
|
59
|
+
equal(foobar_([ctx__new(), ctx]), 3)
|
|
60
|
+
equal(foobar$_(ctx)._, 3)
|
|
61
|
+
equal(foobar_(ctx), 3)
|
|
62
|
+
equal((ctx.get('foobar') as read_rmemo_T<number>)._, 3)
|
|
63
|
+
equal(foobar$_(ctx).custom, 'custom-val')
|
|
64
|
+
equal(subscriber_count, 1)
|
|
65
|
+
})
|
|
66
|
+
test.run()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Be, be__config_params_T, be__val__new_T, Ctx } from '../be_/index.js'
|
|
2
|
+
import type { readwrite_rmemo_T, rmemo_subscriber_T } from '../rmemo/index.js'
|
|
3
|
+
export declare function be_rsig_triple_<
|
|
4
|
+
val_T,
|
|
5
|
+
rsig_T extends readwrite_rmemo_T<val_T> = readwrite_rmemo_T<val_T>,
|
|
6
|
+
ctx_T extends Ctx = Ctx
|
|
7
|
+
>(
|
|
8
|
+
rmemo__new:be__val__new_T<val_T>,
|
|
9
|
+
...subscriber_a:rmemo_subscriber_T<readwrite_rmemo_T<val_T>>[]
|
|
10
|
+
):be_rsig_triple_T<val_T, rsig_T, ctx_T>
|
|
11
|
+
export type be_rsig_triple_T<
|
|
12
|
+
val_T,
|
|
13
|
+
rsig_T extends readwrite_rmemo_T<val_T> = readwrite_rmemo_T<val_T>,
|
|
14
|
+
ctx_T extends Ctx = Ctx
|
|
15
|
+
> = [
|
|
16
|
+
Be<rsig_T>,
|
|
17
|
+
(ctx:ctx_T)=>val_T,
|
|
18
|
+
(ctx:ctx_T, val:val_T)=>void
|
|
19
|
+
]&{
|
|
20
|
+
config:(config:be__config_params_T)=>be_rsig_triple_T<val_T, rsig_T, ctx_T>
|
|
21
|
+
oninit:(fn:(ctx:Ctx, rsig:rsig_T)=>unknown)=>be_rsig_triple_T<val_T, rsig_T, ctx_T>
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { be_ } from '../be_/index.js'
|
|
2
|
+
import { rsig_ } from '../rmemo/index.js'
|
|
3
|
+
/** @typedef {import('../be_/index.d.ts').be__val__new_T} */
|
|
4
|
+
/** @typedef {import('../rmemo/index.d.ts').rmemo_subscriber_T} */
|
|
5
|
+
/** @typedef {import('./index.d.ts').be_rsig_triple_T} */
|
|
6
|
+
/**
|
|
7
|
+
* @param {be__val__new_T<unknown>}val__new
|
|
8
|
+
* @param {rmemo_subscriber_T[]}subscriber_a
|
|
9
|
+
* @returns {be_rsig_triple_T}
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export function be_rsig_triple_(val__new, ...subscriber_a) {
|
|
13
|
+
let oninit
|
|
14
|
+
const be_rsig_triple = [
|
|
15
|
+
be_(ctx=>{
|
|
16
|
+
let rsig = rsig_(val__new(ctx), ...subscriber_a)
|
|
17
|
+
oninit?.(ctx, rsig)
|
|
18
|
+
return rsig
|
|
19
|
+
}),
|
|
20
|
+
ctx=>be_rsig_triple[0](ctx)._,
|
|
21
|
+
(ctx, val)=>{
|
|
22
|
+
be_rsig_triple[0](ctx)._ = val
|
|
23
|
+
},
|
|
24
|
+
]
|
|
25
|
+
be_rsig_triple.config = params=>(be_rsig_triple[0].config(params), be_rsig_triple)
|
|
26
|
+
be_rsig_triple.oninit = _oninit=>(oninit = _oninit, be_rsig_triple)
|
|
27
|
+
return be_rsig_triple
|
|
28
|
+
}
|