@valentin30/signal 0.0.5 → 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 -10
- package/dist/index.d.ts +14 -10
- package/dist/index.js +24 -23
- package/dist/index.mjs +24 -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,4 +191,4 @@ interface Config {
|
|
|
187
191
|
}
|
|
188
192
|
declare function config(config?: Config): void;
|
|
189
193
|
|
|
190
|
-
export { type
|
|
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,4 +191,4 @@ interface Config {
|
|
|
187
191
|
}
|
|
188
192
|
declare function config(config?: Config): void;
|
|
189
193
|
|
|
190
|
-
export { type
|
|
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
|
@@ -82,6 +82,7 @@ __export(internal_exports, {
|
|
|
82
82
|
computed: () => computed2,
|
|
83
83
|
effect: () => effect2,
|
|
84
84
|
ignore: () => ignore2,
|
|
85
|
+
shared: () => shared,
|
|
85
86
|
signal: () => signal2
|
|
86
87
|
});
|
|
87
88
|
|
|
@@ -157,13 +158,9 @@ var Computed = class {
|
|
|
157
158
|
this.#compute = compute;
|
|
158
159
|
this.#equals = equals;
|
|
159
160
|
}
|
|
160
|
-
#dirty() {
|
|
161
|
-
if (this.#empty) return true;
|
|
162
|
-
return this.#values.some(([dep, value]) => !dep.equals(value));
|
|
163
|
-
}
|
|
164
161
|
read() {
|
|
165
162
|
this.#collector.add(this);
|
|
166
|
-
if (!this.#
|
|
163
|
+
if (!this.#empty && !this.#values.some(([dep, value]) => !dep.equals(value))) return this.#value;
|
|
167
164
|
const current = this.#dependencies;
|
|
168
165
|
const next = this.#collector.collect(() => this.#value = this.#compute());
|
|
169
166
|
this.#dependencies = next;
|
|
@@ -250,6 +247,20 @@ function ignore2(callback, ...args) {
|
|
|
250
247
|
}
|
|
251
248
|
ignore2.collector = factory("signal.collector");
|
|
252
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
|
+
|
|
253
264
|
// src/internal/signal.ts
|
|
254
265
|
function signal2(value, equals) {
|
|
255
266
|
return new Signal(value, equals, /* @__PURE__ */ new Set(), signal2.batcher(), signal2.collector());
|
|
@@ -304,24 +315,14 @@ function config(config2 = {}) {
|
|
|
304
315
|
}
|
|
305
316
|
|
|
306
317
|
// src/index.ts
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
signal2.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
effect2.collector.default(shared_collector);
|
|
316
|
-
ignore2.collector.default(shared_collector);
|
|
317
|
-
var __batcher__ = null;
|
|
318
|
-
function shared_batcher() {
|
|
319
|
-
if (!__batcher__) __batcher__ = collector();
|
|
320
|
-
return __batcher__;
|
|
321
|
-
}
|
|
322
|
-
signal2.batcher.default(shared_batcher);
|
|
323
|
-
composed2.batcher.default(shared_batcher);
|
|
324
|
-
batch2.collector.default(shared_batcher);
|
|
318
|
+
signal2.collector.default(shared.collector);
|
|
319
|
+
computed2.collector.default(shared.collector);
|
|
320
|
+
composed2.collector.default(shared.collector);
|
|
321
|
+
effect2.collector.default(shared.collector);
|
|
322
|
+
ignore2.collector.default(shared.collector);
|
|
323
|
+
signal2.batcher.default(shared.batcher);
|
|
324
|
+
composed2.batcher.default(shared.batcher);
|
|
325
|
+
batch2.collector.default(shared.batcher);
|
|
325
326
|
collector.default(collector2);
|
|
326
327
|
signal.default(signal2);
|
|
327
328
|
computed.default(computed2);
|
package/dist/index.mjs
CHANGED
|
@@ -53,6 +53,7 @@ __export(internal_exports, {
|
|
|
53
53
|
computed: () => computed2,
|
|
54
54
|
effect: () => effect2,
|
|
55
55
|
ignore: () => ignore2,
|
|
56
|
+
shared: () => shared,
|
|
56
57
|
signal: () => signal2
|
|
57
58
|
});
|
|
58
59
|
|
|
@@ -128,13 +129,9 @@ var Computed = class {
|
|
|
128
129
|
this.#compute = compute;
|
|
129
130
|
this.#equals = equals;
|
|
130
131
|
}
|
|
131
|
-
#dirty() {
|
|
132
|
-
if (this.#empty) return true;
|
|
133
|
-
return this.#values.some(([dep, value]) => !dep.equals(value));
|
|
134
|
-
}
|
|
135
132
|
read() {
|
|
136
133
|
this.#collector.add(this);
|
|
137
|
-
if (!this.#
|
|
134
|
+
if (!this.#empty && !this.#values.some(([dep, value]) => !dep.equals(value))) return this.#value;
|
|
138
135
|
const current = this.#dependencies;
|
|
139
136
|
const next = this.#collector.collect(() => this.#value = this.#compute());
|
|
140
137
|
this.#dependencies = next;
|
|
@@ -221,6 +218,20 @@ function ignore2(callback, ...args) {
|
|
|
221
218
|
}
|
|
222
219
|
ignore2.collector = factory("signal.collector");
|
|
223
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
|
+
|
|
224
235
|
// src/internal/signal.ts
|
|
225
236
|
function signal2(value, equals) {
|
|
226
237
|
return new Signal(value, equals, /* @__PURE__ */ new Set(), signal2.batcher(), signal2.collector());
|
|
@@ -275,24 +286,14 @@ function config(config2 = {}) {
|
|
|
275
286
|
}
|
|
276
287
|
|
|
277
288
|
// src/index.ts
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
signal2.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
effect2.collector.default(shared_collector);
|
|
287
|
-
ignore2.collector.default(shared_collector);
|
|
288
|
-
var __batcher__ = null;
|
|
289
|
-
function shared_batcher() {
|
|
290
|
-
if (!__batcher__) __batcher__ = collector();
|
|
291
|
-
return __batcher__;
|
|
292
|
-
}
|
|
293
|
-
signal2.batcher.default(shared_batcher);
|
|
294
|
-
composed2.batcher.default(shared_batcher);
|
|
295
|
-
batch2.collector.default(shared_batcher);
|
|
289
|
+
signal2.collector.default(shared.collector);
|
|
290
|
+
computed2.collector.default(shared.collector);
|
|
291
|
+
composed2.collector.default(shared.collector);
|
|
292
|
+
effect2.collector.default(shared.collector);
|
|
293
|
+
ignore2.collector.default(shared.collector);
|
|
294
|
+
signal2.batcher.default(shared.batcher);
|
|
295
|
+
composed2.batcher.default(shared.batcher);
|
|
296
|
+
batch2.collector.default(shared.batcher);
|
|
296
297
|
collector.default(collector2);
|
|
297
298
|
signal.default(signal2);
|
|
298
299
|
computed.default(computed2);
|
package/package.json
CHANGED