ctx-core 4.0.0 → 4.1.1
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 +11 -37
- package/all/be_/index.js +44 -95
- package/all/be_/index.test.ts +27 -60
- package/all/be_rmemo_pair/index.d.ts +11 -7
- package/all/be_rmemo_pair/index.js +25 -14
- package/all/be_rmemo_pair/index.test.ts +48 -11
- package/all/be_rsig_triple/index.d.ts +11 -7
- package/all/be_rsig_triple/index.js +23 -15
- package/all/be_rsig_triple/index.test.ts +35 -9
- package/all/ctx/index.js +7 -8
- package/all/ctx/index.test.ts +1 -0
- package/all/index.d.ts +0 -2
- package/all/index.js +0 -2
- package/all/rmemo/index.js +4 -6
- package/object/index.d.ts +0 -2
- package/object/index.js +0 -2
- package/package.json +26 -5
- package/all/be_/debug.js +0 -25
- package/all/rc_be/index.d.ts +0 -6
- package/all/rc_be/index.js +0 -15
- package/all/rc_be_/index.d.ts +0 -39
- package/all/rc_be_/index.js +0 -53
package/all/be_/index.d.ts
CHANGED
|
@@ -6,36 +6,23 @@ export declare function globalThis__be_<
|
|
|
6
6
|
/**
|
|
7
7
|
* Auto-memoization function for the Ctx.
|
|
8
8
|
*
|
|
9
|
-
* Returns a function to ensure that a member id is defined on a
|
|
10
|
-
* otherwise it
|
|
9
|
+
* Returns a function to ensure that a member id is defined on a Ctx,
|
|
10
|
+
* otherwise it caches & uses the return value of val__new.
|
|
11
11
|
*/
|
|
12
12
|
export declare function be_<
|
|
13
13
|
val_T,
|
|
14
14
|
ctx_T extends Ctx = Ctx
|
|
15
|
-
>(
|
|
15
|
+
>(val__new:be__val__new_T<val_T, ctx_T>, config?:be_config_T):Be<val_T, ctx_T>
|
|
16
16
|
export type be___T<
|
|
17
17
|
val_T,
|
|
18
18
|
ctx_T extends Ctx = Ctx
|
|
19
19
|
> = typeof be_<val_T, ctx_T>
|
|
20
|
-
export {
|
|
21
|
-
be_ as _be,
|
|
22
|
-
be_ as b_,
|
|
23
|
-
be_ as _b,
|
|
24
|
-
}
|
|
25
20
|
export declare function be__is_source_<
|
|
26
21
|
ctx_T extends Ctx = Ctx
|
|
27
22
|
>(be:Be<unknown>):(map_ctx:MapCtx, ctx:ctx_T)=>boolean
|
|
28
23
|
export declare function source__map_ctx_<
|
|
29
24
|
ctx_T extends Ctx = Ctx
|
|
30
|
-
>(ctx:
|
|
31
|
-
export declare function be__set<
|
|
32
|
-
val_T,
|
|
33
|
-
ctx_T extends Ctx = Ctx
|
|
34
|
-
>(
|
|
35
|
-
be:Be<val_T>,
|
|
36
|
-
ctx:ctx_T,
|
|
37
|
-
val:val_T
|
|
38
|
-
):void
|
|
25
|
+
>(ctx:ctx_T, is_source_:is_source__T):MapCtx
|
|
39
26
|
export declare function ctx__set<
|
|
40
27
|
val_T,
|
|
41
28
|
ctx_T extends Ctx = Ctx
|
|
@@ -45,13 +32,6 @@ export declare function ctx__set<
|
|
|
45
32
|
val:val_T,
|
|
46
33
|
is_source_?:is_source__T
|
|
47
34
|
):void
|
|
48
|
-
export declare function be__delete<
|
|
49
|
-
val_T,
|
|
50
|
-
ctx_T extends Ctx = Ctx
|
|
51
|
-
>(
|
|
52
|
-
be:Be<val_T>,
|
|
53
|
-
ctx:ctx_T
|
|
54
|
-
):void
|
|
55
35
|
export declare function ctx__delete<
|
|
56
36
|
val_T,
|
|
57
37
|
ctx_T extends Ctx = Ctx
|
|
@@ -63,28 +43,25 @@ export declare function ctx__delete<
|
|
|
63
43
|
export declare function be__has_<
|
|
64
44
|
ctx_T extends Ctx = Ctx
|
|
65
45
|
>(be_OR_id:Be<unknown>|string, ctx:ctx_T):boolean
|
|
66
|
-
export declare function
|
|
46
|
+
export declare function be__ctx_<
|
|
67
47
|
ctx_T extends Ctx = Ctx
|
|
68
48
|
>(be_OR_id:Be<unknown>|string, ctx:ctx_T):MapCtx
|
|
69
49
|
export declare function be__val_<
|
|
70
50
|
val_T,
|
|
71
51
|
ctx_T extends Ctx = Ctx
|
|
72
52
|
>(be_OR_id:Be<val_T>|string, ctx:ctx_T):val_T|unknown|null
|
|
73
|
-
export
|
|
74
|
-
export
|
|
75
|
-
}
|
|
53
|
+
export type MapCtx = Map<Be<unknown>|string|symbol, unknown>&{ is_ctx: true }
|
|
54
|
+
export type NestedMapCtx = Array<NestedMapCtx|MapCtx>
|
|
76
55
|
export type Ctx = MapCtx|NestedMapCtx
|
|
77
56
|
export declare type Be<
|
|
78
57
|
val_T,
|
|
79
58
|
ctx_T extends Ctx = Ctx
|
|
80
|
-
> = ((ctx:ctx_T
|
|
59
|
+
> = ((ctx:ctx_T)=>val_T)&{
|
|
60
|
+
is_be: true
|
|
81
61
|
id?:string
|
|
82
|
-
}&{
|
|
83
|
-
config:(params:be__config_params_T)=>Be<val_T, ctx_T>
|
|
84
62
|
}
|
|
85
|
-
export type
|
|
63
|
+
export type be_config_T = {
|
|
86
64
|
id?:string
|
|
87
|
-
expired_?:expired__T
|
|
88
65
|
is_source_?:is_source__T
|
|
89
66
|
}
|
|
90
67
|
export declare type be__return_T<
|
|
@@ -98,9 +75,6 @@ export declare type be_T<
|
|
|
98
75
|
export declare type be__val__new_T<
|
|
99
76
|
val_T,
|
|
100
77
|
ctx_T extends Ctx = Ctx
|
|
101
|
-
> = (ctx:ctx_T, be:Be<val_T, ctx_T
|
|
102
|
-
export interface be_params_T {
|
|
103
|
-
force?:boolean
|
|
104
|
-
}
|
|
78
|
+
> = (ctx:ctx_T, be:Be<val_T, ctx_T>)=>val_T
|
|
105
79
|
export type is_source__T = (map_ctx:MapCtx, ctx:Ctx)=>boolean
|
|
106
80
|
export type expired__T = (ctx:Ctx)=>boolean
|
package/all/be_/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { globalThis__prop__ensure } from '../globalThis__prop__ensure/index.js'
|
|
2
|
-
export * from './debug.js'
|
|
3
|
-
let be_M_is_source_ = globalThis.be_M_is_source_ ||= new WeakMap()
|
|
4
2
|
/** @typedef {import('./index.d.ts').Be} */
|
|
5
3
|
/** @typedef {import('./index.d.ts').be_} */
|
|
4
|
+
/** @typedef {import('./index.d.ts').be_config_T} */
|
|
6
5
|
/** @typedef {import('./index.d.ts').Ctx} */
|
|
7
6
|
/** @typedef {import('./index.d.ts').MapCtx} */
|
|
8
7
|
/** @typedef {import('./index.d.ts').be__val__new_T} */
|
|
@@ -12,82 +11,49 @@ let be_M_is_source_ = globalThis.be_M_is_source_ ||= new WeakMap()
|
|
|
12
11
|
* Memoized on globalThis to allow packages being loaded multiple times, which can happen during bundling.
|
|
13
12
|
*
|
|
14
13
|
* Returns a function to ensure that a member id_OR_val_ is defined on a ctx object,
|
|
15
|
-
* otherwise it
|
|
14
|
+
* otherwise it caches & uses the return value of val__new.
|
|
16
15
|
* @param {be__val__new_T}val__new
|
|
17
16
|
* @returns {Be}
|
|
18
17
|
* @private
|
|
19
18
|
*/
|
|
20
19
|
export function globalThis__be_(val__new) {
|
|
21
|
-
return globalThis__prop__ensure(Symbol.for(val__new), ()=>be_(val__new))}
|
|
20
|
+
return globalThis__prop__ensure(Symbol.for(val__new), ()=>be_(val__new)) }
|
|
22
21
|
/**
|
|
23
22
|
* Auto-memoization function for the Ctx.
|
|
24
23
|
*
|
|
25
24
|
* Returns a function to ensure that a member id is defined on a Ctx,
|
|
26
|
-
* otherwise it
|
|
25
|
+
* otherwise it caches & uses the return value of val__new.
|
|
27
26
|
* @param {be__val__new_T}val__new
|
|
27
|
+
* @param {be_config_T}[config]
|
|
28
28
|
* @returns {Be}
|
|
29
29
|
* @private
|
|
30
30
|
*/
|
|
31
|
-
export function be_(val__new) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
export function be_(val__new, config) {
|
|
32
|
+
let be = argv__ctx=>{
|
|
33
|
+
let flat__argv__ctx = Array.isArray(argv__ctx) && argv__ctx.flat(Infinity)
|
|
34
|
+
let be__ctx =
|
|
35
|
+
flat__argv__ctx
|
|
36
|
+
? flat__argv__ctx.find(ctx=>ctx.has(be))
|
|
37
|
+
: argv__ctx.has(be) && argv__ctx
|
|
38
|
+
if (!be__ctx) {
|
|
39
|
+
be__ctx =
|
|
40
|
+
flat__argv__ctx
|
|
41
|
+
? flat__argv__ctx.find(ctx=>!be.is_source_ || be.is_source_(ctx, argv__ctx))
|
|
42
|
+
: (!be.is_source_ || be.is_source_(argv__ctx, argv__ctx)) && argv__ctx
|
|
43
|
+
// circular dependency state
|
|
44
|
+
// if val__new calls this be before returning, Symbol('cir') will be the value of this be
|
|
45
|
+
// 'cir' is used instead of 'circular' to reduce the payload by a few bytes
|
|
46
|
+
be__ctx.set(be, Symbol('cir'))
|
|
47
|
+
be__ctx.set(be, val__new(argv__ctx, be))
|
|
48
|
+
if (be.id) be__ctx.set(be.id, be__ctx.get(be))
|
|
42
49
|
}
|
|
43
|
-
|
|
44
|
-
be_.source__debug?.(ctx)
|
|
45
|
-
let pending = ctx.get(Symbol.for('pending'))
|
|
46
|
-
if (!pending) {
|
|
47
|
-
pending = new Map
|
|
48
|
-
ctx.set(Symbol.for('pending'), pending)
|
|
49
|
-
}
|
|
50
|
-
be_.pending__debug?.(pending)
|
|
51
|
-
pending.set(be, be.id || be)
|
|
52
|
-
let val = val__new ? val__new(argv__ctx, be, params) : null
|
|
53
|
-
ctx.set(be, val)
|
|
54
|
-
if (be.id) {
|
|
55
|
-
ctx.set(be.id, val)
|
|
56
|
-
}
|
|
57
|
-
pending.delete(be)
|
|
58
|
-
return val
|
|
59
|
-
}
|
|
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
|
|
50
|
+
return be__ctx.get(be)
|
|
65
51
|
}
|
|
52
|
+
be.id = config?.id
|
|
53
|
+
be.is_source_ = config?.is_source_
|
|
54
|
+
be.is_be = true
|
|
66
55
|
return be
|
|
67
56
|
}
|
|
68
|
-
export {
|
|
69
|
-
be_ as _be,
|
|
70
|
-
be_ as b_,
|
|
71
|
-
be_ as _b,
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @param {Be}be
|
|
75
|
-
* @returns {is_source__T}
|
|
76
|
-
* @private
|
|
77
|
-
*/
|
|
78
|
-
export function be__is_source__(be) {
|
|
79
|
-
return be_M_is_source_.get(be)
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* @param {Be}be
|
|
83
|
-
* @param {Ctx}ctx
|
|
84
|
-
* @param {unknown}val
|
|
85
|
-
* @returns {unknown}
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
|
-
export function be__set(be, ctx, val) {
|
|
89
|
-
ctx__set(ctx, be, val, be__is_source__(be))
|
|
90
|
-
}
|
|
91
57
|
/**
|
|
92
58
|
* @param {Ctx}ctx
|
|
93
59
|
* @param {Be|string|symbol}be_OR_id
|
|
@@ -100,7 +66,7 @@ export function ctx__set(
|
|
|
100
66
|
ctx,
|
|
101
67
|
be_OR_id,
|
|
102
68
|
val,
|
|
103
|
-
is_source_
|
|
69
|
+
is_source_ = be_OR_id.is_source_
|
|
104
70
|
) {
|
|
105
71
|
let source__map_ctx = source__map_ctx_(ctx, is_source_)
|
|
106
72
|
if (source__map_ctx) {
|
|
@@ -111,18 +77,9 @@ export function ctx__set(
|
|
|
111
77
|
}
|
|
112
78
|
}
|
|
113
79
|
}
|
|
114
|
-
/**
|
|
115
|
-
* @param {Be}be
|
|
116
|
-
* @param {Ctx}ctx
|
|
117
|
-
* @private
|
|
118
|
-
*/
|
|
119
|
-
export function be__delete(be, ctx) {
|
|
120
|
-
ctx__delete(ctx, be)
|
|
121
|
-
}
|
|
122
80
|
/**
|
|
123
81
|
* @param {Ctx}ctx
|
|
124
82
|
* @param {Be|string|symbol}be_OR_id
|
|
125
|
-
* @param {is_source__T}[is_source_]
|
|
126
83
|
*/
|
|
127
84
|
export function ctx__delete(
|
|
128
85
|
ctx,
|
|
@@ -149,7 +106,7 @@ export function ctx__delete(
|
|
|
149
106
|
* @private
|
|
150
107
|
*/
|
|
151
108
|
export function be__has_(be_or_id, argv__ctx) {
|
|
152
|
-
return Boolean(
|
|
109
|
+
return Boolean(be__ctx_(be_or_id, argv__ctx))
|
|
153
110
|
}
|
|
154
111
|
/**
|
|
155
112
|
* @param {Be|string}be_or_id
|
|
@@ -157,17 +114,17 @@ export function be__has_(be_or_id, argv__ctx) {
|
|
|
157
114
|
* @returns {MapCtx}
|
|
158
115
|
* @private
|
|
159
116
|
*/
|
|
160
|
-
export function
|
|
117
|
+
export function be__ctx_(be_or_id, argv__ctx) {
|
|
161
118
|
if (Array.isArray(argv__ctx)) {
|
|
162
|
-
for (let
|
|
163
|
-
|
|
164
|
-
if (
|
|
119
|
+
for (let ctx of argv__ctx) {
|
|
120
|
+
let be__ctx = be__ctx_(be_or_id, ctx)
|
|
121
|
+
if (be__ctx) return be__ctx
|
|
165
122
|
}
|
|
166
|
-
return null
|
|
167
123
|
} else {
|
|
168
|
-
|
|
124
|
+
if (argv__ctx.has(be_or_id)) return argv__ctx
|
|
169
125
|
}
|
|
170
126
|
}
|
|
127
|
+
export { be__ctx_ as be__has__ctx_ }
|
|
171
128
|
/**
|
|
172
129
|
* @param {Be|string}be_or_id
|
|
173
130
|
* @param {Ctx}argv__ctx
|
|
@@ -175,30 +132,22 @@ export function be__has__ctx_(be_or_id, argv__ctx) {
|
|
|
175
132
|
* @private
|
|
176
133
|
*/
|
|
177
134
|
export function be__val_(be_or_id, argv__ctx) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
let ctx = argv__ctx[i]
|
|
181
|
-
const be__has__ctx = be__has__ctx_(be_or_id, ctx)
|
|
182
|
-
if (be__has__ctx) return be__has__ctx.get(be_or_id)
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
return argv__ctx.get(be_or_id)
|
|
186
|
-
}
|
|
135
|
+
let be__ctx = be__ctx_(be_or_id, argv__ctx)
|
|
136
|
+
if (be__ctx) return be__ctx.get(be_or_id)
|
|
187
137
|
}
|
|
188
138
|
/**
|
|
189
|
-
* @param {Ctx}
|
|
139
|
+
* @param {Ctx}argv__ctx
|
|
190
140
|
* @param {is_source__T}is_source_
|
|
191
141
|
* @returns {unknown}
|
|
192
142
|
* @private
|
|
193
143
|
*/
|
|
194
|
-
export function source__map_ctx_(
|
|
195
|
-
if (Array.isArray(
|
|
196
|
-
for (let
|
|
197
|
-
let
|
|
198
|
-
let source__map_ctx = source__map_ctx_(i_ctx, is_source_)
|
|
144
|
+
export function source__map_ctx_(argv__ctx, is_source_) {
|
|
145
|
+
if (Array.isArray(argv__ctx)) {
|
|
146
|
+
for (let ctx of argv__ctx) {
|
|
147
|
+
let source__map_ctx = source__map_ctx_(ctx, is_source_)
|
|
199
148
|
if (source__map_ctx) return source__map_ctx
|
|
200
149
|
}
|
|
201
|
-
} else if (!is_source_ || is_source_(/** @type {MapCtx} */
|
|
202
|
-
return
|
|
150
|
+
} else if (!is_source_ || is_source_(/** @type {MapCtx} */argv__ctx, argv__ctx)) {
|
|
151
|
+
return argv__ctx
|
|
203
152
|
}
|
|
204
153
|
}
|
package/all/be_/index.test.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { test } from 'uvu'
|
|
2
2
|
import { equal } from 'uvu/assert'
|
|
3
3
|
import {
|
|
4
|
+
type Be,
|
|
4
5
|
be_,
|
|
5
|
-
|
|
6
|
+
be__ctx_,
|
|
6
7
|
be__has_,
|
|
7
|
-
be__has__ctx_,
|
|
8
|
-
be__set,
|
|
9
8
|
be__val_,
|
|
10
9
|
type Ctx,
|
|
11
10
|
ctx__delete,
|
|
@@ -13,13 +12,14 @@ import {
|
|
|
13
12
|
type MapCtx
|
|
14
13
|
} from '../be_/index.js'
|
|
15
14
|
import { ctx__new } from '../ctx/index.js'
|
|
15
|
+
|
|
16
16
|
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_(()=>incrementer()
|
|
21
|
-
const child_ = be_(ctx=>root_(ctx) + incrementer()
|
|
22
|
-
const child1_ = be_(ctx=>root_(ctx) + child_(ctx)
|
|
20
|
+
const root_ = be_(()=>incrementer(), { id: 'root_' })
|
|
21
|
+
const child_ = be_(ctx=>root_(ctx) + incrementer(), { id: 'child_' })
|
|
22
|
+
const child1_ = be_(ctx=>root_(ctx) + child_(ctx), { 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_(()=>1
|
|
34
|
+
const root_ = be_(()=>1, { 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_(ctx=>root_(ctx) + 1
|
|
39
|
+
const child_ = be_(ctx=>root_(ctx) + 1, { 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_(()=>1
|
|
50
|
+
const root_ = be_(()=>1, { 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_(ctx=>root_(ctx) + 1
|
|
57
|
+
const child_ = be_(ctx=>root_(ctx) + 1, { id: 'child_' })
|
|
58
58
|
equal(child_(ctx), 2)
|
|
59
59
|
equal(ctx0.has(child_), true)
|
|
60
60
|
equal(ctx1.has(child_), false)
|
|
@@ -70,7 +70,7 @@ test('be_|is_source_', ()=>{
|
|
|
70
70
|
const root_ = be_(ctx=>{
|
|
71
71
|
be__ctx_a.push(ctx)
|
|
72
72
|
return 1
|
|
73
|
-
}
|
|
73
|
+
}, {
|
|
74
74
|
is_source_: map_ctx=>!!map_ctx.get('matching'),
|
|
75
75
|
id: 'root_'
|
|
76
76
|
})
|
|
@@ -81,7 +81,7 @@ test('be_|is_source_', ()=>{
|
|
|
81
81
|
})
|
|
82
82
|
test('be_|Ctx generic type', ()=>{
|
|
83
83
|
const valid_ctx = ctx__new() as test_ctx_T
|
|
84
|
-
const val_ = be_<boolean, test_ctx_T>(()=>true
|
|
84
|
+
const val_ = be_<boolean, test_ctx_T>(()=>true, { id: 'val_' })
|
|
85
85
|
val_(valid_ctx)
|
|
86
86
|
// val_(ctx_()) // type error
|
|
87
87
|
})
|
|
@@ -90,23 +90,15 @@ test('be_|Ctx|NestedMapCtx', ()=>{
|
|
|
90
90
|
const ctx1 = ctx__new()
|
|
91
91
|
ctx1.set('matching', true)
|
|
92
92
|
const ctx = [ctx0, ctx1]
|
|
93
|
-
const nested__ctx_ = be_<Ctx>(ctx=>[ctx]
|
|
93
|
+
const nested__ctx_ = be_<Ctx>(ctx=>[ctx], { id: 'nested__ctx_' })
|
|
94
94
|
equal(nested__ctx_(ctx), [[ctx0, ctx1]])
|
|
95
95
|
})
|
|
96
|
-
test('
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
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)
|
|
96
|
+
test('be_|circular dependency', ()=>{
|
|
97
|
+
const be0:Be<symbol> = be_(ctx=>be1(ctx))
|
|
98
|
+
const be1:Be<symbol> = be_(ctx=>be0(ctx))
|
|
99
|
+
const ctx = ctx__new()
|
|
100
|
+
equal(String(be0(ctx)), 'Symbol(cir)')
|
|
101
|
+
equal(String(be1(ctx)), 'Symbol(cir)')
|
|
110
102
|
})
|
|
111
103
|
test('ctx__set', ()=>{
|
|
112
104
|
const ctx0 = ctx__new()
|
|
@@ -119,31 +111,6 @@ test('ctx__set', ()=>{
|
|
|
119
111
|
equal(ctx0.get('key'), 2)
|
|
120
112
|
equal(ctx1.has('key'), false)
|
|
121
113
|
})
|
|
122
|
-
test('be__delete', ()=>{
|
|
123
|
-
const ctx0 = ctx__new()
|
|
124
|
-
const val_ = be_<boolean>(()=>true).config({ id: 'val_' })
|
|
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
114
|
test('ctx__delete|id', ()=>{
|
|
148
115
|
const ctx0 = ctx__new()
|
|
149
116
|
ctx__delete(ctx0, 'key')
|
|
@@ -193,7 +160,7 @@ test('ctx__delete|be', ()=>{
|
|
|
193
160
|
equal(ctx0.has(num_), false)
|
|
194
161
|
equal(ctx1.has(num_), false)
|
|
195
162
|
const is_source__num_ =
|
|
196
|
-
be_(()=>1
|
|
163
|
+
be_(()=>1, { is_source_: ctx=>!!ctx.get('ctx1') })
|
|
197
164
|
is_source__num_(nested__ctx)
|
|
198
165
|
equal(ctx0.has(is_source__num_), false)
|
|
199
166
|
equal(ctx1.has(is_source__num_), true)
|
|
@@ -220,26 +187,26 @@ test('be__has_', ()=>{
|
|
|
220
187
|
ctx1.set('key', true)
|
|
221
188
|
equal(be__has_('key', nested__ctx), true)
|
|
222
189
|
})
|
|
223
|
-
test('
|
|
190
|
+
test('be__ctx_', ()=>{
|
|
224
191
|
const ctx0 = ctx__new()
|
|
225
192
|
ctx__delete(ctx0, 'key')
|
|
226
|
-
equal(
|
|
193
|
+
equal(be__ctx_('key', ctx0), undefined)
|
|
227
194
|
ctx0.set('key', true)
|
|
228
|
-
equal(
|
|
195
|
+
equal(be__ctx_('key', ctx0), ctx0)
|
|
229
196
|
ctx__delete(ctx0, 'key')
|
|
230
|
-
equal(
|
|
197
|
+
equal(be__ctx_('key', ctx0), undefined)
|
|
231
198
|
const ctx1 = ctx__new()
|
|
232
199
|
const nested__ctx = [ctx0, ctx1]
|
|
233
200
|
ctx1.set('key', true)
|
|
234
|
-
equal(
|
|
201
|
+
equal(be__ctx_('key', nested__ctx), ctx1)
|
|
235
202
|
})
|
|
236
203
|
test('be__val_', ()=>{
|
|
237
204
|
const ctx = ctx__new()
|
|
238
|
-
const val_ = be_<boolean>(()=>true
|
|
205
|
+
const val_ = be_<boolean>(()=>true, { id: 'val_' })
|
|
239
206
|
equal(val_(ctx), true)
|
|
240
207
|
equal(ctx.get(val_), true)
|
|
241
208
|
equal(be__val_(val_, ctx), true)
|
|
242
|
-
|
|
209
|
+
ctx__set(ctx, val_, false)
|
|
243
210
|
equal(val_(ctx), false)
|
|
244
211
|
equal(be__val_(val_, ctx), false)
|
|
245
212
|
})
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import type { Be,
|
|
2
|
-
import type { read_rmemo_T,
|
|
1
|
+
import type { Be, be__val__new_T, be_config_T, Ctx } from '../be_/index.js'
|
|
2
|
+
import type { read_rmemo_T, rmemo_def_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
|
+
>(be: Be<rmemo_T, ctx_T>):be_rmemo_pair_T<val_T, rmemo_T, ctx_T>
|
|
3
8
|
export declare function be_rmemo_pair_<
|
|
4
9
|
val_T,
|
|
5
10
|
rmemo_T extends read_rmemo_T<val_T> = read_rmemo_T<val_T>,
|
|
6
11
|
ctx_T extends Ctx = Ctx
|
|
7
12
|
>(
|
|
8
13
|
rmemo__new:be__val__new_T<val_T>,
|
|
9
|
-
|
|
14
|
+
...subscriber_a_THEN_config:
|
|
15
|
+
|[...rmemo_def_T<val_T>[]]
|
|
16
|
+
|[...rmemo_def_T<val_T>[], config:be_config_T]
|
|
10
17
|
):be_rmemo_pair_T<val_T, rmemo_T, ctx_T>
|
|
11
18
|
export type be_rmemo_pair_T<
|
|
12
19
|
val_T,
|
|
@@ -15,7 +22,4 @@ export type be_rmemo_pair_T<
|
|
|
15
22
|
> = [
|
|
16
23
|
Be<rmemo_T, ctx_T>,
|
|
17
24
|
(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
|
-
}
|
|
25
|
+
]
|
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import { be_ } from '../be_/index.js'
|
|
2
2
|
import { rmemo_ } from '../rmemo/index.js'
|
|
3
|
+
/** @typedef {import('../be_/index.d.ts').Be} */
|
|
3
4
|
/** @typedef {import('../be_/index.d.ts').be__val__new_T} */
|
|
5
|
+
/** @typedef {import('../be_/index.d.ts').be_config_T} */
|
|
4
6
|
/** @typedef {import('../rmemo/index.d.ts').rmemo_subscriber_T} */
|
|
5
7
|
/** @typedef {import('./index.d.ts').be_rmemo_pair_T} */
|
|
6
8
|
/**
|
|
7
|
-
* @param {be__val__new_T<unknown>}
|
|
8
|
-
* @param {rmemo_subscriber_T[]}
|
|
9
|
+
* @param {Be|be__val__new_T<unknown>}be_OR_val__new
|
|
10
|
+
* @param {rmemo_subscriber_T[]|[...rmemo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
|
|
9
11
|
* @returns {be_rmemo_pair_T}
|
|
10
12
|
* @private
|
|
11
13
|
*/
|
|
12
|
-
export function be_rmemo_pair_(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
export function be_rmemo_pair_(
|
|
15
|
+
be_OR_val__new,
|
|
16
|
+
...subscriber_a_THEN_config
|
|
17
|
+
) {
|
|
18
|
+
let config =
|
|
19
|
+
typeof subscriber_a_THEN_config[subscriber_a_THEN_config.length - 1] === 'object'
|
|
20
|
+
? subscriber_a_THEN_config.pop()
|
|
21
|
+
: undefined
|
|
22
|
+
/** @type {Be} */
|
|
23
|
+
let be =
|
|
24
|
+
be_OR_val__new.is_be
|
|
25
|
+
? be_OR_val__new
|
|
26
|
+
: be_(ctx=>
|
|
27
|
+
rmemo_(()=>be_OR_val__new(ctx), ...subscriber_a_THEN_config),
|
|
28
|
+
config)
|
|
29
|
+
return [
|
|
30
|
+
be,
|
|
31
|
+
ctx=>be(ctx)._,
|
|
32
|
+
(ctx, val)=>{
|
|
33
|
+
be(ctx)._ = val
|
|
34
|
+
},
|
|
21
35
|
]
|
|
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
36
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { test } from 'uvu'
|
|
2
2
|
import { equal } from 'uvu/assert'
|
|
3
|
+
import { be_ } from '../be_/index.js'
|
|
3
4
|
import { be_rsig_triple_ } from '../be_rsig_triple/index.js'
|
|
4
5
|
import { ctx__new } from '../ctx/index.js'
|
|
5
6
|
import type { read_rmemo_T, readwrite_rmemo_T } from '../rmemo/index.js'
|
|
7
|
+
import { rmemo_ } from '../rmemo/index.js'
|
|
6
8
|
import { be_rmemo_pair_ } from './index.js'
|
|
7
9
|
test('be_rmemo_pair_', ()=>{
|
|
8
10
|
const [
|
|
9
|
-
|
|
11
|
+
,
|
|
10
12
|
base_,
|
|
11
13
|
base__set,
|
|
12
14
|
] = be_rsig_triple_(()=>1)
|
|
@@ -25,27 +27,61 @@ test('be_rmemo_pair_|+id|+is_source_|+oninit|+subscriber_a', ()=>{
|
|
|
25
27
|
const ctx = ctx__new()
|
|
26
28
|
let subscriber_count = 0
|
|
27
29
|
const [
|
|
28
|
-
|
|
30
|
+
,
|
|
29
31
|
base_,
|
|
30
32
|
base__set,
|
|
31
|
-
] = be_rsig_triple_(()=>1
|
|
32
|
-
|
|
33
|
+
] = be_rsig_triple_(()=>1,
|
|
34
|
+
{ is_source_: map_ctx=>map_ctx === ctx })
|
|
33
35
|
const [
|
|
34
36
|
foobar$_,
|
|
35
37
|
foobar_,
|
|
36
|
-
] = be_rmemo_pair_
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
()=>subscriber_count++)
|
|
40
|
-
.config({
|
|
38
|
+
] = be_rmemo_pair_(ctx=>base_(ctx) + 1,
|
|
39
|
+
()=>subscriber_count++,
|
|
40
|
+
{
|
|
41
41
|
id: 'foobar',
|
|
42
42
|
is_source_: map_ctx=>map_ctx === ctx,
|
|
43
43
|
})
|
|
44
|
-
|
|
44
|
+
equal(subscriber_count, 0)
|
|
45
|
+
equal(foobar$_([ctx__new(), ctx])._, 2)
|
|
46
|
+
equal(foobar_([ctx__new(), ctx]), 2)
|
|
47
|
+
equal(foobar$_(ctx)._, 2)
|
|
48
|
+
equal(foobar_(ctx), 2)
|
|
49
|
+
equal((ctx.get('foobar') as read_rmemo_T<number>)._, 2)
|
|
50
|
+
equal(subscriber_count, 1)
|
|
51
|
+
base__set(ctx, 2)
|
|
52
|
+
equal(foobar$_([ctx__new(), ctx])._, 3)
|
|
53
|
+
equal(foobar_([ctx__new(), ctx]), 3)
|
|
54
|
+
equal(foobar$_(ctx)._, 3)
|
|
55
|
+
equal(foobar_(ctx), 3)
|
|
56
|
+
equal((ctx.get('foobar') as read_rmemo_T<number>)._, 3)
|
|
57
|
+
equal(subscriber_count, 1)
|
|
58
|
+
})
|
|
59
|
+
test('be_rmemo_pair_|be', ()=>{
|
|
60
|
+
const ctx = ctx__new()
|
|
61
|
+
let subscriber_count = 0
|
|
62
|
+
const [
|
|
63
|
+
,
|
|
64
|
+
base_,
|
|
65
|
+
base__set,
|
|
66
|
+
] = be_rsig_triple_(()=>1,
|
|
67
|
+
{ is_source_: map_ctx=>map_ctx === ctx })
|
|
68
|
+
const [
|
|
69
|
+
foobar$_,
|
|
70
|
+
foobar_,
|
|
71
|
+
] = be_rmemo_pair_<number, custom_rmemo_T>(
|
|
72
|
+
be_(_ctx=>{
|
|
73
|
+
const foobar$ = rmemo_(
|
|
74
|
+
()=>base_(ctx) + 1,
|
|
75
|
+
()=>subscriber_count++
|
|
76
|
+
) as custom_rmemo_T
|
|
45
77
|
if (Array.isArray(_ctx)) equal(_ctx[1], ctx)
|
|
46
78
|
else equal(_ctx, ctx)
|
|
47
79
|
foobar$.custom = 'custom-val'
|
|
48
|
-
|
|
80
|
+
return foobar$
|
|
81
|
+
}, {
|
|
82
|
+
id: 'foobar',
|
|
83
|
+
is_source_: map_ctx=>map_ctx === ctx,
|
|
84
|
+
}))
|
|
49
85
|
equal(subscriber_count, 0)
|
|
50
86
|
equal(foobar$_([ctx__new(), ctx])._, 2)
|
|
51
87
|
equal(foobar_([ctx__new(), ctx]), 2)
|
|
@@ -64,3 +100,4 @@ test('be_rmemo_pair_|+id|+is_source_|+oninit|+subscriber_a', ()=>{
|
|
|
64
100
|
equal(subscriber_count, 1)
|
|
65
101
|
})
|
|
66
102
|
test.run()
|
|
103
|
+
type custom_rmemo_T = readwrite_rmemo_T<number>&{ custom:string }
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import type { Be,
|
|
2
|
-
import type { readwrite_rmemo_T,
|
|
1
|
+
import type { Be, be__val__new_T, be_config_T, Ctx } from '../be_/index.js'
|
|
2
|
+
import type { readwrite_rmemo_T, rmemo_def_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
|
+
>(be: Be<rsig_T, ctx_T>):be_rsig_triple_T<val_T, rsig_T, ctx_T>
|
|
3
8
|
export declare function be_rsig_triple_<
|
|
4
9
|
val_T,
|
|
5
10
|
rsig_T extends readwrite_rmemo_T<val_T> = readwrite_rmemo_T<val_T>,
|
|
6
11
|
ctx_T extends Ctx = Ctx
|
|
7
12
|
>(
|
|
8
13
|
rmemo__new:be__val__new_T<val_T>,
|
|
9
|
-
...
|
|
14
|
+
...subscriber_a_THEN_config:
|
|
15
|
+
|[...rmemo_def_T<val_T>[]]
|
|
16
|
+
|[...rmemo_def_T<val_T>[], config:be_config_T]
|
|
10
17
|
):be_rsig_triple_T<val_T, rsig_T, ctx_T>
|
|
11
18
|
export type be_rsig_triple_T<
|
|
12
19
|
val_T,
|
|
@@ -16,7 +23,4 @@ export type be_rsig_triple_T<
|
|
|
16
23
|
Be<rsig_T>,
|
|
17
24
|
(ctx:ctx_T)=>val_T,
|
|
18
25
|
(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
|
-
}
|
|
26
|
+
]
|
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
import { be_ } from '../be_/index.js'
|
|
2
2
|
import { rsig_ } from '../rmemo/index.js'
|
|
3
|
+
/** @typedef {import('../be_/index.d.ts').Be} */
|
|
3
4
|
/** @typedef {import('../be_/index.d.ts').be__val__new_T} */
|
|
5
|
+
/** @typedef {import('../be_/index.d.ts').be_config_T} */
|
|
6
|
+
/** @typedef {import('../rmemo/index.d.ts').rsig_T} */
|
|
4
7
|
/** @typedef {import('../rmemo/index.d.ts').rmemo_subscriber_T} */
|
|
5
8
|
/** @typedef {import('./index.d.ts').be_rsig_triple_T} */
|
|
6
9
|
/**
|
|
7
|
-
* @param {be__val__new_T<unknown>}
|
|
8
|
-
* @param {rmemo_subscriber_T[]}
|
|
10
|
+
* @param {Be<rsig_T>|be__val__new_T<unknown>}be_OR_val__new
|
|
11
|
+
* @param {rmemo_subscriber_T[]|[...rmemo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
|
|
9
12
|
* @returns {be_rsig_triple_T}
|
|
10
13
|
* @private
|
|
11
14
|
*/
|
|
12
|
-
export function be_rsig_triple_(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
export function be_rsig_triple_(
|
|
16
|
+
be_OR_val__new,
|
|
17
|
+
...subscriber_a_THEN_config
|
|
18
|
+
) {
|
|
19
|
+
let config =
|
|
20
|
+
typeof subscriber_a_THEN_config[subscriber_a_THEN_config.length - 1] === 'object'
|
|
21
|
+
? subscriber_a_THEN_config.pop()
|
|
22
|
+
: undefined
|
|
23
|
+
/** @type {Be<rsig_T>} */
|
|
24
|
+
let be =
|
|
25
|
+
be_OR_val__new.is_be
|
|
26
|
+
? be_OR_val__new
|
|
27
|
+
: be_(ctx=>rsig_(be_OR_val__new(ctx), ...subscriber_a_THEN_config),
|
|
28
|
+
config)
|
|
29
|
+
return [
|
|
30
|
+
be,
|
|
31
|
+
ctx=>be(ctx)._,
|
|
21
32
|
(ctx, val)=>{
|
|
22
|
-
|
|
33
|
+
be(ctx)._ = val
|
|
23
34
|
},
|
|
24
35
|
]
|
|
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
36
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { test } from 'uvu'
|
|
2
2
|
import { equal } from 'uvu/assert'
|
|
3
|
+
import { be_ } from '../be_/index.js'
|
|
3
4
|
import { ctx__new } from '../ctx/index.js'
|
|
4
|
-
import { type readwrite_rmemo_T } from '../rmemo/index.js'
|
|
5
|
+
import { type readwrite_rmemo_T, rsig_ } from '../rmemo/index.js'
|
|
5
6
|
import { be_rsig_triple_ } from './index.js'
|
|
6
7
|
test('be_rsig_triple_', ()=>{
|
|
7
8
|
const [
|
|
@@ -16,22 +17,46 @@ test('be_rsig_triple_', ()=>{
|
|
|
16
17
|
equal(foobar$_(ctx)._, 2)
|
|
17
18
|
equal(foobar_(ctx), 2)
|
|
18
19
|
})
|
|
19
|
-
test('be_rsig_triple_|+id|+is_source_
|
|
20
|
+
test('be_rsig_triple_|+id|+is_source_', ()=>{
|
|
20
21
|
const ctx = ctx__new()
|
|
21
22
|
let subscriber_count = 0
|
|
22
23
|
const [
|
|
23
24
|
foobar$_,
|
|
24
25
|
foobar_,
|
|
25
26
|
foobar__set,
|
|
26
|
-
] = be_rsig_triple_
|
|
27
|
+
] = be_rsig_triple_(
|
|
27
28
|
()=>1,
|
|
28
|
-
()=>subscriber_count
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
()=>subscriber_count++,
|
|
30
|
+
{ id: 'foobar', is_source_: map_ctx=>map_ctx === ctx },)
|
|
31
|
+
equal(subscriber_count, 0)
|
|
32
|
+
equal(foobar$_([ctx__new(), ctx])._, 1)
|
|
33
|
+
equal(foobar_([ctx__new(), ctx]), 1)
|
|
34
|
+
equal(foobar$_(ctx)._, 1)
|
|
35
|
+
equal(foobar_(ctx), 1)
|
|
36
|
+
equal(subscriber_count, 1)
|
|
37
|
+
equal((ctx.get('foobar') as readwrite_rmemo_T<number>)._, 1)
|
|
38
|
+
foobar__set([ctx__new(), ctx], 2)
|
|
39
|
+
equal(foobar$_([ctx__new(), ctx])._, 2)
|
|
40
|
+
equal(foobar_([ctx__new(), ctx]), 2)
|
|
41
|
+
equal(foobar$_(ctx)._, 2)
|
|
42
|
+
equal(foobar_(ctx), 2)
|
|
43
|
+
equal((ctx.get('foobar') as readwrite_rmemo_T<number>)._, 2)
|
|
44
|
+
equal(subscriber_count, 1)
|
|
45
|
+
})
|
|
46
|
+
test('be_rsig_triple_|+be', ()=>{
|
|
47
|
+
const ctx = ctx__new()
|
|
48
|
+
let subscriber_count = 0
|
|
49
|
+
const [
|
|
50
|
+
foobar$_,
|
|
51
|
+
foobar_,
|
|
52
|
+
foobar__set,
|
|
53
|
+
] = be_rsig_triple_<number, custom_rsig_T>(
|
|
54
|
+
be_(()=>{
|
|
55
|
+
const foobar$ =
|
|
56
|
+
rsig_(1, ()=>subscriber_count++) as custom_rsig_T
|
|
33
57
|
foobar$.custom = 'custom-val'
|
|
34
|
-
|
|
58
|
+
return foobar$
|
|
59
|
+
}, { id: 'foobar', is_source_: map_ctx=>map_ctx === ctx }))
|
|
35
60
|
equal(subscriber_count, 0)
|
|
36
61
|
equal(foobar$_([ctx__new(), ctx])._, 1)
|
|
37
62
|
equal(foobar_([ctx__new(), ctx]), 1)
|
|
@@ -50,3 +75,4 @@ test('be_rsig_triple_|+id|+is_source_|+oninit', ()=>{
|
|
|
50
75
|
equal(subscriber_count, 1)
|
|
51
76
|
})
|
|
52
77
|
test.run()
|
|
78
|
+
type custom_rsig_T = readwrite_rmemo_T<number>&{ custom:string }
|
package/all/ctx/index.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* @private
|
|
4
4
|
*/
|
|
5
5
|
export function ctx__new() {
|
|
6
|
-
|
|
6
|
+
let ctx = new Map
|
|
7
|
+
ctx.is_ctx = true
|
|
8
|
+
return ctx
|
|
7
9
|
}
|
|
8
10
|
export { ctx__new as ctx_ }
|
|
9
11
|
/**
|
|
@@ -12,11 +14,8 @@ export { ctx__new as ctx_ }
|
|
|
12
14
|
* @private
|
|
13
15
|
*/
|
|
14
16
|
export function is_ctx_(val) {
|
|
15
|
-
if (!Array.isArray(val)) return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!is_ctx_(flat__val[i])) return false
|
|
20
|
-
}
|
|
21
|
-
return true
|
|
17
|
+
if (!Array.isArray(val)) return val instanceof Map && !!val.is_ctx
|
|
18
|
+
let flat__map_ctx_a = val.flat(Infinity)
|
|
19
|
+
if (!flat__map_ctx_a[0]) return false
|
|
20
|
+
return flat__map_ctx_a.every(map_ctx=>map_ctx.is_ctx)
|
|
22
21
|
}
|
package/all/ctx/index.test.ts
CHANGED
package/all/index.d.ts
CHANGED
|
@@ -307,8 +307,6 @@ export * from './rad_deg/index.js'
|
|
|
307
307
|
export * from './random_idx/index.js'
|
|
308
308
|
export * from './rank/index.js'
|
|
309
309
|
export * from './rate_limit/index.js'
|
|
310
|
-
export * from './rc_be/index.js'
|
|
311
|
-
export * from './rc_be_/index.js'
|
|
312
310
|
export * from './reduce/index.js'
|
|
313
311
|
export * from './reject/index.js'
|
|
314
312
|
export * from './remove/index.js'
|
package/all/index.js
CHANGED
|
@@ -307,8 +307,6 @@ export * from './rad_deg/index.js'
|
|
|
307
307
|
export * from './random_idx/index.js'
|
|
308
308
|
export * from './rank/index.js'
|
|
309
309
|
export * from './rate_limit/index.js'
|
|
310
|
-
export * from './rc_be/index.js'
|
|
311
|
-
export * from './rc_be_/index.js'
|
|
312
310
|
export * from './reduce/index.js'
|
|
313
311
|
export * from './reject/index.js'
|
|
314
312
|
export * from './remove/index.js'
|
package/all/rmemo/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** @typedef {import('./index.d.ts').rmemo_T} */
|
|
2
2
|
/** @typedef {import('./index.d.ts').rmemo_subscriber_T} */
|
|
3
|
-
/** @type {(()=>unknown)[]} */
|
|
4
|
-
let queue = []
|
|
5
3
|
/** @type {WeakRef<rmemo_T>} */
|
|
6
4
|
let cur_ref
|
|
5
|
+
/** @type {(()=>unknown)[]} */
|
|
6
|
+
let queue = []
|
|
7
7
|
/**
|
|
8
8
|
* @param {(rmemo:rmemo_T<unknown>)=>unknown}_f
|
|
9
9
|
* @param {rmemo_subscriber_T<unknown>[]}subscriber_a
|
|
@@ -21,7 +21,6 @@ export function rmemo_(_f, ...subscriber_a) {
|
|
|
21
21
|
rmemo._rS = new Set
|
|
22
22
|
rmemo.go = ()=>(rmemo(), rmemo)
|
|
23
23
|
rmemo.onset = ()=>0
|
|
24
|
-
let c = 0
|
|
25
24
|
Object.defineProperty(rmemo, '_', {
|
|
26
25
|
get() {
|
|
27
26
|
if (!_a.length) {
|
|
@@ -44,7 +43,6 @@ export function rmemo_(_f, ...subscriber_a) {
|
|
|
44
43
|
if (!_a.length || val !== _a[0]) {
|
|
45
44
|
rmemo.refresh(val)
|
|
46
45
|
}
|
|
47
|
-
return val
|
|
48
46
|
}
|
|
49
47
|
})
|
|
50
48
|
rmemo.refresh = val=>{
|
|
@@ -60,6 +58,7 @@ export function rmemo_(_f, ...subscriber_a) {
|
|
|
60
58
|
rmemo_(()=>subscriber(rmemo)).go())
|
|
61
59
|
}
|
|
62
60
|
if (run_queue) {
|
|
61
|
+
// eslint-disable-next-line no-cond-assign
|
|
63
62
|
for (let ref; ref = queue.shift();) {
|
|
64
63
|
if (queue.some(_ref=>ref.l > _ref.l)) {
|
|
65
64
|
queue.push(ref)
|
|
@@ -79,8 +78,7 @@ export function rmemo_(_f, ...subscriber_a) {
|
|
|
79
78
|
* @private
|
|
80
79
|
*/
|
|
81
80
|
export function rsig_(init_val, ...subscriber_a) {
|
|
82
|
-
let rsig =
|
|
83
|
-
rmemo_(signal$=>signal$._v, ...subscriber_a)
|
|
81
|
+
let rsig = rmemo_(_rsig=>_rsig._v, ...subscriber_a)
|
|
84
82
|
rsig.onset = val=>rsig._v = val
|
|
85
83
|
rsig._v = init_val
|
|
86
84
|
return rsig
|
package/object/index.d.ts
CHANGED
|
@@ -39,8 +39,6 @@ export * from '../all/pick/index.js'
|
|
|
39
39
|
export * from '../all/pick_keys/index.js'
|
|
40
40
|
export * from '../all/pick_val_a/index.js'
|
|
41
41
|
export * from '../all/prototype/index.js'
|
|
42
|
-
export * from '../all/rc_be/index.js'
|
|
43
|
-
export * from '../all/rc_be_/index.js'
|
|
44
42
|
export * from '../all/toString/index.js'
|
|
45
43
|
export * from '../all/unpick/index.js'
|
|
46
44
|
export * from '../all/unpick_keys/index.js'
|
package/object/index.js
CHANGED
|
@@ -38,8 +38,6 @@ export * from '../all/pick/index.js'
|
|
|
38
38
|
export * from '../all/pick_keys/index.js'
|
|
39
39
|
export * from '../all/pick_val_a/index.js'
|
|
40
40
|
export * from '../all/prototype/index.js'
|
|
41
|
-
export * from '../all/rc_be/index.js'
|
|
42
|
-
export * from '../all/rc_be_/index.js'
|
|
43
41
|
export * from '../all/toString/index.js'
|
|
44
42
|
export * from '../all/unpick/index.js'
|
|
45
43
|
export * from '../all/unpick_keys/index.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -124,33 +124,54 @@
|
|
|
124
124
|
},
|
|
125
125
|
"sideEffects": false,
|
|
126
126
|
"size-limit": [
|
|
127
|
+
{
|
|
128
|
+
"name": "ctx_",
|
|
129
|
+
"import": {
|
|
130
|
+
"./be": "{ ctx_ }"
|
|
131
|
+
},
|
|
132
|
+
"limit": "34 B"
|
|
133
|
+
},
|
|
127
134
|
{
|
|
128
135
|
"name": "be_",
|
|
129
136
|
"import": {
|
|
130
137
|
"./be": "{ be_ }"
|
|
131
138
|
},
|
|
132
|
-
"limit": "
|
|
139
|
+
"limit": "162 B"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"name": "be_ ctx_",
|
|
143
|
+
"import": {
|
|
144
|
+
"./be": "{ be_, ctx_ }"
|
|
145
|
+
},
|
|
146
|
+
"limit": "187 B"
|
|
133
147
|
},
|
|
134
148
|
{
|
|
135
149
|
"name": "rmemo_",
|
|
136
150
|
"import": {
|
|
137
151
|
"./rmemo": "{ rmemo_ }"
|
|
138
152
|
},
|
|
139
|
-
"limit": "
|
|
153
|
+
"limit": "344 B"
|
|
140
154
|
},
|
|
141
155
|
{
|
|
142
156
|
"name": "rmemo_ signal_",
|
|
143
157
|
"import": {
|
|
144
158
|
"./rmemo": "{ rsig_, rmemo_ }"
|
|
145
159
|
},
|
|
146
|
-
"limit": "
|
|
160
|
+
"limit": "372 B"
|
|
147
161
|
},
|
|
148
162
|
{
|
|
149
163
|
"name": "rmemo_ signal_ be_ ctx_",
|
|
150
164
|
"import": {
|
|
151
165
|
"./rmemo": "{ rsig_, rmemo_, be_, ctx_ }"
|
|
152
166
|
},
|
|
153
|
-
"limit": "
|
|
167
|
+
"limit": "532 B"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"name": "rmemo_ signal_ be_ ctx_ be_rmemo_pair_ be_rsig_triple_",
|
|
171
|
+
"import": {
|
|
172
|
+
"./rmemo": "{ rsig_, rmemo_, be_, ctx_, be_rmemo_pair_, be_rsig_triple_ }"
|
|
173
|
+
},
|
|
174
|
+
"limit": "613 B"
|
|
154
175
|
}
|
|
155
176
|
],
|
|
156
177
|
"scripts": {
|
package/all/be_/debug.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { be_ } from './index.js'
|
|
2
|
-
export function be__debug() {
|
|
3
|
-
be_.argv__debug = argv__ctx=>{
|
|
4
|
-
if (!argv__ctx) {
|
|
5
|
-
throw new Error(`be: no Ctx`)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
be_.source__debug = ctx=>{
|
|
9
|
-
if (!ctx) {
|
|
10
|
-
throw new Error(
|
|
11
|
-
`be: ${String(id)}: no is_source_ returns true`)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
be_.pending__debug = pending=>{
|
|
15
|
-
if (pending.get(be)) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
`be_: ${
|
|
18
|
-
String(id)
|
|
19
|
-
}: circular:\n${pending.values().map(pending_value=>
|
|
20
|
-
typeof pending_value === 'string'
|
|
21
|
-
? pending_value
|
|
22
|
-
: 'Function').join('\n')}`)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
package/all/rc_be/index.d.ts
DELETED
package/all/rc_be/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { rc_be_ } from '../rc_be_/index.js'
|
|
2
|
-
/** @typedef {import('../be_/index.d.ts').Ctx} */
|
|
3
|
-
/** @typedef {import('../rc_be_/index.d.ts').rc_be__val__new_T} */
|
|
4
|
-
/**
|
|
5
|
-
* @param {Ctx}ctx
|
|
6
|
-
* @param {rc_be__val__new_T<NonNullable<unknown>>}key_or_val
|
|
7
|
-
* @returns {NonNullable<unknown>}
|
|
8
|
-
*/
|
|
9
|
-
export function rc_be(
|
|
10
|
-
ctx,
|
|
11
|
-
val__new
|
|
12
|
-
) {
|
|
13
|
-
return rc_be_(val__new)(ctx)
|
|
14
|
-
}
|
|
15
|
-
export { rc_be as rc_b, }
|
package/all/rc_be_/index.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Be, be__val__new_T, be_params_T, Ctx } from '../be_/index.js'
|
|
2
|
-
export declare const be_m_set_key:unique symbol
|
|
3
|
-
/**
|
|
4
|
-
* Returns _be with referencing counting.
|
|
5
|
-
* When all unsubscribes have been called, the ctx[key] is deleted.
|
|
6
|
-
*/
|
|
7
|
-
export declare function rc_be_<
|
|
8
|
-
Out extends NonNullable<unknown>
|
|
9
|
-
>(val__new:rc_be__val__new_T<Out>):rc_be__return_T<Out>
|
|
10
|
-
export declare type rc_be__return_T<
|
|
11
|
-
Out extends NonNullable<unknown>
|
|
12
|
-
> = (ctx:Ctx, params?:rc_be_params_T)=>RcBe_return_T<Out>
|
|
13
|
-
export {
|
|
14
|
-
rc_be_ as _rc_be,
|
|
15
|
-
rc_be_ as _rc_b,
|
|
16
|
-
}
|
|
17
|
-
export declare type be_m_set_T<
|
|
18
|
-
Out extends NonNullable<unknown>
|
|
19
|
-
> = Map<Be<Out>, Set<any>>
|
|
20
|
-
export declare type val_this_on_destroy_T = (...destroy_a:rc_be_destroy_T[])=>void
|
|
21
|
-
export interface val_this_T {
|
|
22
|
-
on_destroy:val_this_on_destroy_T
|
|
23
|
-
onDestroy:val_this_on_destroy_T
|
|
24
|
-
}
|
|
25
|
-
export interface rc_be_params_T extends be_params_T {
|
|
26
|
-
owner?:object
|
|
27
|
-
}
|
|
28
|
-
export declare type rc_be__val__new_T<
|
|
29
|
-
Out extends NonNullable<unknown>
|
|
30
|
-
> = be__val__new_T<Out>&((this:val_this_T, ctx:Ctx, key:Be<Out>, opts?:rc_be_params_T)=>Out)
|
|
31
|
-
export declare type rc_be_destroy_T = ()=>void
|
|
32
|
-
export interface RcBe_return_T<Out extends unknown = unknown> {
|
|
33
|
-
value:Out
|
|
34
|
-
destroy:rc_be_destroy_T
|
|
35
|
-
}
|
|
36
|
-
export declare type RcBe<
|
|
37
|
-
Out extends NonNullable<unknown>
|
|
38
|
-
> = (ctx:Ctx, opts?:be_params_T)=>RcBe_return_T<Out>
|
|
39
|
-
export declare type RcB<Out extends NonNullable<unknown>> = RcBe<Out>
|
package/all/rc_be_/index.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { be_ } from '../be_/index.js'
|
|
2
|
-
/** @typedef {import('../rc_be_/index.d.ts').rc_be__val__new_T} */
|
|
3
|
-
export const be_m_set_key = Symbol('be_m_set')
|
|
4
|
-
/**
|
|
5
|
-
* @param {rc_be__val__new_T}val__new
|
|
6
|
-
* @returns {import('./index.d.ts').rc_be__return_T}
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
export function rc_be_(val__new) {
|
|
10
|
-
return (ctx1, opts1)=>{
|
|
11
|
-
const ctx_any = ctx1
|
|
12
|
-
const destroy_cb_a = []
|
|
13
|
-
const val_this = {
|
|
14
|
-
on_destroy,
|
|
15
|
-
onDestroy: on_destroy
|
|
16
|
-
}
|
|
17
|
-
/** @type {rc_be__val__new_T} */
|
|
18
|
-
const val__new = val__new ? val__new : key_or_val_
|
|
19
|
-
const be1 = be_(val__new)
|
|
20
|
-
let be_m_set = ctx_any[be_m_set_key]
|
|
21
|
-
if (!be_m_set) {
|
|
22
|
-
be_m_set = new Map()
|
|
23
|
-
ctx_any[be_m_set_key] = be_m_set
|
|
24
|
-
}
|
|
25
|
-
let rc_set = be_m_set.get(be1)
|
|
26
|
-
if (!rc_set) {
|
|
27
|
-
rc_set = new Set()
|
|
28
|
-
be_m_set.set(be1, rc_set)
|
|
29
|
-
}
|
|
30
|
-
const owner = (opts1 === null || opts1 === void 0 ? void 0 : opts1.owner) || {}
|
|
31
|
-
rc_set.add(owner)
|
|
32
|
-
let destroy = ()=>{
|
|
33
|
-
rc_set.delete(owner)
|
|
34
|
-
if (!rc_set.size) {
|
|
35
|
-
for (const destroy_cb of destroy_cb_a) {
|
|
36
|
-
destroy_cb()
|
|
37
|
-
}
|
|
38
|
-
ctx1.delete(be1)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
value: be1(ctx1, opts1),
|
|
43
|
-
destroy
|
|
44
|
-
}
|
|
45
|
-
function on_destroy(...in_destroy_cb_a) {
|
|
46
|
-
destroy_cb_a.push(...in_destroy_cb_a)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
rc_be_ as _rc_be,
|
|
52
|
-
rc_be_ as _rc_b,
|
|
53
|
-
}
|