ctx-core 4.6.0 → 4.6.2

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.
@@ -1,5 +1,5 @@
1
1
  import type { Be, be__val__new_T, be_config_T, Ctx } from '../be_/index.js'
2
- import type { memo_T, rmemo_def_T } from '../rmemo/index.js'
2
+ import type { memo_T } from '../rmemo/index.js'
3
3
  export declare function be_memo_pair_<
4
4
  val_T,
5
5
  _memo_T extends memo_T<val_T> = memo_T<val_T>,
@@ -12,8 +12,8 @@ export declare function be_memo_pair_<
12
12
  >(
13
13
  rmemo__new:be__val__new_T<val_T>,
14
14
  ...subscriber_a_THEN_config:
15
- |[...rmemo_def_T<val_T>[]]
16
- |[...rmemo_def_T<val_T>[], config:be_config_T]
15
+ |[...((ctx:Ctx, memo:_memo_T)=>unknown)[]]
16
+ |[...((ctx:Ctx, memo:_memo_T)=>unknown)[], config:be_config_T]
17
17
  ):be_memo_pair_T<val_T, _memo_T, ctx_T>
18
18
  export type be_memo_pair_T<
19
19
  val_T,
@@ -24,7 +24,10 @@ export function be_memo_pair_(
24
24
  be_OR_val__new.is_be
25
25
  ? be_OR_val__new
26
26
  : be_(ctx=>
27
- memo_(()=>be_OR_val__new(ctx), ...subscriber_a_THEN_config),
27
+ memo_(
28
+ ()=>be_OR_val__new(ctx),
29
+ ...subscriber_a_THEN_config.map(subscriber=>
30
+ memo=>subscriber(ctx, memo))),
28
31
  config)
29
32
  return [
30
33
  be,
@@ -26,6 +26,12 @@ test('be_memo_pair_', ()=>{
26
26
  test('be_memo_pair_|+id|+is_source_|+oninit|+subscriber_a', ()=>{
27
27
  const ctx = ctx__new()
28
28
  let subscriber_count = 0
29
+ const [
30
+ ,
31
+ subscriber_dep_,
32
+ subscriber_dep__set
33
+ ] = be_sig_triple_(()=>1,
34
+ { is_source_: map_ctx=>map_ctx === ctx })
29
35
  const [
30
36
  ,
31
37
  base_,
@@ -36,11 +42,11 @@ test('be_memo_pair_|+id|+is_source_|+oninit|+subscriber_a', ()=>{
36
42
  foobar$_,
37
43
  foobar_,
38
44
  ] = be_memo_pair_(ctx=>base_(ctx) + 1,
39
- ()=>subscriber_count++,
40
- {
41
- id: 'foobar',
42
- is_source_: map_ctx=>map_ctx === ctx,
43
- })
45
+ (ctx, foobar$)=>{
46
+ subscriber_count++
47
+ subscriber_dep__set(ctx, subscriber_count + foobar$())
48
+ },
49
+ { id: 'foobar', is_source_: map_ctx=>map_ctx === ctx })
44
50
  equal(subscriber_count, 0)
45
51
  equal(foobar$_([ctx__new(), ctx])._, 2)
46
52
  equal(foobar_([ctx__new(), ctx]), 2)
@@ -48,13 +54,15 @@ test('be_memo_pair_|+id|+is_source_|+oninit|+subscriber_a', ()=>{
48
54
  equal(foobar_(ctx), 2)
49
55
  equal((ctx.get('foobar') as memo_T<number>)._, 2)
50
56
  equal(subscriber_count, 1)
57
+ equal(subscriber_dep_(ctx), 3)
51
58
  base__set(ctx, 2)
52
59
  equal(foobar$_([ctx__new(), ctx])._, 3)
53
60
  equal(foobar_([ctx__new(), ctx]), 3)
54
61
  equal(foobar$_(ctx)._, 3)
55
62
  equal(foobar_(ctx), 3)
56
63
  equal((ctx.get('foobar') as memo_T<number>)._, 3)
57
- equal(subscriber_count, 1)
64
+ equal(subscriber_count, 2)
65
+ equal(subscriber_dep_(ctx), 5)
58
66
  })
59
67
  test('be_memo_pair_|be', ()=>{
60
68
  const ctx = ctx__new()
@@ -1,19 +1,19 @@
1
- import type { Be, be__val__new_T, be_config_T, Ctx } from '../be_/index.js'
2
- import type { sig_T, rmemo_def_T } from '../rmemo/index.js'
1
+ import type { Be, be_config_T, Ctx } from '../be_/index.js'
2
+ import type { rmemo_val_T, sig_T } from '../rmemo/index.js'
3
3
  export declare function be_sig_triple_<
4
4
  val_T,
5
5
  _sig_T extends sig_T<val_T> = sig_T<val_T>,
6
6
  ctx_T extends Ctx = Ctx
7
- >(be: Be<_sig_T, ctx_T>):be_sig_triple_T<val_T, _sig_T, ctx_T>
7
+ >(be:Be<_sig_T, ctx_T>):be_sig_triple_T<val_T, _sig_T, ctx_T>
8
8
  export declare function be_sig_triple_<
9
9
  val_T,
10
10
  _sig_T extends sig_T<val_T> = sig_T<val_T>,
11
11
  ctx_T extends Ctx = Ctx
12
12
  >(
13
- rmemo__new:be__val__new_T<val_T>,
13
+ val__new:(ctx:Ctx, sig:_sig_T)=>val_T,
14
14
  ...subscriber_a_THEN_config:
15
- |[...rmemo_def_T<val_T>[]]
16
- |[...rmemo_def_T<val_T>[], config:be_config_T]
15
+ |[...((ctx:Ctx, sig:_sig_T)=>unknown)[]]
16
+ |[...((ctx:Ctx, sig:_sig_T)=>unknown)[], config:be_config_T]
17
17
  ):be_sig_triple_T<val_T, _sig_T, ctx_T>
18
18
  export type be_sig_triple_T<
19
19
  val_T,
@@ -22,5 +22,5 @@ export type be_sig_triple_T<
22
22
  > = [
23
23
  Be<_sig_T>,
24
24
  (ctx:ctx_T)=>val_T,
25
- (ctx:ctx_T, val:val_T)=>void
25
+ (ctx:ctx_T, val:rmemo_val_T<_sig_T>)=>void
26
26
  ]
@@ -24,11 +24,15 @@ export function be_sig_triple_(
24
24
  let be =
25
25
  be_OR_val__new.is_be
26
26
  ? be_OR_val__new
27
- : be_(ctx=>sig_(be_OR_val__new(ctx), ...subscriber_a_THEN_config),
28
- config)
27
+ : be_(ctx=>
28
+ sig_(
29
+ be_OR_val__new(ctx),
30
+ ...subscriber_a_THEN_config.map(subscriber=>
31
+ sig=>subscriber(ctx, sig))),
32
+ config)
29
33
  return [
30
34
  be,
31
- ctx=>be(ctx)._,
35
+ ctx=>be(ctx)(),
32
36
  (ctx, val)=>{
33
37
  be(ctx)._ = val
34
38
  },
@@ -2,7 +2,7 @@ import { test } from 'uvu'
2
2
  import { equal } from 'uvu/assert'
3
3
  import { be_ } from '../be_/index.js'
4
4
  import { ctx__new } from '../ctx/index.js'
5
- import { type sig_T, sig_ } from '../rmemo/index.js'
5
+ import { sig_, type sig_T } from '../rmemo/index.js'
6
6
  import { be_sig_triple_ } from './index.js'
7
7
  test('be_sig_triple_', ()=>{
8
8
  const [
@@ -20,20 +20,30 @@ test('be_sig_triple_', ()=>{
20
20
  test('be_sig_triple_|+id|+is_source_', ()=>{
21
21
  const ctx = ctx__new()
22
22
  let subscriber_count = 0
23
+ const [
24
+ ,
25
+ subscriber_dep_,
26
+ subscriber_dep__set
27
+ ] = be_sig_triple_(()=>1,
28
+ { is_source_: map_ctx=>map_ctx === ctx })
23
29
  const [
24
30
  foobar$_,
25
31
  foobar_,
26
32
  foobar__set,
27
33
  ] = be_sig_triple_(
28
34
  ()=>1,
29
- ()=>subscriber_count++,
30
- { id: 'foobar', is_source_: map_ctx=>map_ctx === ctx },)
35
+ (ctx, foobar$)=>{
36
+ subscriber_count++
37
+ subscriber_dep__set(ctx, subscriber_count + foobar$())
38
+ },
39
+ { id: 'foobar', is_source_: map_ctx=>map_ctx === ctx })
31
40
  equal(subscriber_count, 0)
32
41
  equal(foobar$_([ctx__new(), ctx])._, 1)
33
42
  equal(foobar_([ctx__new(), ctx]), 1)
34
43
  equal(foobar$_(ctx)._, 1)
35
44
  equal(foobar_(ctx), 1)
36
45
  equal(subscriber_count, 1)
46
+ equal(subscriber_dep_(ctx), 2)
37
47
  equal((ctx.get('foobar') as sig_T<number>)._, 1)
38
48
  foobar__set([ctx__new(), ctx], 2)
39
49
  equal(foobar$_([ctx__new(), ctx])._, 2)
@@ -41,7 +51,8 @@ test('be_sig_triple_|+id|+is_source_', ()=>{
41
51
  equal(foobar$_(ctx)._, 2)
42
52
  equal(foobar_(ctx), 2)
43
53
  equal((ctx.get('foobar') as sig_T<number>)._, 2)
44
- equal(subscriber_count, 1)
54
+ equal(subscriber_count, 2)
55
+ equal(subscriber_dep_(ctx), 4)
45
56
  })
46
57
  test('be_sig_triple_|+be', ()=>{
47
58
  const ctx = ctx__new()
@@ -93,9 +93,10 @@ export { memo_ as memosig_ }
93
93
  * @private
94
94
  */
95
95
  export function sig_(init_val, ...subscriber_a) {
96
- return memo_(sig=>
97
- 'val' in sig
96
+ return memo_(sig=>{
97
+ return 'val' in sig
98
98
  ? sig.val
99
- : init_val,
99
+ : init_val
100
+ },
100
101
  ...subscriber_a)
101
102
  }
@@ -142,6 +142,11 @@ test('sig_', ()=>{
142
142
  sig._ = 'val1'
143
143
  equal(sig(), 'val1')
144
144
  })
145
+ test('sig_|set before read', ()=>{
146
+ const sig = sig_('val0')
147
+ sig._ = 'val1'
148
+ equal(sig(), 'val1')
149
+ })
145
150
  test('sig_|undefined', ()=>{
146
151
  const sig = sig_(undefined)
147
152
  const memo = memo_(()=>sig())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "4.6.0",
3
+ "version": "4.6.2",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -157,7 +157,7 @@
157
157
  "import": {
158
158
  "./rmemo": "{ sig_, memo_ }"
159
159
  },
160
- "limit": "359 B"
160
+ "limit": "360 B"
161
161
  },
162
162
  {
163
163
  "name": "memo_ sig_ be_ ctx_",
@@ -171,7 +171,7 @@
171
171
  "import": {
172
172
  "./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
173
173
  },
174
- "limit": "602 B"
174
+ "limit": "619 B"
175
175
  }
176
176
  ],
177
177
  "scripts": {