@valentin30/signal 0.0.6 → 0.0.7
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/dist/index.d.mts +14 -15
- package/dist/index.d.ts +14 -15
- package/dist/index.js +19 -24
- package/dist/index.mjs +19 -23
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -9,17 +9,17 @@ type Factory<Fn extends Function> = Fn & {
|
|
|
9
9
|
};
|
|
10
10
|
declare function factory<Fn extends Function>(name: string): Factory<Fn>;
|
|
11
11
|
|
|
12
|
+
type Callback = () => void;
|
|
13
|
+
|
|
12
14
|
interface Collector$1<T> {
|
|
13
15
|
add(value: T): void;
|
|
14
16
|
collecting(): boolean;
|
|
15
|
-
collect(callback:
|
|
16
|
-
ignore(callback:
|
|
17
|
+
collect(callback: Callback): Readonly<Set<T>>;
|
|
18
|
+
ignore(callback: Callback): void;
|
|
17
19
|
}
|
|
18
20
|
type CollectorFactory = <T>() => Collector$1<T>;
|
|
19
21
|
declare const collector$1: Factory<CollectorFactory>;
|
|
20
22
|
|
|
21
|
-
type Callback = () => void;
|
|
22
|
-
|
|
23
23
|
declare function batch$1(callback: Callback): void;
|
|
24
24
|
declare function batch$1(callback: Callback, collector: Collector$1<Callback>): void;
|
|
25
25
|
declare function batch$1(callback: Callback, collector?: Collector$1<Callback>): void;
|
|
@@ -34,8 +34,8 @@ declare class Collector<T> implements Collector$1<T> {
|
|
|
34
34
|
constructor(values: Set<T> | null);
|
|
35
35
|
collecting(): boolean;
|
|
36
36
|
add(value: T): void;
|
|
37
|
-
collect(callback:
|
|
38
|
-
ignore(callback:
|
|
37
|
+
collect(callback: Callback): Set<T>;
|
|
38
|
+
ignore(callback: Callback): void;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
type Equals<T> = (value: T, other: T) => boolean;
|
|
@@ -114,6 +114,11 @@ declare namespace ignore$1 {
|
|
|
114
114
|
}
|
|
115
115
|
type IgnoreCollectorFactory = () => Collector$1<ReadonlySignal<unknown>>;
|
|
116
116
|
|
|
117
|
+
declare const shared: {
|
|
118
|
+
batcher(): Collector$1<Callback>;
|
|
119
|
+
collector(): Collector$1<ReadonlySignal<unknown>>;
|
|
120
|
+
};
|
|
121
|
+
|
|
117
122
|
type SignalBatcherFactory = () => Collector$1<Callback>;
|
|
118
123
|
type SignalCollectorFactory = () => Collector$1<ReadonlySignal<unknown>>;
|
|
119
124
|
declare function signal<T>(value: T, equals?: Equals<T>): Signal$1<T>;
|
|
@@ -149,13 +154,12 @@ type index_SignalBatcherFactory = SignalBatcherFactory;
|
|
|
149
154
|
type index_SignalCollectorFactory = SignalCollectorFactory;
|
|
150
155
|
declare const index_collector: typeof collector;
|
|
151
156
|
declare const index_effect: typeof effect;
|
|
157
|
+
declare const index_shared: typeof shared;
|
|
152
158
|
declare const index_signal: typeof signal;
|
|
153
159
|
declare namespace index {
|
|
154
|
-
export { type index_BatchCollectorFactory as BatchCollectorFactory, index_Collector as Collector, index_Composed as Composed, type index_ComposedBatcherFactory as ComposedBatcherFactory, type index_ComposedCollectorFactory as ComposedCollectorFactory, index_Computed as Computed, type index_ComputedCollectorFactory as ComputedCollectorFactory, type index_EffectCollectorFactory as EffectCollectorFactory, type Ignore$1 as Ignore, type index_IgnoreCollectorFactory as IgnoreCollectorFactory, index_Signal as Signal, type index_SignalBatcherFactory as SignalBatcherFactory, type index_SignalCollectorFactory as SignalCollectorFactory, batch$1 as batch, index_collector as collector, composed$1 as composed, computed$1 as computed, index_effect as effect, ignore$1 as ignore, index_signal as signal };
|
|
160
|
+
export { type index_BatchCollectorFactory as BatchCollectorFactory, index_Collector as Collector, index_Composed as Composed, type index_ComposedBatcherFactory as ComposedBatcherFactory, type index_ComposedCollectorFactory as ComposedCollectorFactory, index_Computed as Computed, type index_ComputedCollectorFactory as ComputedCollectorFactory, type index_EffectCollectorFactory as EffectCollectorFactory, type Ignore$1 as Ignore, type index_IgnoreCollectorFactory as IgnoreCollectorFactory, index_Signal as Signal, type index_SignalBatcherFactory as SignalBatcherFactory, type index_SignalCollectorFactory as SignalCollectorFactory, batch$1 as batch, index_collector as collector, composed$1 as composed, computed$1 as computed, index_effect as effect, ignore$1 as ignore, index_shared as shared, index_signal as signal };
|
|
155
161
|
}
|
|
156
162
|
|
|
157
|
-
type Arguments<T> = T extends (...args: infer A) => any ? A : never;
|
|
158
|
-
|
|
159
163
|
interface Batch {
|
|
160
164
|
(callback: Callback): void;
|
|
161
165
|
(callback: Callback, collector: Collector$1<Callback>): void;
|
|
@@ -187,9 +191,4 @@ interface Config {
|
|
|
187
191
|
}
|
|
188
192
|
declare function config(config?: Config): void;
|
|
189
193
|
|
|
190
|
-
|
|
191
|
-
batcher(): Collector$1<Callback>;
|
|
192
|
-
collector(): Collector$1<ReadonlySignal<unknown>>;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export { type Arguments, type Batch, type Callback, type Collector$1 as Collector, type CollectorFactory, type Comparable, type ComposedFactory, type ComputedFactory, type Config, type Effect, type EffectCallback, type EffectCleanup, type Equals, type Factory, type Function, type Ignore, type Maybe, type Reader, type ReadonlySignal, type Signal$1 as Signal, type SignalFactory, type Subscription, type Writer, batch, collector$1 as collector, composed, computed, config, effect$1 as effect, factory, ignore, index as internal, shared, signal$1 as signal };
|
|
194
|
+
export { type Batch, type Callback, type Collector$1 as Collector, type CollectorFactory, type Comparable, type ComposedFactory, type ComputedFactory, type Config, type Effect, type EffectCallback, type EffectCleanup, type Equals, type Factory, type Function, type Ignore, type Maybe, type Reader, type ReadonlySignal, type Signal$1 as Signal, type SignalFactory, type Subscription, type Writer, batch, collector$1 as collector, composed, computed, config, effect$1 as effect, factory, ignore, index as internal, signal$1 as signal };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,17 +9,17 @@ type Factory<Fn extends Function> = Fn & {
|
|
|
9
9
|
};
|
|
10
10
|
declare function factory<Fn extends Function>(name: string): Factory<Fn>;
|
|
11
11
|
|
|
12
|
+
type Callback = () => void;
|
|
13
|
+
|
|
12
14
|
interface Collector$1<T> {
|
|
13
15
|
add(value: T): void;
|
|
14
16
|
collecting(): boolean;
|
|
15
|
-
collect(callback:
|
|
16
|
-
ignore(callback:
|
|
17
|
+
collect(callback: Callback): Readonly<Set<T>>;
|
|
18
|
+
ignore(callback: Callback): void;
|
|
17
19
|
}
|
|
18
20
|
type CollectorFactory = <T>() => Collector$1<T>;
|
|
19
21
|
declare const collector$1: Factory<CollectorFactory>;
|
|
20
22
|
|
|
21
|
-
type Callback = () => void;
|
|
22
|
-
|
|
23
23
|
declare function batch$1(callback: Callback): void;
|
|
24
24
|
declare function batch$1(callback: Callback, collector: Collector$1<Callback>): void;
|
|
25
25
|
declare function batch$1(callback: Callback, collector?: Collector$1<Callback>): void;
|
|
@@ -34,8 +34,8 @@ declare class Collector<T> implements Collector$1<T> {
|
|
|
34
34
|
constructor(values: Set<T> | null);
|
|
35
35
|
collecting(): boolean;
|
|
36
36
|
add(value: T): void;
|
|
37
|
-
collect(callback:
|
|
38
|
-
ignore(callback:
|
|
37
|
+
collect(callback: Callback): Set<T>;
|
|
38
|
+
ignore(callback: Callback): void;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
type Equals<T> = (value: T, other: T) => boolean;
|
|
@@ -114,6 +114,11 @@ declare namespace ignore$1 {
|
|
|
114
114
|
}
|
|
115
115
|
type IgnoreCollectorFactory = () => Collector$1<ReadonlySignal<unknown>>;
|
|
116
116
|
|
|
117
|
+
declare const shared: {
|
|
118
|
+
batcher(): Collector$1<Callback>;
|
|
119
|
+
collector(): Collector$1<ReadonlySignal<unknown>>;
|
|
120
|
+
};
|
|
121
|
+
|
|
117
122
|
type SignalBatcherFactory = () => Collector$1<Callback>;
|
|
118
123
|
type SignalCollectorFactory = () => Collector$1<ReadonlySignal<unknown>>;
|
|
119
124
|
declare function signal<T>(value: T, equals?: Equals<T>): Signal$1<T>;
|
|
@@ -149,13 +154,12 @@ type index_SignalBatcherFactory = SignalBatcherFactory;
|
|
|
149
154
|
type index_SignalCollectorFactory = SignalCollectorFactory;
|
|
150
155
|
declare const index_collector: typeof collector;
|
|
151
156
|
declare const index_effect: typeof effect;
|
|
157
|
+
declare const index_shared: typeof shared;
|
|
152
158
|
declare const index_signal: typeof signal;
|
|
153
159
|
declare namespace index {
|
|
154
|
-
export { type index_BatchCollectorFactory as BatchCollectorFactory, index_Collector as Collector, index_Composed as Composed, type index_ComposedBatcherFactory as ComposedBatcherFactory, type index_ComposedCollectorFactory as ComposedCollectorFactory, index_Computed as Computed, type index_ComputedCollectorFactory as ComputedCollectorFactory, type index_EffectCollectorFactory as EffectCollectorFactory, type Ignore$1 as Ignore, type index_IgnoreCollectorFactory as IgnoreCollectorFactory, index_Signal as Signal, type index_SignalBatcherFactory as SignalBatcherFactory, type index_SignalCollectorFactory as SignalCollectorFactory, batch$1 as batch, index_collector as collector, composed$1 as composed, computed$1 as computed, index_effect as effect, ignore$1 as ignore, index_signal as signal };
|
|
160
|
+
export { type index_BatchCollectorFactory as BatchCollectorFactory, index_Collector as Collector, index_Composed as Composed, type index_ComposedBatcherFactory as ComposedBatcherFactory, type index_ComposedCollectorFactory as ComposedCollectorFactory, index_Computed as Computed, type index_ComputedCollectorFactory as ComputedCollectorFactory, type index_EffectCollectorFactory as EffectCollectorFactory, type Ignore$1 as Ignore, type index_IgnoreCollectorFactory as IgnoreCollectorFactory, index_Signal as Signal, type index_SignalBatcherFactory as SignalBatcherFactory, type index_SignalCollectorFactory as SignalCollectorFactory, batch$1 as batch, index_collector as collector, composed$1 as composed, computed$1 as computed, index_effect as effect, ignore$1 as ignore, index_shared as shared, index_signal as signal };
|
|
155
161
|
}
|
|
156
162
|
|
|
157
|
-
type Arguments<T> = T extends (...args: infer A) => any ? A : never;
|
|
158
|
-
|
|
159
163
|
interface Batch {
|
|
160
164
|
(callback: Callback): void;
|
|
161
165
|
(callback: Callback, collector: Collector$1<Callback>): void;
|
|
@@ -187,9 +191,4 @@ interface Config {
|
|
|
187
191
|
}
|
|
188
192
|
declare function config(config?: Config): void;
|
|
189
193
|
|
|
190
|
-
|
|
191
|
-
batcher(): Collector$1<Callback>;
|
|
192
|
-
collector(): Collector$1<ReadonlySignal<unknown>>;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export { type Arguments, type Batch, type Callback, type Collector$1 as Collector, type CollectorFactory, type Comparable, type ComposedFactory, type ComputedFactory, type Config, type Effect, type EffectCallback, type EffectCleanup, type Equals, type Factory, type Function, type Ignore, type Maybe, type Reader, type ReadonlySignal, type Signal$1 as Signal, type SignalFactory, type Subscription, type Writer, batch, collector$1 as collector, composed, computed, config, effect$1 as effect, factory, ignore, index as internal, shared, signal$1 as signal };
|
|
194
|
+
export { type Batch, type Callback, type Collector$1 as Collector, type CollectorFactory, type Comparable, type ComposedFactory, type ComputedFactory, type Config, type Effect, type EffectCallback, type EffectCleanup, type Equals, type Factory, type Function, type Ignore, type Maybe, type Reader, type ReadonlySignal, type Signal$1 as Signal, type SignalFactory, type Subscription, type Writer, batch, collector$1 as collector, composed, computed, config, effect$1 as effect, factory, ignore, index as internal, signal$1 as signal };
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,6 @@ __export(index_exports, {
|
|
|
29
29
|
factory: () => factory,
|
|
30
30
|
ignore: () => ignore,
|
|
31
31
|
internal: () => internal_exports,
|
|
32
|
-
shared: () => shared,
|
|
33
32
|
signal: () => signal
|
|
34
33
|
});
|
|
35
34
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -67,27 +66,13 @@ var effect = factory("effect");
|
|
|
67
66
|
// src/core/ignore.ts
|
|
68
67
|
var ignore = factory("ignore");
|
|
69
68
|
|
|
70
|
-
// src/core/shared.ts
|
|
71
|
-
var __batcher__ = null;
|
|
72
|
-
var __collector__ = null;
|
|
73
|
-
var shared = {
|
|
74
|
-
batcher() {
|
|
75
|
-
if (!__batcher__) __batcher__ = collector();
|
|
76
|
-
return __batcher__;
|
|
77
|
-
},
|
|
78
|
-
collector() {
|
|
79
|
-
if (!__collector__) __collector__ = collector();
|
|
80
|
-
return __collector__;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
69
|
// src/core/signal.ts
|
|
85
70
|
var signal = factory("signal");
|
|
86
71
|
|
|
87
72
|
// src/internal/index.ts
|
|
88
73
|
var internal_exports = {};
|
|
89
74
|
__export(internal_exports, {
|
|
90
|
-
Collector: () =>
|
|
75
|
+
Collector: () => Collector,
|
|
91
76
|
Composed: () => Composed,
|
|
92
77
|
Computed: () => Computed,
|
|
93
78
|
Signal: () => Signal,
|
|
@@ -97,6 +82,7 @@ __export(internal_exports, {
|
|
|
97
82
|
computed: () => computed2,
|
|
98
83
|
effect: () => effect2,
|
|
99
84
|
ignore: () => ignore2,
|
|
85
|
+
shared: () => shared,
|
|
100
86
|
signal: () => signal2
|
|
101
87
|
});
|
|
102
88
|
|
|
@@ -109,9 +95,9 @@ batch2.collector = factory("batch.collector");
|
|
|
109
95
|
|
|
110
96
|
// src/internal/collector.ts
|
|
111
97
|
function collector2() {
|
|
112
|
-
return new
|
|
98
|
+
return new Collector(null);
|
|
113
99
|
}
|
|
114
|
-
var
|
|
100
|
+
var Collector = class {
|
|
115
101
|
#values;
|
|
116
102
|
constructor(values) {
|
|
117
103
|
this.#values = values;
|
|
@@ -172,13 +158,9 @@ var Computed = class {
|
|
|
172
158
|
this.#compute = compute;
|
|
173
159
|
this.#equals = equals;
|
|
174
160
|
}
|
|
175
|
-
#dirty() {
|
|
176
|
-
if (this.#empty) return true;
|
|
177
|
-
return this.#values.some(([dep, value]) => !dep.equals(value));
|
|
178
|
-
}
|
|
179
161
|
read() {
|
|
180
162
|
this.#collector.add(this);
|
|
181
|
-
if (!this.#
|
|
163
|
+
if (!this.#empty && !this.#values.some(([dep, value]) => !dep.equals(value))) return this.#value;
|
|
182
164
|
const current = this.#dependencies;
|
|
183
165
|
const next = this.#collector.collect(() => this.#value = this.#compute());
|
|
184
166
|
this.#dependencies = next;
|
|
@@ -265,6 +247,20 @@ function ignore2(callback, ...args) {
|
|
|
265
247
|
}
|
|
266
248
|
ignore2.collector = factory("signal.collector");
|
|
267
249
|
|
|
250
|
+
// src/internal/shared.ts
|
|
251
|
+
var __batcher__ = null;
|
|
252
|
+
var __collector__ = null;
|
|
253
|
+
var shared = {
|
|
254
|
+
batcher() {
|
|
255
|
+
if (!__batcher__) __batcher__ = collector();
|
|
256
|
+
return __batcher__;
|
|
257
|
+
},
|
|
258
|
+
collector() {
|
|
259
|
+
if (!__collector__) __collector__ = collector();
|
|
260
|
+
return __collector__;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
268
264
|
// src/internal/signal.ts
|
|
269
265
|
function signal2(value, equals) {
|
|
270
266
|
return new Signal(value, equals, /* @__PURE__ */ new Set(), signal2.batcher(), signal2.collector());
|
|
@@ -345,6 +341,5 @@ ignore.default(ignore2);
|
|
|
345
341
|
factory,
|
|
346
342
|
ignore,
|
|
347
343
|
internal,
|
|
348
|
-
shared,
|
|
349
344
|
signal
|
|
350
345
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -37,27 +37,13 @@ var effect = factory("effect");
|
|
|
37
37
|
// src/core/ignore.ts
|
|
38
38
|
var ignore = factory("ignore");
|
|
39
39
|
|
|
40
|
-
// src/core/shared.ts
|
|
41
|
-
var __batcher__ = null;
|
|
42
|
-
var __collector__ = null;
|
|
43
|
-
var shared = {
|
|
44
|
-
batcher() {
|
|
45
|
-
if (!__batcher__) __batcher__ = collector();
|
|
46
|
-
return __batcher__;
|
|
47
|
-
},
|
|
48
|
-
collector() {
|
|
49
|
-
if (!__collector__) __collector__ = collector();
|
|
50
|
-
return __collector__;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
40
|
// src/core/signal.ts
|
|
55
41
|
var signal = factory("signal");
|
|
56
42
|
|
|
57
43
|
// src/internal/index.ts
|
|
58
44
|
var internal_exports = {};
|
|
59
45
|
__export(internal_exports, {
|
|
60
|
-
Collector: () =>
|
|
46
|
+
Collector: () => Collector,
|
|
61
47
|
Composed: () => Composed,
|
|
62
48
|
Computed: () => Computed,
|
|
63
49
|
Signal: () => Signal,
|
|
@@ -67,6 +53,7 @@ __export(internal_exports, {
|
|
|
67
53
|
computed: () => computed2,
|
|
68
54
|
effect: () => effect2,
|
|
69
55
|
ignore: () => ignore2,
|
|
56
|
+
shared: () => shared,
|
|
70
57
|
signal: () => signal2
|
|
71
58
|
});
|
|
72
59
|
|
|
@@ -79,9 +66,9 @@ batch2.collector = factory("batch.collector");
|
|
|
79
66
|
|
|
80
67
|
// src/internal/collector.ts
|
|
81
68
|
function collector2() {
|
|
82
|
-
return new
|
|
69
|
+
return new Collector(null);
|
|
83
70
|
}
|
|
84
|
-
var
|
|
71
|
+
var Collector = class {
|
|
85
72
|
#values;
|
|
86
73
|
constructor(values) {
|
|
87
74
|
this.#values = values;
|
|
@@ -142,13 +129,9 @@ var Computed = class {
|
|
|
142
129
|
this.#compute = compute;
|
|
143
130
|
this.#equals = equals;
|
|
144
131
|
}
|
|
145
|
-
#dirty() {
|
|
146
|
-
if (this.#empty) return true;
|
|
147
|
-
return this.#values.some(([dep, value]) => !dep.equals(value));
|
|
148
|
-
}
|
|
149
132
|
read() {
|
|
150
133
|
this.#collector.add(this);
|
|
151
|
-
if (!this.#
|
|
134
|
+
if (!this.#empty && !this.#values.some(([dep, value]) => !dep.equals(value))) return this.#value;
|
|
152
135
|
const current = this.#dependencies;
|
|
153
136
|
const next = this.#collector.collect(() => this.#value = this.#compute());
|
|
154
137
|
this.#dependencies = next;
|
|
@@ -235,6 +218,20 @@ function ignore2(callback, ...args) {
|
|
|
235
218
|
}
|
|
236
219
|
ignore2.collector = factory("signal.collector");
|
|
237
220
|
|
|
221
|
+
// src/internal/shared.ts
|
|
222
|
+
var __batcher__ = null;
|
|
223
|
+
var __collector__ = null;
|
|
224
|
+
var shared = {
|
|
225
|
+
batcher() {
|
|
226
|
+
if (!__batcher__) __batcher__ = collector();
|
|
227
|
+
return __batcher__;
|
|
228
|
+
},
|
|
229
|
+
collector() {
|
|
230
|
+
if (!__collector__) __collector__ = collector();
|
|
231
|
+
return __collector__;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
238
235
|
// src/internal/signal.ts
|
|
239
236
|
function signal2(value, equals) {
|
|
240
237
|
return new Signal(value, equals, /* @__PURE__ */ new Set(), signal2.batcher(), signal2.collector());
|
|
@@ -314,6 +311,5 @@ export {
|
|
|
314
311
|
factory,
|
|
315
312
|
ignore,
|
|
316
313
|
internal_exports as internal,
|
|
317
|
-
shared,
|
|
318
314
|
signal
|
|
319
315
|
};
|
package/package.json
CHANGED