ctx-core 3.3.3 → 4.1.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 +34 -78
- package/all/be_/index.js +53 -136
- package/all/be_/index.test.ts +29 -63
- package/all/be_rmemo_pair/index.d.ts +23 -0
- package/all/be_rmemo_pair/index.js +36 -0
- package/all/be_rmemo_pair/index.test.ts +103 -0
- package/all/be_rsig_triple/index.d.ts +24 -0
- package/all/be_rsig_triple/index.js +36 -0
- package/all/be_rsig_triple/index.test.ts +78 -0
- package/all/call_assign/index.js +1 -1
- package/all/compose/index.js +1 -1
- package/all/ctx/index.js +7 -8
- package/all/ctx/index.test.ts +1 -0
- 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 -5
- package/all/index.js +3 -5
- 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/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 +27 -29
- 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 -4
- package/object/index.js +0 -4
- package/package.json +28 -7
- package/rmemo/index.d.ts +2 -0
- package/rmemo/index.js +2 -0
- package/all/be_/debug.js +0 -25
- 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/all/rc_be/index.d.ts +0 -9
- package/all/rc_be/index.js +0 -17
- package/all/rc_be_/index.d.ts +0 -42
- package/all/rc_be_/index.js +0 -62
- package/be/index.test.ts +0 -251
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_(
|
|
21
|
-
const child_ = be_(
|
|
22
|
-
const child1_ = be_(
|
|
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_('root_'
|
|
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_(
|
|
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_('root_'
|
|
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_(
|
|
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)
|
|
@@ -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
73
|
}, {
|
|
74
|
-
is_source_(
|
|
75
|
-
|
|
76
|
-
}
|
|
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, { id: 'val_' })
|
|
86
85
|
val_(valid_ctx)
|
|
87
86
|
// val_(ctx_()) // type error
|
|
88
87
|
})
|
|
@@ -91,22 +90,15 @@ 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], { id: 'nested__ctx_' })
|
|
95
94
|
equal(nested__ctx_(ctx), [[ctx0, ctx1]])
|
|
96
95
|
})
|
|
97
|
-
test('
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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>('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
114
|
test('ctx__delete|id', ()=>{
|
|
148
115
|
const ctx0 = ctx__new()
|
|
149
116
|
ctx__delete(ctx0, 'key')
|
|
@@ -193,8 +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,
|
|
197
|
-
{ is_source_: ctx=>!!ctx.get('ctx1') })
|
|
163
|
+
be_(()=>1, { is_source_: ctx=>!!ctx.get('ctx1') })
|
|
198
164
|
is_source__num_(nested__ctx)
|
|
199
165
|
equal(ctx0.has(is_source__num_), false)
|
|
200
166
|
equal(ctx1.has(is_source__num_), true)
|
|
@@ -221,26 +187,26 @@ test('be__has_', ()=>{
|
|
|
221
187
|
ctx1.set('key', true)
|
|
222
188
|
equal(be__has_('key', nested__ctx), true)
|
|
223
189
|
})
|
|
224
|
-
test('
|
|
190
|
+
test('be__ctx_', ()=>{
|
|
225
191
|
const ctx0 = ctx__new()
|
|
226
192
|
ctx__delete(ctx0, 'key')
|
|
227
|
-
equal(
|
|
193
|
+
equal(be__ctx_('key', ctx0), undefined)
|
|
228
194
|
ctx0.set('key', true)
|
|
229
|
-
equal(
|
|
195
|
+
equal(be__ctx_('key', ctx0), ctx0)
|
|
230
196
|
ctx__delete(ctx0, 'key')
|
|
231
|
-
equal(
|
|
197
|
+
equal(be__ctx_('key', ctx0), undefined)
|
|
232
198
|
const ctx1 = ctx__new()
|
|
233
199
|
const nested__ctx = [ctx0, ctx1]
|
|
234
200
|
ctx1.set('key', true)
|
|
235
|
-
equal(
|
|
201
|
+
equal(be__ctx_('key', nested__ctx), ctx1)
|
|
236
202
|
})
|
|
237
203
|
test('be__val_', ()=>{
|
|
238
204
|
const ctx = ctx__new()
|
|
239
|
-
const val_ = be_<boolean>('val_'
|
|
205
|
+
const val_ = be_<boolean>(()=>true, { id: 'val_' })
|
|
240
206
|
equal(val_(ctx), true)
|
|
241
207
|
equal(ctx.get(val_), true)
|
|
242
208
|
equal(be__val_(val_, ctx), true)
|
|
243
|
-
|
|
209
|
+
ctx__set(ctx, val_, false)
|
|
244
210
|
equal(val_(ctx), false)
|
|
245
211
|
equal(be__val_(val_, ctx), false)
|
|
246
212
|
})
|
|
@@ -0,0 +1,23 @@
|
|
|
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>
|
|
8
|
+
export declare function be_rmemo_pair_<
|
|
9
|
+
val_T,
|
|
10
|
+
rmemo_T extends read_rmemo_T<val_T> = read_rmemo_T<val_T>,
|
|
11
|
+
ctx_T extends Ctx = Ctx
|
|
12
|
+
>(
|
|
13
|
+
rmemo__new:be__val__new_T<val_T>,
|
|
14
|
+
...subscriber_a_THEN_config:[...rmemo_def_T<val_T>[], config?:be_config_T]
|
|
15
|
+
):be_rmemo_pair_T<val_T, rmemo_T, ctx_T>
|
|
16
|
+
export type be_rmemo_pair_T<
|
|
17
|
+
val_T,
|
|
18
|
+
rmemo_T extends read_rmemo_T<val_T> = read_rmemo_T<val_T>,
|
|
19
|
+
ctx_T extends Ctx = Ctx
|
|
20
|
+
> = [
|
|
21
|
+
Be<rmemo_T, ctx_T>,
|
|
22
|
+
(ctx:ctx_T)=>val_T
|
|
23
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { be_ } from '../be_/index.js'
|
|
2
|
+
import { rmemo_ } from '../rmemo/index.js'
|
|
3
|
+
/** @typedef {import('../be_/index.d.ts').Be} */
|
|
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').rmemo_subscriber_T} */
|
|
7
|
+
/** @typedef {import('./index.d.ts').be_rmemo_pair_T} */
|
|
8
|
+
/**
|
|
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
|
|
11
|
+
* @returns {be_rmemo_pair_T}
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
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
|
+
},
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { be_ } from '../be_/index.js'
|
|
4
|
+
import { be_rsig_triple_ } from '../be_rsig_triple/index.js'
|
|
5
|
+
import { ctx__new } from '../ctx/index.js'
|
|
6
|
+
import type { read_rmemo_T, readwrite_rmemo_T } from '../rmemo/index.js'
|
|
7
|
+
import { rmemo_ } from '../rmemo/index.js'
|
|
8
|
+
import { be_rmemo_pair_ } from './index.js'
|
|
9
|
+
test('be_rmemo_pair_', ()=>{
|
|
10
|
+
const [
|
|
11
|
+
,
|
|
12
|
+
base_,
|
|
13
|
+
base__set,
|
|
14
|
+
] = be_rsig_triple_(()=>1)
|
|
15
|
+
const [
|
|
16
|
+
foobar$_,
|
|
17
|
+
foobar_,
|
|
18
|
+
] = be_rmemo_pair_(ctx=>base_(ctx) + 1)
|
|
19
|
+
const ctx = ctx__new()
|
|
20
|
+
equal(foobar$_(ctx)._, 2)
|
|
21
|
+
equal(foobar_(ctx), 2)
|
|
22
|
+
base__set(ctx, 2)
|
|
23
|
+
equal(foobar$_(ctx)._, 3)
|
|
24
|
+
equal(foobar_(ctx), 3)
|
|
25
|
+
})
|
|
26
|
+
test('be_rmemo_pair_|+id|+is_source_|+oninit|+subscriber_a', ()=>{
|
|
27
|
+
const ctx = ctx__new()
|
|
28
|
+
let subscriber_count = 0
|
|
29
|
+
const [
|
|
30
|
+
,
|
|
31
|
+
base_,
|
|
32
|
+
base__set,
|
|
33
|
+
] = be_rsig_triple_(()=>1,
|
|
34
|
+
{ is_source_: map_ctx=>map_ctx === ctx })
|
|
35
|
+
const [
|
|
36
|
+
foobar$_,
|
|
37
|
+
foobar_,
|
|
38
|
+
] = be_rmemo_pair_(ctx=>base_(ctx) + 1,
|
|
39
|
+
()=>subscriber_count++,
|
|
40
|
+
{
|
|
41
|
+
id: 'foobar',
|
|
42
|
+
is_source_: map_ctx=>map_ctx === ctx,
|
|
43
|
+
})
|
|
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
|
|
77
|
+
if (Array.isArray(_ctx)) equal(_ctx[1], ctx)
|
|
78
|
+
else equal(_ctx, ctx)
|
|
79
|
+
foobar$.custom = 'custom-val'
|
|
80
|
+
return foobar$
|
|
81
|
+
}, {
|
|
82
|
+
id: 'foobar',
|
|
83
|
+
is_source_: map_ctx=>map_ctx === ctx,
|
|
84
|
+
}))
|
|
85
|
+
equal(subscriber_count, 0)
|
|
86
|
+
equal(foobar$_([ctx__new(), ctx])._, 2)
|
|
87
|
+
equal(foobar_([ctx__new(), ctx]), 2)
|
|
88
|
+
equal(foobar$_(ctx)._, 2)
|
|
89
|
+
equal(foobar_(ctx), 2)
|
|
90
|
+
equal((ctx.get('foobar') as read_rmemo_T<number>)._, 2)
|
|
91
|
+
equal(foobar$_(ctx).custom, 'custom-val')
|
|
92
|
+
equal(subscriber_count, 1)
|
|
93
|
+
base__set(ctx, 2)
|
|
94
|
+
equal(foobar$_([ctx__new(), ctx])._, 3)
|
|
95
|
+
equal(foobar_([ctx__new(), ctx]), 3)
|
|
96
|
+
equal(foobar$_(ctx)._, 3)
|
|
97
|
+
equal(foobar_(ctx), 3)
|
|
98
|
+
equal((ctx.get('foobar') as read_rmemo_T<number>)._, 3)
|
|
99
|
+
equal(foobar$_(ctx).custom, 'custom-val')
|
|
100
|
+
equal(subscriber_count, 1)
|
|
101
|
+
})
|
|
102
|
+
test.run()
|
|
103
|
+
type custom_rmemo_T = readwrite_rmemo_T<number>&{ custom:string }
|
|
@@ -0,0 +1,24 @@
|
|
|
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>
|
|
8
|
+
export declare function be_rsig_triple_<
|
|
9
|
+
val_T,
|
|
10
|
+
rsig_T extends readwrite_rmemo_T<val_T> = readwrite_rmemo_T<val_T>,
|
|
11
|
+
ctx_T extends Ctx = Ctx
|
|
12
|
+
>(
|
|
13
|
+
rmemo__new:be__val__new_T<val_T>,
|
|
14
|
+
...subscriber_a_THEN_config:[...rmemo_def_T<val_T>[], config?:be_config_T]
|
|
15
|
+
):be_rsig_triple_T<val_T, rsig_T, ctx_T>
|
|
16
|
+
export type be_rsig_triple_T<
|
|
17
|
+
val_T,
|
|
18
|
+
rsig_T extends readwrite_rmemo_T<val_T> = readwrite_rmemo_T<val_T>,
|
|
19
|
+
ctx_T extends Ctx = Ctx
|
|
20
|
+
> = [
|
|
21
|
+
Be<rsig_T>,
|
|
22
|
+
(ctx:ctx_T)=>val_T,
|
|
23
|
+
(ctx:ctx_T, val:val_T)=>void
|
|
24
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { be_ } from '../be_/index.js'
|
|
2
|
+
import { rsig_ } from '../rmemo/index.js'
|
|
3
|
+
/** @typedef {import('../be_/index.d.ts').Be} */
|
|
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} */
|
|
7
|
+
/** @typedef {import('../rmemo/index.d.ts').rmemo_subscriber_T} */
|
|
8
|
+
/** @typedef {import('./index.d.ts').be_rsig_triple_T} */
|
|
9
|
+
/**
|
|
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
|
|
12
|
+
* @returns {be_rsig_triple_T}
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
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)._,
|
|
32
|
+
(ctx, val)=>{
|
|
33
|
+
be(ctx)._ = val
|
|
34
|
+
},
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { test } from 'uvu'
|
|
2
|
+
import { equal } from 'uvu/assert'
|
|
3
|
+
import { be_ } from '../be_/index.js'
|
|
4
|
+
import { ctx__new } from '../ctx/index.js'
|
|
5
|
+
import { type readwrite_rmemo_T, rsig_ } from '../rmemo/index.js'
|
|
6
|
+
import { be_rsig_triple_ } from './index.js'
|
|
7
|
+
test('be_rsig_triple_', ()=>{
|
|
8
|
+
const [
|
|
9
|
+
foobar$_,
|
|
10
|
+
foobar_,
|
|
11
|
+
foobar__set,
|
|
12
|
+
] = be_rsig_triple_(()=>1)
|
|
13
|
+
const ctx = ctx__new()
|
|
14
|
+
equal(foobar$_(ctx)._, 1)
|
|
15
|
+
equal(foobar_(ctx), 1)
|
|
16
|
+
foobar__set(ctx, 2)
|
|
17
|
+
equal(foobar$_(ctx)._, 2)
|
|
18
|
+
equal(foobar_(ctx), 2)
|
|
19
|
+
})
|
|
20
|
+
test('be_rsig_triple_|+id|+is_source_', ()=>{
|
|
21
|
+
const ctx = ctx__new()
|
|
22
|
+
let subscriber_count = 0
|
|
23
|
+
const [
|
|
24
|
+
foobar$_,
|
|
25
|
+
foobar_,
|
|
26
|
+
foobar__set,
|
|
27
|
+
] = be_rsig_triple_(
|
|
28
|
+
()=>1,
|
|
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
|
|
57
|
+
foobar$.custom = 'custom-val'
|
|
58
|
+
return foobar$
|
|
59
|
+
}, { id: 'foobar', is_source_: map_ctx=>map_ctx === ctx }))
|
|
60
|
+
equal(subscriber_count, 0)
|
|
61
|
+
equal(foobar$_([ctx__new(), ctx])._, 1)
|
|
62
|
+
equal(foobar_([ctx__new(), ctx]), 1)
|
|
63
|
+
equal(foobar$_(ctx)._, 1)
|
|
64
|
+
equal(foobar_(ctx), 1)
|
|
65
|
+
equal(subscriber_count, 1)
|
|
66
|
+
equal((ctx.get('foobar') as readwrite_rmemo_T<number>)._, 1)
|
|
67
|
+
equal(foobar$_(ctx).custom, 'custom-val')
|
|
68
|
+
foobar__set([ctx__new(), ctx], 2)
|
|
69
|
+
equal(foobar$_([ctx__new(), ctx])._, 2)
|
|
70
|
+
equal(foobar_([ctx__new(), ctx]), 2)
|
|
71
|
+
equal(foobar$_(ctx)._, 2)
|
|
72
|
+
equal(foobar_(ctx), 2)
|
|
73
|
+
equal((ctx.get('foobar') as readwrite_rmemo_T<number>)._, 2)
|
|
74
|
+
equal(foobar$_(ctx).custom, 'custom-val')
|
|
75
|
+
equal(subscriber_count, 1)
|
|
76
|
+
})
|
|
77
|
+
test.run()
|
|
78
|
+
type custom_rsig_T = readwrite_rmemo_T<number>&{ custom:string }
|
package/all/call_assign/index.js
CHANGED
package/all/compose/index.js
CHANGED
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/each/index.js
CHANGED
package/all/eql_fn_a/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { response_pair__new } from '../response_pair/index.js'
|
|
2
|
-
/** @typedef {import('../fetch__template_pair/index.d.ts').fetch__template_pair_T}
|
|
2
|
+
/** @typedef {import('../fetch__template_pair/index.d.ts').fetch__template_pair_T} */
|
|
3
3
|
/**
|
|
4
4
|
* @param {(...arg_a:any[])=>Promise<Response>}fetch_fn
|
|
5
5
|
* @param {(val:unknown)=>unknown}[hydrate]
|
package/all/filter/index.js
CHANGED
package/all/http_error/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assign } from '../assign/index.js'
|
|
2
2
|
/** @typedef {import('../error_o/index.d.ts').argument__error_o_T} */
|
|
3
|
-
/** @typedef {import('../http_error/index.d.ts').HttpError}
|
|
3
|
+
/** @typedef {import('../http_error/index.d.ts').HttpError} */
|
|
4
4
|
/**
|
|
5
5
|
* @param {string}[message]
|
|
6
6
|
* @param {argument__error_o_T}[error_o]
|
package/all/idx_filter/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { I__ } from '../combinators/index.js'
|
|
2
|
-
/** @typedef {import('../a_item/index.d.ts').a_item_T}
|
|
3
|
-
/** @typedef {import('../array_types/index.d.ts').is_match__T}
|
|
2
|
+
/** @typedef {import('../a_item/index.d.ts').a_item_T} */
|
|
3
|
+
/** @typedef {import('../array_types/index.d.ts').is_match__T} */
|
|
4
4
|
/**
|
|
5
5
|
* Returns Array of `idx` indices filtered by `fn`.
|
|
6
6
|
* @param {unknown[]}in_a
|
package/all/idx_key_r/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { I__ } from '../combinators/index.js'
|
|
2
|
-
/** @typedef {import('../array_types/index.d.ts').item_key_idx_val_fn_T}
|
|
3
|
-
/** @typedef {import('../idx_key_r/index.d.ts').idx_key_r_T}
|
|
2
|
+
/** @typedef {import('../array_types/index.d.ts').item_key_idx_val_fn_T} */
|
|
3
|
+
/** @typedef {import('../idx_key_r/index.d.ts').idx_key_r_T} */
|
|
4
4
|
/**
|
|
5
5
|
* Returns a Hash where each key is `a[idx][key]` & value is `idx`.
|
|
6
6
|
* @param {unknown[]}a
|
|
@@ -45,8 +45,8 @@ export {
|
|
|
45
45
|
maybe_idx_key_r_ as maybe_idx_key_h_,
|
|
46
46
|
maybe_idx_key_r_ as _maybe_idx_key_hash,
|
|
47
47
|
}
|
|
48
|
-
/** @typedef {import('./index.d.ts').idx_key_r_T}
|
|
49
|
-
/** @typedef {import('../array_types/index.d.ts').item_key_idx_val_fn_T}
|
|
48
|
+
/** @typedef {import('./index.d.ts').idx_key_r_T} */
|
|
49
|
+
/** @typedef {import('../array_types/index.d.ts').item_key_idx_val_fn_T} */
|
|
50
50
|
/**
|
|
51
51
|
* Returns function that returns from [_idx_key_hash](#_idx_key_hash) with `item_key_idx_val_` function argument.
|
|
52
52
|
* @param {item_key_idx_val_fn_T<string, Record<string, string>>}item_key_idx_val_
|
package/all/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export * from './Map__object/index.js'
|
|
|
5
5
|
export * from './NumericRange/index.js'
|
|
6
6
|
export * from './NumericUnit/index.js'
|
|
7
7
|
export * from './PHI/index.js'
|
|
8
|
-
export * from './primitive/index.js'
|
|
9
8
|
export * from './Request/index.js'
|
|
10
9
|
export * from './Response/index.js'
|
|
11
10
|
export * from './Timeout/index.js'
|
|
@@ -45,8 +44,8 @@ export * from './base64__buffer/index.js'
|
|
|
45
44
|
export * from './batch_queue/index.js'
|
|
46
45
|
export * from './be/index.js'
|
|
47
46
|
export * from './be_/index.js'
|
|
48
|
-
export * from './
|
|
49
|
-
export * from './
|
|
47
|
+
export * from './be_rmemo_pair/index.js'
|
|
48
|
+
export * from './be_rsig_triple/index.js'
|
|
50
49
|
export * from './binary_sort_rank/index.js'
|
|
51
50
|
export * from './bind_apply/index.js'
|
|
52
51
|
export * from './bind_call/index.js'
|
|
@@ -291,6 +290,7 @@ export * from './pick/index.js'
|
|
|
291
290
|
export * from './pick_keys/index.js'
|
|
292
291
|
export * from './pick_val_a/index.js'
|
|
293
292
|
export * from './prev_idx/index.js'
|
|
293
|
+
export * from './primitive/index.js'
|
|
294
294
|
export * from './promise/index.js'
|
|
295
295
|
export * from './promise_o/index.js'
|
|
296
296
|
export * from './promise_timeout/index.js'
|
|
@@ -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'
|