ctx-core 4.8.2 → 4.9.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.
@@ -1,16 +1,16 @@
1
- import type { Be, be__val__new_T, be_config_T, Ctx } from '../be_/index.js'
1
+ import type { Be, be_config_T, Ctx } from '../be_/index.js'
2
2
  import type { memo_T, sig_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>,
6
6
  ctx_T extends Ctx = Ctx
7
- >(be: Be<_memo_T, ctx_T>):be_memo_pair_T<val_T, _memo_T, ctx_T>
7
+ >(be:Be<_memo_T, ctx_T>):be_memo_pair_T<val_T, _memo_T, ctx_T>
8
8
  export declare function be_memo_pair_<
9
9
  val_T,
10
10
  _memo_T extends memo_T<val_T> = memo_T<val_T>,
11
11
  ctx_T extends Ctx = Ctx
12
12
  >(
13
- rmemo__new:be__val__new_T<val_T>,
13
+ rmemo__new:(ctx:Ctx, memo:_memo_T&{ _:val_T })=>val_T,
14
14
  ...subscriber_a_THEN_config:
15
15
  |[...((ctx:Ctx, memosig:sig_T<val_T>)=>unknown)[]]
16
16
  |[...((ctx:Ctx, memosig:sig_T<val_T>)=>unknown)[], config:be_config_T]
@@ -1,10 +1,8 @@
1
+ /// <reference types="../be_/index.d.ts" />
2
+ /// <reference types="../rmemo/index.d.ts" />
3
+ /// <reference types="./index.d.ts" />
1
4
  import { be_ } from '../be_/index.js'
2
5
  import { memo_ } 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_memo_pair_T} */
8
6
  /**
9
7
  * @param {Be|be__val__new_T<unknown>}be_OR_val__new
10
8
  * @param {rmemo_subscriber_T[]|[...rmemo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
@@ -18,14 +16,14 @@ export function be_memo_pair_(
18
16
  let config =
19
17
  typeof subscriber_a_THEN_config[subscriber_a_THEN_config.length - 1] === 'object'
20
18
  ? subscriber_a_THEN_config.pop()
21
- : undefined
19
+ : 0
22
20
  /** @type {Be} */
23
21
  let be =
24
22
  be_OR_val__new.is_be
25
23
  ? be_OR_val__new
26
24
  : be_(ctx=>
27
25
  memo_(
28
- ()=>be_OR_val__new(ctx),
26
+ memo=>be_OR_val__new(ctx, memo),
29
27
  ...subscriber_a_THEN_config.map(subscriber=>
30
28
  memo=>subscriber(ctx, memo))),
31
29
  config)
@@ -15,13 +15,20 @@ test('be_memo_pair_', ()=>{
15
15
  const [
16
16
  foobar$_,
17
17
  foobar_,
18
- ] = be_memo_pair_(ctx=>base_(ctx) + 1)
18
+ ] = be_memo_pair_<number, sig_T<number>&{ count:number }>((_ctx, foobar$)=>{
19
+ equal(_ctx, ctx)
20
+ foobar$.count = (foobar$.count ||= 0) + 1
21
+ return base_(ctx) + 1
22
+ })
19
23
  const ctx = ctx__new()
24
+ equal(foobar$_(ctx).count, undefined)
20
25
  equal(foobar$_(ctx)._, 2)
21
26
  equal(foobar_(ctx), 2)
27
+ equal(foobar$_(ctx).count, 1)
22
28
  base__set(ctx, 2)
23
29
  equal(foobar$_(ctx)._, 3)
24
30
  equal(foobar_(ctx), 3)
31
+ equal(foobar$_(ctx).count, 2)
25
32
  })
