@valentin30/signal 0.1.0 → 0.2.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/dist/index.d.mts +260 -167
- package/dist/index.d.ts +260 -167
- package/dist/index.js +422 -297
- package/dist/index.mjs +414 -291
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,14 +4,74 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// src/core/
|
|
7
|
+
// src/core/contracts/comparable.ts
|
|
8
|
+
var Equals;
|
|
9
|
+
((Equals2) => {
|
|
10
|
+
function strict(value, other) {
|
|
11
|
+
if (value === other) return true;
|
|
12
|
+
if (value !== value && other !== other) return true;
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
Equals2.strict = strict;
|
|
16
|
+
})(Equals || (Equals = {}));
|
|
17
|
+
function comparator(equals = Equals.strict) {
|
|
18
|
+
return { equals };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/core/contracts/readable.ts
|
|
22
|
+
function reader(read) {
|
|
23
|
+
return { read };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/core/contracts/writable.ts
|
|
27
|
+
function writer(write) {
|
|
28
|
+
return {
|
|
29
|
+
write(value) {
|
|
30
|
+
const result = write(value);
|
|
31
|
+
if (typeof result === "boolean") return result;
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/internal/internal.ts
|
|
38
|
+
var internal_exports = {};
|
|
39
|
+
__export(internal_exports, {
|
|
40
|
+
BasicValue: () => BasicValue,
|
|
41
|
+
BatchWriter: () => BatchWriter,
|
|
42
|
+
CallbackScheduler: () => CallbackScheduler,
|
|
43
|
+
CollectorBasedBatcher: () => CollectorBasedBatcher,
|
|
44
|
+
CollectorController: () => CollectorController,
|
|
45
|
+
Composed: () => Composed,
|
|
46
|
+
ComputedValue: () => ComputedValue,
|
|
47
|
+
DependencyManager: () => DependencyManager,
|
|
48
|
+
EmittingValue: () => EmittingValue,
|
|
49
|
+
Reactive: () => Reactive,
|
|
50
|
+
ScheduledEmitter: () => ScheduledEmitter,
|
|
51
|
+
Snapshot: () => Snapshot
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// src/utils/utils.ts
|
|
55
|
+
var utils_exports = {};
|
|
56
|
+
__export(utils_exports, {
|
|
57
|
+
call: () => call,
|
|
58
|
+
factory: () => factory,
|
|
59
|
+
singleton: () => singleton
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// src/utils/call.ts
|
|
63
|
+
function call(callback) {
|
|
64
|
+
callback();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/utils/factory.ts
|
|
8
68
|
function factory(name) {
|
|
9
69
|
let __default__ = null;
|
|
10
70
|
let __factory__ = null;
|
|
11
71
|
function object(...args) {
|
|
12
72
|
if (__factory__) return __factory__(...args);
|
|
13
73
|
if (__default__) return __default__(...args);
|
|
14
|
-
throw new Error(`${name}
|
|
74
|
+
throw new Error(`${name}::factory() not configured!`);
|
|
15
75
|
}
|
|
16
76
|
object.configured = () => __default__ !== null || __factory__ !== null;
|
|
17
77
|
object.default = (factory2) => {
|
|
@@ -23,320 +83,383 @@ function factory(name) {
|
|
|
23
83
|
return object;
|
|
24
84
|
}
|
|
25
85
|
|
|
26
|
-
// src/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// src/core/computed.ts
|
|
36
|
-
var computed = factory("computed");
|
|
37
|
-
|
|
38
|
-
// src/core/effect.ts
|
|
39
|
-
var effect = factory("effect");
|
|
40
|
-
|
|
41
|
-
// src/core/ignore.ts
|
|
42
|
-
var ignore = factory("ignore");
|
|
43
|
-
|
|
44
|
-
// src/core/signal.ts
|
|
45
|
-
var signal = factory("signal");
|
|
46
|
-
|
|
47
|
-
// src/internal/index.ts
|
|
48
|
-
var internal_exports = {};
|
|
49
|
-
__export(internal_exports, {
|
|
50
|
-
batch: () => internal_batch,
|
|
51
|
-
collector: () => internal_collector,
|
|
52
|
-
composed: () => internal_composed,
|
|
53
|
-
computed: () => internal_computed,
|
|
54
|
-
effect: () => internal_effect,
|
|
55
|
-
ignore: () => internal_ignore,
|
|
56
|
-
shared: () => internal_shared,
|
|
57
|
-
signal: () => internal_signal
|
|
58
|
-
});
|
|
86
|
+
// src/utils/singleton.ts
|
|
87
|
+
function singleton(factory2) {
|
|
88
|
+
function object() {
|
|
89
|
+
return object.instance ??= factory2();
|
|
90
|
+
}
|
|
91
|
+
object.instance = void 0;
|
|
92
|
+
return object;
|
|
93
|
+
}
|
|
59
94
|
|
|
60
95
|
// src/internal/batch.ts
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
96
|
+
var CollectorBasedBatcher = class {
|
|
97
|
+
collector;
|
|
98
|
+
constructor(collector) {
|
|
99
|
+
this.collector = collector;
|
|
100
|
+
}
|
|
101
|
+
batch(callback, ...args) {
|
|
102
|
+
if (this.collector.collecting()) return callback(...args);
|
|
103
|
+
const [value, collected] = this.collector.collect(callback, ...args);
|
|
104
|
+
collected.forEach(utils_exports.call);
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
68
108
|
|
|
69
109
|
// src/internal/collector.ts
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
class Constructor {
|
|
75
|
-
#values;
|
|
76
|
-
constructor(values) {
|
|
77
|
-
this.#values = values;
|
|
78
|
-
}
|
|
79
|
-
collecting() {
|
|
80
|
-
return this.#values !== null;
|
|
81
|
-
}
|
|
82
|
-
add(value) {
|
|
83
|
-
if (!this.collecting() || !this.#values) return;
|
|
84
|
-
this.#values.add(value);
|
|
85
|
-
}
|
|
86
|
-
collect(callback) {
|
|
87
|
-
const current = this.#values;
|
|
88
|
-
this.#values = /* @__PURE__ */ new Set();
|
|
89
|
-
callback();
|
|
90
|
-
const collected = this.#values;
|
|
91
|
-
this.#values = current;
|
|
92
|
-
return collected;
|
|
93
|
-
}
|
|
94
|
-
ignore(callback) {
|
|
95
|
-
const current = this.#values;
|
|
96
|
-
this.#values = null;
|
|
97
|
-
callback();
|
|
98
|
-
this.#values = current;
|
|
99
|
-
}
|
|
110
|
+
var CollectorController = class {
|
|
111
|
+
values;
|
|
112
|
+
constructor(values = null) {
|
|
113
|
+
this.values = values;
|
|
100
114
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
#values;
|
|
123
|
-
#dependencies;
|
|
124
|
-
#compute;
|
|
125
|
-
#equals;
|
|
126
|
-
#listeners;
|
|
127
|
-
#collector;
|
|
128
|
-
constructor(empty, value, values, dependencies, listeners, collector3, compute, equals) {
|
|
129
|
-
this.#empty = empty;
|
|
130
|
-
this.#value = value;
|
|
131
|
-
this.#values = values;
|
|
132
|
-
this.#dependencies = dependencies;
|
|
133
|
-
this.#listeners = listeners;
|
|
134
|
-
this.#collector = collector3;
|
|
135
|
-
this.#compute = compute;
|
|
136
|
-
this.#equals = equals;
|
|
137
|
-
}
|
|
138
|
-
read() {
|
|
139
|
-
this.#collector.add(this);
|
|
140
|
-
return this.peek();
|
|
141
|
-
}
|
|
142
|
-
peek() {
|
|
143
|
-
if (!this.#empty && !this.#values.some(([dep, value]) => !dep.equals(value))) return this.#value;
|
|
144
|
-
const current = this.#dependencies;
|
|
145
|
-
const next = this.#collector.collect(() => this.#value = this.#compute());
|
|
146
|
-
this.#dependencies = next;
|
|
147
|
-
this.#values = Array.from(next).map((dep) => [dep, dep.read()]);
|
|
148
|
-
this.#empty = false;
|
|
149
|
-
if (!current.size && !next.size) return this.#value;
|
|
150
|
-
if (!this.#listeners.size) return this.#value;
|
|
151
|
-
current.forEach((dep) => !next.has(dep) && this.#listeners.forEach((listener) => dep.unsubscribe(listener)));
|
|
152
|
-
next.forEach((dep) => !current.has(dep) && this.#listeners.forEach((listener) => dep.subscribe(listener)));
|
|
153
|
-
return this.#value;
|
|
154
|
-
}
|
|
155
|
-
equals(other) {
|
|
156
|
-
if (this.#equals) return this.#equals(this.read(), other);
|
|
157
|
-
return this.read() === other;
|
|
158
|
-
}
|
|
159
|
-
subscribe(callback) {
|
|
160
|
-
this.#listeners.add(callback);
|
|
161
|
-
this.#dependencies.forEach((dep) => dep.subscribe(callback));
|
|
162
|
-
return this.unsubscribe.bind(this, callback);
|
|
115
|
+
collecting() {
|
|
116
|
+
return !!this.values;
|
|
117
|
+
}
|
|
118
|
+
add(value) {
|
|
119
|
+
if (!this.values) return;
|
|
120
|
+
this.values.add(value);
|
|
121
|
+
}
|
|
122
|
+
track(value) {
|
|
123
|
+
if (!this.values) return;
|
|
124
|
+
this.values.add(value);
|
|
125
|
+
}
|
|
126
|
+
collect(callback, ...args) {
|
|
127
|
+
const current = this.values;
|
|
128
|
+
this.values = /* @__PURE__ */ new Set();
|
|
129
|
+
const response = [];
|
|
130
|
+
try {
|
|
131
|
+
response[0] = callback(...args);
|
|
132
|
+
} finally {
|
|
133
|
+
response[1] = this.values;
|
|
134
|
+
this.values = current;
|
|
135
|
+
return response;
|
|
163
136
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
137
|
+
}
|
|
138
|
+
ignore(callback, ...args) {
|
|
139
|
+
const current = this.values;
|
|
140
|
+
this.values = null;
|
|
141
|
+
try {
|
|
142
|
+
return callback(...args);
|
|
143
|
+
} finally {
|
|
144
|
+
this.values = current;
|
|
167
145
|
}
|
|
168
146
|
}
|
|
169
|
-
|
|
170
|
-
})(internal_computed || (internal_computed = {}));
|
|
147
|
+
};
|
|
171
148
|
|
|
172
149
|
// src/internal/composed.ts
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
((
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
150
|
+
var Composed = class {
|
|
151
|
+
value;
|
|
152
|
+
writer;
|
|
153
|
+
constructor(value, writer2) {
|
|
154
|
+
this.value = value;
|
|
155
|
+
this.writer = writer2;
|
|
156
|
+
}
|
|
157
|
+
read() {
|
|
158
|
+
return this.value.read();
|
|
159
|
+
}
|
|
160
|
+
peek() {
|
|
161
|
+
return this.value.peek();
|
|
162
|
+
}
|
|
163
|
+
write(value) {
|
|
164
|
+
if (this.value.equals(this.peek(), value)) return false;
|
|
165
|
+
return this.writer.write(value);
|
|
166
|
+
}
|
|
167
|
+
equals(...args) {
|
|
168
|
+
const [value, other] = args.length === 1 ? [this.read(), args[0]] : args;
|
|
169
|
+
return this.value.equals(value, other);
|
|
170
|
+
}
|
|
171
|
+
subscribe(callback) {
|
|
172
|
+
return this.value.subscribe(callback);
|
|
173
|
+
}
|
|
174
|
+
unsubscribe(callback) {
|
|
175
|
+
return this.value.unsubscribe(callback);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// src/internal/dependency.ts
|
|
180
|
+
var Snapshot;
|
|
181
|
+
((Snapshot2) => {
|
|
182
|
+
function changed([value, snapshot]) {
|
|
183
|
+
return !value.equals(value.peek(), snapshot);
|
|
184
|
+
}
|
|
185
|
+
Snapshot2.changed = changed;
|
|
186
|
+
function from(values) {
|
|
187
|
+
if (!values.size) return [];
|
|
188
|
+
return Array.from(values).map(create);
|
|
189
|
+
}
|
|
190
|
+
Snapshot2.from = from;
|
|
191
|
+
function create(value) {
|
|
192
|
+
return [value, value.peek()];
|
|
193
|
+
}
|
|
194
|
+
})(Snapshot || (Snapshot = {}));
|
|
195
|
+
var DependencyManager = class {
|
|
196
|
+
snapshot;
|
|
197
|
+
dependencies;
|
|
198
|
+
collector;
|
|
199
|
+
listeners;
|
|
200
|
+
constructor(collector, listeners = /* @__PURE__ */ new Set(), dependencies = /* @__PURE__ */ new Set(), snapshot = null) {
|
|
201
|
+
this.collector = collector;
|
|
202
|
+
this.listeners = listeners;
|
|
203
|
+
this.dependencies = dependencies;
|
|
204
|
+
this.snapshot = snapshot;
|
|
205
|
+
}
|
|
206
|
+
changed() {
|
|
207
|
+
if (!this.snapshot) return true;
|
|
208
|
+
return this.snapshot.some(Snapshot.changed);
|
|
209
|
+
}
|
|
210
|
+
track(callback) {
|
|
211
|
+
const [_, dependencies] = this.collector.collect(callback);
|
|
212
|
+
if (!this.dependencies.size && !dependencies.size) return;
|
|
213
|
+
this.snapshot = Snapshot.from(dependencies);
|
|
214
|
+
if (this.equals(dependencies)) return;
|
|
215
|
+
if (this.listeners.size) {
|
|
216
|
+
this.dependencies.forEach((dep) => !dependencies.has(dep) && this.listeners.forEach((cb) => dep.unsubscribe(cb)));
|
|
217
|
+
dependencies.forEach((dep) => !this.dependencies.has(dep) && this.listeners.forEach((cb) => dep.subscribe(cb)));
|
|
201
218
|
}
|
|
219
|
+
this.dependencies = dependencies;
|
|
220
|
+
}
|
|
221
|
+
subscribe(callback) {
|
|
222
|
+
this.listeners.add(callback);
|
|
223
|
+
this.dependencies.forEach((dep) => dep.subscribe(callback));
|
|
224
|
+
return () => this.unsubscribe(callback);
|
|
225
|
+
}
|
|
226
|
+
unsubscribe(callback) {
|
|
227
|
+
this.listeners.delete(callback);
|
|
228
|
+
this.dependencies.forEach((dep) => dep.unsubscribe(callback));
|
|
229
|
+
}
|
|
230
|
+
equals(other) {
|
|
231
|
+
if (this.dependencies === other) return true;
|
|
232
|
+
if (this.dependencies.size !== other.size) return false;
|
|
233
|
+
for (const item of this.dependencies) if (!other.has(item)) return false;
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// src/internal/emitter.ts
|
|
239
|
+
var ScheduledEmitter = class {
|
|
240
|
+
listeners;
|
|
241
|
+
scheduler;
|
|
242
|
+
constructor(scheduler, listeners = /* @__PURE__ */ new Set()) {
|
|
243
|
+
this.scheduler = scheduler;
|
|
244
|
+
this.listeners = listeners;
|
|
245
|
+
}
|
|
246
|
+
emit() {
|
|
247
|
+
this.scheduler.schedule(...this.listeners);
|
|
248
|
+
}
|
|
249
|
+
subscribe(callback) {
|
|
250
|
+
this.listeners.add(callback);
|
|
251
|
+
return () => this.unsubscribe(callback);
|
|
252
|
+
}
|
|
253
|
+
unsubscribe(callback) {
|
|
254
|
+
this.listeners.delete(callback);
|
|
202
255
|
}
|
|
203
|
-
|
|
204
|
-
})(internal_composed || (internal_composed = {}));
|
|
256
|
+
};
|
|
205
257
|
|
|
206
|
-
// src/internal/
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
258
|
+
// src/internal/reactive.ts
|
|
259
|
+
var Reactive = class {
|
|
260
|
+
value;
|
|
261
|
+
tracker;
|
|
262
|
+
subscription;
|
|
263
|
+
constructor(value, tracker, subscription) {
|
|
264
|
+
this.value = value;
|
|
265
|
+
this.tracker = tracker;
|
|
266
|
+
this.subscription = subscription;
|
|
267
|
+
}
|
|
268
|
+
read() {
|
|
269
|
+
this.tracker.track(this);
|
|
270
|
+
return this.peek();
|
|
271
|
+
}
|
|
272
|
+
peek() {
|
|
273
|
+
return this.value.read();
|
|
274
|
+
}
|
|
275
|
+
write(value) {
|
|
276
|
+
return this.value.write(value);
|
|
277
|
+
}
|
|
278
|
+
equals(...args) {
|
|
279
|
+
const [value, other] = args.length === 1 ? [this.read(), args[0]] : args;
|
|
280
|
+
return this.value.equals(value, other);
|
|
281
|
+
}
|
|
282
|
+
subscribe(callback) {
|
|
283
|
+
return this.subscription.subscribe(callback);
|
|
284
|
+
}
|
|
285
|
+
unsubscribe(callback) {
|
|
286
|
+
return this.subscription.unsubscribe(callback);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// src/internal/scheduler.ts
|
|
291
|
+
var CallbackScheduler = class {
|
|
292
|
+
collector;
|
|
293
|
+
add;
|
|
294
|
+
constructor(collector) {
|
|
295
|
+
this.collector = collector;
|
|
296
|
+
this.add = this.collector.add.bind(this.collector);
|
|
297
|
+
}
|
|
298
|
+
schedule(...args) {
|
|
299
|
+
if (args.length === 0) return;
|
|
300
|
+
if (!this.collector.collecting()) return args.forEach(utils_exports.call);
|
|
301
|
+
args.forEach(this.add);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// src/internal/value.ts
|
|
306
|
+
var BasicValue = class {
|
|
307
|
+
value;
|
|
308
|
+
comparator;
|
|
309
|
+
constructor(value, comparator2) {
|
|
310
|
+
this.value = value;
|
|
311
|
+
this.comparator = comparator2;
|
|
312
|
+
}
|
|
313
|
+
read() {
|
|
314
|
+
return this.value;
|
|
315
|
+
}
|
|
316
|
+
write(value) {
|
|
317
|
+
if (this.comparator.equals(this.value, value)) return false;
|
|
318
|
+
this.value = value;
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
equals(...args) {
|
|
322
|
+
const [value, other] = args.length === 1 ? [this.read(), args[0]] : args;
|
|
323
|
+
return this.comparator.equals(value, other);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
var EmittingValue = class {
|
|
327
|
+
value;
|
|
328
|
+
emitter;
|
|
329
|
+
constructor(value, emitter) {
|
|
330
|
+
this.value = value;
|
|
331
|
+
this.emitter = emitter;
|
|
332
|
+
}
|
|
333
|
+
read() {
|
|
334
|
+
return this.value.read();
|
|
335
|
+
}
|
|
336
|
+
write(value) {
|
|
337
|
+
const changed = this.value.write(value);
|
|
338
|
+
if (changed) this.emitter.emit();
|
|
339
|
+
return changed;
|
|
340
|
+
}
|
|
341
|
+
equals(...args) {
|
|
342
|
+
const [value, other] = args.length === 1 ? [this.read(), args[0]] : args;
|
|
343
|
+
return this.value.equals(value, other);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
var ComputedValue = class {
|
|
347
|
+
cache;
|
|
348
|
+
computation;
|
|
349
|
+
dependencies;
|
|
350
|
+
constructor(cache, computation, dependencies) {
|
|
351
|
+
this.cache = cache;
|
|
352
|
+
this.computation = computation;
|
|
353
|
+
this.dependencies = dependencies;
|
|
354
|
+
this.recompute = this.recompute.bind(this);
|
|
355
|
+
}
|
|
356
|
+
read() {
|
|
357
|
+
if (this.dependencies.changed()) this.dependencies.track(this.recompute);
|
|
358
|
+
return this.cache.read();
|
|
359
|
+
}
|
|
360
|
+
recompute() {
|
|
361
|
+
this.cache.write(this.computation.read());
|
|
362
|
+
}
|
|
363
|
+
write(_) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
equals(...args) {
|
|
367
|
+
const [value, other] = args.length === 1 ? [this.read(), args[0]] : args;
|
|
368
|
+
return this.cache.equals(value, other);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// src/internal/writable.ts
|
|
373
|
+
var BatchWriter = class {
|
|
374
|
+
writer;
|
|
375
|
+
batcher;
|
|
376
|
+
constructor(writer2, batcher) {
|
|
377
|
+
this.writer = writer2;
|
|
378
|
+
this.batcher = batcher;
|
|
379
|
+
}
|
|
380
|
+
write(value) {
|
|
381
|
+
const result = this.batcher.batch(() => this.writer.write(value));
|
|
382
|
+
if (typeof result === "boolean") return result;
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// src/app/index.ts
|
|
388
|
+
function configuration() {
|
|
389
|
+
return __configuration__;
|
|
224
390
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
391
|
+
var __configuration__ = {
|
|
392
|
+
signal: utils_exports.factory("@configuration.signal"),
|
|
393
|
+
computed: utils_exports.factory("@configuration.computed"),
|
|
394
|
+
composed: utils_exports.factory("@configuration.composed"),
|
|
395
|
+
batcher: utils_exports.factory("@configuration.batch"),
|
|
396
|
+
ignorer: utils_exports.factory("@configuration.ignore"),
|
|
397
|
+
// Internal
|
|
398
|
+
scheduler: utils_exports.factory("@configuration.scheduler"),
|
|
399
|
+
tracker: utils_exports.factory("@configuration.tracker"),
|
|
400
|
+
collector: utils_exports.factory("@configuration.collector"),
|
|
401
|
+
dependency_tracker: utils_exports.factory("@configuration.dependency.tracker"),
|
|
402
|
+
dependency_collector: utils_exports.factory("@configuration.dependency.collector"),
|
|
403
|
+
callback_collector: utils_exports.factory("@configuration.callback.collector")
|
|
404
|
+
};
|
|
405
|
+
__configuration__.signal.default((value, equals) => {
|
|
406
|
+
const emitter = new internal_exports.ScheduledEmitter(configuration().scheduler());
|
|
407
|
+
const state = new internal_exports.EmittingValue(new internal_exports.BasicValue(value, comparator(equals)), emitter);
|
|
408
|
+
return new internal_exports.Reactive(state, configuration().tracker(), emitter);
|
|
409
|
+
});
|
|
410
|
+
__configuration__.computed.default((compute, equals) => {
|
|
411
|
+
const dependency = configuration().dependency_tracker();
|
|
412
|
+
const cache = new internal_exports.BasicValue(void 0, comparator(equals));
|
|
413
|
+
const value = new internal_exports.ComputedValue(cache, reader(compute), dependency);
|
|
414
|
+
return new internal_exports.Reactive(value, configuration().tracker(), dependency);
|
|
415
|
+
});
|
|
416
|
+
__configuration__.composed.default(
|
|
417
|
+
(value, write) => new internal_exports.Composed(value, new internal_exports.BatchWriter(writer(write), configuration().batcher()))
|
|
418
|
+
);
|
|
419
|
+
__configuration__.batcher.default(utils_exports.singleton(() => new internal_exports.CollectorBasedBatcher(configuration().callback_collector())));
|
|
420
|
+
__configuration__.ignorer.default(configuration().dependency_collector);
|
|
421
|
+
__configuration__.scheduler.default(utils_exports.singleton(() => new internal_exports.CallbackScheduler(configuration().callback_collector())));
|
|
422
|
+
__configuration__.collector.default(configuration().dependency_collector);
|
|
423
|
+
__configuration__.tracker.default(configuration().dependency_collector);
|
|
424
|
+
__configuration__.dependency_tracker.default(() => new internal_exports.DependencyManager(configuration().collector()));
|
|
425
|
+
__configuration__.dependency_collector.default(utils_exports.singleton(() => new internal_exports.CollectorController()));
|
|
426
|
+
__configuration__.callback_collector.default(utils_exports.singleton(() => new internal_exports.CollectorController()));
|
|
228
427
|
|
|
229
|
-
// src/
|
|
230
|
-
function
|
|
231
|
-
|
|
232
|
-
internal_ignore.collector().ignore(() => value = typeof callback === "function" ? callback(...args) : callback.read());
|
|
233
|
-
return value;
|
|
428
|
+
// src/core/batch.ts
|
|
429
|
+
function batch(callback, ...args) {
|
|
430
|
+
return configuration().batcher().batch(callback, ...args);
|
|
234
431
|
}
|
|
235
|
-
((internal_ignore2) => {
|
|
236
|
-
internal_ignore2.collector = factory("signal.collector");
|
|
237
|
-
})(internal_ignore || (internal_ignore = {}));
|
|
238
432
|
|
|
239
|
-
// src/
|
|
240
|
-
|
|
241
|
-
((
|
|
242
|
-
|
|
243
|
-
let __collector__ = null;
|
|
244
|
-
function batcher() {
|
|
245
|
-
if (!__batcher__) __batcher__ = collector();
|
|
246
|
-
return __batcher__;
|
|
247
|
-
}
|
|
248
|
-
internal_shared2.batcher = batcher;
|
|
249
|
-
function collector2() {
|
|
250
|
-
if (!__collector__) __collector__ = collector();
|
|
251
|
-
return __collector__;
|
|
252
|
-
}
|
|
253
|
-
internal_shared2.collector = collector2;
|
|
254
|
-
})(internal_shared || (internal_shared = {}));
|
|
433
|
+
// src/core/composed.ts
|
|
434
|
+
function composed(value, write) {
|
|
435
|
+
return configuration().composed(value, write);
|
|
436
|
+
}
|
|
255
437
|
|
|
256
|
-
// src/
|
|
257
|
-
function
|
|
258
|
-
return
|
|
438
|
+
// src/core/computed.ts
|
|
439
|
+
function computed(compute, equals) {
|
|
440
|
+
return configuration().computed(compute, equals);
|
|
259
441
|
}
|
|
260
|
-
((internal_signal2) => {
|
|
261
|
-
internal_signal2.batcher = factory("signal.batcher");
|
|
262
|
-
internal_signal2.collector = factory("signal.collector");
|
|
263
|
-
class Constructor {
|
|
264
|
-
#value;
|
|
265
|
-
#equals;
|
|
266
|
-
#listeners;
|
|
267
|
-
#batcher;
|
|
268
|
-
#collector;
|
|
269
|
-
constructor(value, equals, listeners, batcher2, collector3) {
|
|
270
|
-
this.#value = value;
|
|
271
|
-
this.#equals = equals;
|
|
272
|
-
this.#listeners = listeners;
|
|
273
|
-
this.#batcher = batcher2;
|
|
274
|
-
this.#collector = collector3;
|
|
275
|
-
}
|
|
276
|
-
read() {
|
|
277
|
-
this.#collector.add(this);
|
|
278
|
-
return this.peek();
|
|
279
|
-
}
|
|
280
|
-
peek() {
|
|
281
|
-
return this.#value;
|
|
282
|
-
}
|
|
283
|
-
write(value) {
|
|
284
|
-
if (this.equals(value)) return;
|
|
285
|
-
this.#value = value;
|
|
286
|
-
if (this.#batcher.collecting()) this.#listeners.forEach((listener) => this.#batcher.add(listener));
|
|
287
|
-
else this.#listeners.forEach((listener) => listener());
|
|
288
|
-
}
|
|
289
|
-
equals(other) {
|
|
290
|
-
if (this.#equals) return this.#equals(this.#value, other);
|
|
291
|
-
return this.#value === other;
|
|
292
|
-
}
|
|
293
|
-
subscribe(callback) {
|
|
294
|
-
this.#listeners.add(callback);
|
|
295
|
-
return this.unsubscribe.bind(this, callback);
|
|
296
|
-
}
|
|
297
|
-
unsubscribe(callback) {
|
|
298
|
-
this.#listeners.delete(callback);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
internal_signal2.Constructor = Constructor;
|
|
302
|
-
})(internal_signal || (internal_signal = {}));
|
|
303
442
|
|
|
304
|
-
// src/core/
|
|
305
|
-
function
|
|
306
|
-
|
|
307
|
-
signal.factory(config2.signal);
|
|
308
|
-
computed.factory(config2.computed);
|
|
309
|
-
composed.factory(config2.composed);
|
|
310
|
-
effect.factory(config2.effect);
|
|
311
|
-
batch.factory(config2.batch);
|
|
312
|
-
ignore.factory(config2.ignore);
|
|
443
|
+
// src/core/ignore.ts
|
|
444
|
+
function ignore(callback, ...args) {
|
|
445
|
+
return configuration().ignorer().ignore(callback, ...args);
|
|
313
446
|
}
|
|
314
447
|
|
|
315
|
-
// src/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
internal_effect.collector.default(internal_shared.collector);
|
|
320
|
-
internal_ignore.collector.default(internal_shared.collector);
|
|
321
|
-
internal_signal.batcher.default(internal_shared.batcher);
|
|
322
|
-
internal_composed.batcher.default(internal_shared.batcher);
|
|
323
|
-
internal_batch.collector.default(internal_shared.batcher);
|
|
324
|
-
collector.default(internal_collector);
|
|
325
|
-
signal.default(internal_signal);
|
|
326
|
-
computed.default(internal_computed);
|
|
327
|
-
composed.default(internal_composed);
|
|
328
|
-
effect.default(internal_effect);
|
|
329
|
-
batch.default(internal_batch);
|
|
330
|
-
ignore.default(internal_ignore);
|
|
448
|
+
// src/core/signal.ts
|
|
449
|
+
function signal(value, equals) {
|
|
450
|
+
return configuration().signal(value, equals);
|
|
451
|
+
}
|
|
331
452
|
export {
|
|
453
|
+
Equals,
|
|
454
|
+
internal_exports as Internal,
|
|
332
455
|
batch,
|
|
333
|
-
|
|
456
|
+
comparator,
|
|
334
457
|
composed,
|
|
335
458
|
computed,
|
|
336
|
-
|
|
337
|
-
effect,
|
|
338
|
-
factory,
|
|
459
|
+
configuration,
|
|
339
460
|
ignore,
|
|
340
|
-
|
|
341
|
-
signal
|
|
461
|
+
reader,
|
|
462
|
+
signal,
|
|
463
|
+
utils_exports as utils,
|
|
464
|
+
writer
|
|
342
465
|
};
|