26
33
  test('be_memo_pair_|+id|+is_source_|+oninit|+subscriber_a', ()=>{
27
34
  const ctx = ctx__new()
@@ -0,0 +1,26 @@
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
+ export declare function be_memosig_triple_<
4
+ val_T,
5
+ _sig_T extends sig_T<val_T> = sig_T<val_T>,
6
+ ctx_T extends Ctx = Ctx
7
+ >(be:Be<_sig_T, ctx_T>):be_memosig_triple_T<val_T, _sig_T, ctx_T>
8
+ export declare function be_memosig_triple_<
9
+ val_T,
10
+ _sig_T extends sig_T<val_T> = sig_T<val_T>,
11
+ ctx_T extends Ctx = Ctx
12
+ >(
13
+ rmemo__new:(ctx:Ctx, memosig:_sig_T)=>val_T,
14
+ ...subscriber_a_THEN_config:
15
+ |[...((ctx:Ctx, sig:_sig_T)=>unknown)[]]
16
+ |[...((ctx:Ctx, sig:_sig_T)=>unknown)[], config:be_config_T]
17
+ ):be_memosig_triple_T<val_T, _sig_T, ctx_T>
18
+ export type be_memosig_triple_T<
19
+ val_T,
20
+ _sig_T extends sig_T<val_T> = sig_T<val_T>,
21
+ ctx_T extends Ctx = Ctx
22
+ > = [
23
+ Be<_sig_T>,
24
+ (ctx:ctx_T)=>val_T,
25
+ (ctx:ctx_T, val:rmemo_val_T<_sig_T>)=>void
26
+ ]
@@ -0,0 +1,21 @@
1
+ /// <reference types="../be_/index.d.ts" />
2
+ /// <reference types="../be_sig_triple/index.d.ts" />
3
+ /// <reference types="../rmemo/index.d.ts" />
4
+ /// <reference types="./index.d.ts" />
5
+ import { be_memo_pair_ } from '../be_memo_pair'
6
+ /**
7
+ * @param {Be<sig_T>|be__val__new_T<unknown>}be_OR_val__new
8
+ * @param {rmemo_subscriber_T[]|[...rmemo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
9
+ * @returns {be_memosig_triple_T}
10
+ * @private
11
+ */
12
+ export function be_memosig_triple_(...arg_a) {
13
+ /** @type {be_sig_triple_T} */
14
+ let memo_pair = be_memo_pair_(...arg_a)
15
+ return [
16
+ ...memo_pair,
17
+ (ctx, val)=>{
18
+ memo_pair[0](ctx)._ = val
19
+ },
20
+ ]
21
+ }
@@ -0,0 +1,144 @@
1
+ import { test } from 'uvu'
2
+ import { equal } from 'uvu/assert'
3
+ import { be_ } from '../be_/index.js'
4
+ import { be_sig_triple_ } from '../be_sig_triple/index.js'
5
+ import { ctx__new } from '../ctx/index.js'
6
+ import { memosig_, type sig_T } from '../rmemo/index.js'
7
+ import { be_memosig_triple_ } from './index.js'
8
+ test('be_memosig_triple_', ()=>{
9
+ const [
10
+ ,
11
+ base_,
12
+ base__set,
13
+ ] = be_sig_triple_(()=>1)
14
+ const [
15
+ foobar$_,
16
+ foobar_,
17
+ foobar__set,
18
+ ] = be_memosig_triple_<number, sig_T<number>&{
19
+ count:number
20
+ }>((_ctx, foobar$)=>{
21
+ equal(_ctx, ctx)
22
+ foobar$.count = (foobar$.count ||= 0) + 1
23
+ return base_(ctx) + 1
24
+ })
25
+ const ctx = ctx__new()
26
+ equal(foobar$_(ctx).count, undefined)
27
+ equal(foobar$_(ctx)._, 2)
28
+ equal(foobar_(ctx), 2)
29
+ equal(foobar$_(ctx).count, 1)
30
+ foobar__set(ctx, 5)
31
+ equal(foobar$_(ctx)._, 5)
32
+ equal(foobar_(ctx), 5)
33
+ equal(foobar$_(ctx).count, 1)
34
+ base__set(ctx, 2)
35
+ equal(foobar$_(ctx)._, 3)
36
+ equal(foobar_(ctx), 3)
37
+ equal(foobar$_(ctx).count, 2)
38
+ })
39
+ test('be_memosig_triple_|+id|+is_source_', ()=>{
40
+ const ctx = ctx__new()
41
+ let subscriber_count = 0
42
+ const [
43
+ ,
44
+ base_,
45
+ base__set,
46
+ ] = be_sig_triple_(
47
+ ()=>1,
48
+ { is_source_: map_ctx=>map_ctx === ctx })
49
+ const [
50
+ ,
51
+ subscriber_dep_,
52
+ subscriber_dep__set
53
+ ] = be_sig_triple_(()=>1,
54
+ { is_source_: map_ctx=>map_ctx === ctx })
55
+ const [
56
+ foobar$_,
57
+ foobar_,
58
+ foobar__set,
59
+ ] = be_memosig_triple_(
60
+ ctx=>
61
+ base_(ctx) + 1,
62
+ (ctx, foobar$)=>{
63
+ subscriber_count++
64
+ subscriber_dep__set(ctx, subscriber_count + foobar$())
65
+ },
66
+ { id: 'foobar', is_source_: map_ctx=>map_ctx === ctx })
67
+ equal(subscriber_count, 0)
68
+ equal(foobar$_([ctx__new(), ctx])._, 2)
69
+ equal(foobar_([ctx__new(), ctx]), 2)
70
+ equal(foobar$_(ctx)._, 2)
71
+ equal(foobar_(ctx), 2)
72
+ equal(subscriber_count, 1)
73
+ equal((ctx.get('foobar') as sig_T<number>)._, 2)
74
+ equal(subscriber_dep_(ctx), 3)
75
+ foobar__set([ctx__new(), ctx], 5)
76
+ equal(foobar$_([ctx__new(), ctx])._, 5)
77
+ equal(foobar_([ctx__new(), ctx]), 5)
78
+ equal(foobar$_(ctx)._, 5)
79
+ equal(foobar_(ctx), 5)
80
+ equal((ctx.get('foobar') as sig_T<number>)._, 5)
81
+ equal(subscriber_count, 2)
82
+ equal(subscriber_dep_(ctx), 7)
83
+ base__set(ctx, 2)
84
+ equal(foobar$_([ctx__new(), ctx])._, 3)
85
+ equal(foobar_([ctx__new(), ctx]), 3)
86
+ equal(foobar$_(ctx)._, 3)
87
+ equal(foobar_(ctx), 3)
88
+ equal(subscriber_count, 3)
89
+ equal((ctx.get('foobar') as sig_T<number>)._, 3)
90
+ equal(subscriber_dep_(ctx), 6)
91
+ })
92
+ test('be_memosig_triple_|+be', ()=>{
93
+ const ctx = ctx__new()
94
+ let subscriber_count = 0
95
+ const [
96
+ ,
97
+ base_,
98
+ base__set,
99
+ ] = be_sig_triple_(()=>1,
100
+ { is_source_: map_ctx=>map_ctx === ctx })
101
+ const [
102
+ foobar$_,
103
+ foobar_,
104
+ foobar__set,
105
+ ] = be_memosig_triple_<number, custom_sig_T>(
106
+ be_(ctx=>{
107
+ const foobar$ =
108
+ memosig_(()=>base_(ctx) + 1,
109
+ foobar$=>{
110
+ foobar$()
111
+ subscriber_count++
112
+ }) as custom_sig_T
113
+ foobar$.custom = 'custom-val'
114
+ return foobar$
115
+ }, { id: 'foobar', is_source_: map_ctx=>map_ctx === ctx }))
116
+ equal(subscriber_count, 0)
117
+ equal(foobar$_([ctx__new(), ctx])._, 2)
118
+ equal(foobar_([ctx__new(), ctx]), 2)
119
+ equal(foobar$_(ctx)._, 2)
120
+ equal(foobar_(ctx), 2)
121
+ equal(subscriber_count, 1)
122
+ equal((ctx.get('foobar') as sig_T<number>)._, 2)
123
+ equal(foobar$_(ctx).custom, 'custom-val')
124
+ foobar__set(ctx, 5)
125
+ equal(foobar$_([ctx__new(), ctx])._, 5)
126
+ equal(foobar_([ctx__new(), ctx]), 5)
127
+ equal(foobar$_(ctx)._, 5)
128
+ equal(foobar_(ctx), 5)
129
+ equal(subscriber_count, 2)
130
+ equal((ctx.get('foobar') as sig_T<number>)._, 5)
131
+ equal(foobar$_(ctx).custom, 'custom-val')
132
+ base__set([ctx__new(), ctx], 2)
133
+ equal(foobar$_([ctx__new(), ctx])._, 3)
134
+ equal(foobar_([ctx__new(), ctx]), 3)
135
+ equal(foobar$_(ctx)._, 3)
136
+ equal(foobar_(ctx), 3)
137
+ equal((ctx.get('foobar') as sig_T<number>)._, 3)
138
+ equal(foobar$_(ctx).custom, 'custom-val')
139
+ equal(subscriber_count, 3)
140
+ })
141
+ test.run()
142
+ type custom_sig_T = sig_T<number>&{
143
+ custom:string
144
+ }
@@ -10,7 +10,7 @@ export declare function be_sig_triple_<
10
10
  _sig_T extends sig_T<val_T> = sig_T<val_T>,
11
11
  ctx_T extends Ctx = Ctx
12
12
  >(
13
- val__new:(ctx:Ctx, sig:_sig_T)=>val_T,
13
+ val__new:(ctx:Ctx)=>val_T,
14
14
  ...subscriber_a_THEN_config:
15
15
  |[...((ctx:Ctx, sig:_sig_T)=>unknown)[]]
16
16
  |[...((ctx:Ctx, sig:_sig_T)=>unknown)[], config:be_config_T]
@@ -1,11 +1,8 @@
1
+ /// <reference types="../be_/index.d.ts" />
2
+ /// <reference types="../rmemo/index.d.ts" />
3
+ /// <reference types="./index.d.ts" />
1
4
  import { be_ } from '../be_/index.js'
2
5
  import { sig_ } 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').sig_T} */
7
- /** @typedef {import('../rmemo/index.d.ts').rmemo_subscriber_T} */
8
- /** @typedef {import('./index.d.ts').be_sig_triple_T} */
9
6
  /**
10
7
  * @param {Be<sig_T>|be__val__new_T<unknown>}be_OR_val__new
11
8
  * @param {rmemo_subscriber_T[]|[...rmemo_subscriber_T[], be_config_T]}subscriber_a_THEN_config
@@ -19,7 +16,7 @@ export function be_sig_triple_(
19
16
  let config =
20
17
  typeof subscriber_a_THEN_config[subscriber_a_THEN_config.length - 1] === 'object'
21
18
  ? subscriber_a_THEN_config.pop()
22
- : undefined
19
+ : 0
23
20
  /** @type {Be<sig_T>} */
24
21
  let be =
25
22
  be_OR_val__new.is_be
@@ -9,7 +9,10 @@ test('be_sig_triple_', ()=>{
9
9
  foobar$_,
10
10
  foobar_,
11
11
  foobar__set,
12
- ] = be_sig_triple_(()=>1)
12
+ ] = be_sig_triple_(_ctx=>{
13
+ equal(_ctx, ctx)
14
+ return 1
15
+ })
13
16
  const ctx = ctx__new()
14
17
  equal(foobar$_(ctx)._, 1)
15
18
  equal(foobar_(ctx), 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "4.8.2",
3
+ "version": "4.9.0",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -171,7 +171,7 @@
171
171
  "import": {
172
172
  "./rmemo": "{ sig_, memo_, be_, ctx_, be_memo_pair_, be_sig_triple_ }"
173
173
  },
174
- "limit": "607 B"
174
+ "limit": "599 B"
175
175
  }
176
176
  ],
177
177
  "scripts": {
package/rmemo/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { sig__set_ as set_ } from '../all/rmemo/index.js'
2
1
  export * from '../all/be_/index.js'
3
2
  export * from '../all/be_memo_pair/index.js'
3
+ export * from '../all/be_memosig_triple/index.js'
4
4
  export * from '../all/be_sig_triple/index.js'
5
5
  export * from '../all/ctx/index.js'
6
6
  export * from '../all/rmemo/index.js'
package/rmemo/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from '../all/be_/index.js'
2
2
  export * from '../all/be_memo_pair/index.js'
3
+ export * from '../all/be_memosig_triple/index.js'
3
4
  export * from '../all/be_sig_triple/index.js'
4
5
  export * from '../all/ctx/index.js'
5
6
  export * from '../all/rmemo/index.js'