@valentin30/signal 0.0.4 → 0.0.5
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 +4 -17
- package/dist/index.d.ts +4 -17
- package/dist/index.js +72 -72
- package/dist/index.mjs +72 -72
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -30,7 +30,7 @@ type BatchCollectorFactory = () => Collector$1<Callback>;
|
|
|
30
30
|
|
|
31
31
|
declare function collector<T>(): Collector$1<T>;
|
|
32
32
|
declare class Collector<T> implements Collector$1<T> {
|
|
33
|
-
private
|
|
33
|
+
#private;
|
|
34
34
|
constructor(values: Set<T> | null);
|
|
35
35
|
collecting(): boolean;
|
|
36
36
|
add(value: T): void;
|
|
@@ -69,16 +69,8 @@ declare namespace computed$1 {
|
|
|
69
69
|
}
|
|
70
70
|
type ComputedCollectorFactory = () => Collector$1<ReadonlySignal<unknown>>;
|
|
71
71
|
declare class Computed<T> implements ReadonlySignal<T> {
|
|
72
|
-
private
|
|
73
|
-
private value;
|
|
74
|
-
private values;
|
|
75
|
-
private dependencies;
|
|
76
|
-
private readonly compute;
|
|
77
|
-
private readonly equalsFn;
|
|
78
|
-
private readonly listeners;
|
|
79
|
-
private readonly collector;
|
|
72
|
+
#private;
|
|
80
73
|
constructor(empty: boolean, value: T | undefined, values: [ReadonlySignal<unknown>, unknown][], dependencies: Set<ReadonlySignal<unknown>>, listeners: Set<Callback>, collector: Collector$1<ReadonlySignal<unknown>>, compute: () => T, equals: Maybe<Equals<T>>);
|
|
81
|
-
private dirty;
|
|
82
74
|
read(): T;
|
|
83
75
|
equals(other: T): boolean;
|
|
84
76
|
subscribe(callback: Callback): Callback;
|
|
@@ -93,8 +85,7 @@ declare namespace composed$1 {
|
|
|
93
85
|
var collector: Factory<ComposedCollectorFactory>;
|
|
94
86
|
}
|
|
95
87
|
declare class Composed<T> extends Computed<T> implements Signal$1<T> {
|
|
96
|
-
private
|
|
97
|
-
private readonly writeFn;
|
|
88
|
+
#private;
|
|
98
89
|
constructor(empty: boolean, value: T | undefined, values: [ReadonlySignal<unknown>, unknown][], dependencies: Set<ReadonlySignal<unknown>>, listeners: Set<Callback>, batcher: Collector$1<Callback>, collector: Collector$1<ReadonlySignal<unknown>>, compute: () => T, write: (value: T) => void, equals: Maybe<Equals<T>>);
|
|
99
90
|
write(value: T): void;
|
|
100
91
|
}
|
|
@@ -131,11 +122,7 @@ declare namespace signal {
|
|
|
131
122
|
var collector: Factory<SignalCollectorFactory>;
|
|
132
123
|
}
|
|
133
124
|
declare class Signal<T> implements Signal$1<T> {
|
|
134
|
-
private
|
|
135
|
-
private readonly equalsFn;
|
|
136
|
-
private readonly listeners;
|
|
137
|
-
private readonly batcher;
|
|
138
|
-
private readonly collector;
|
|
125
|
+
#private;
|
|
139
126
|
constructor(value: T, equals: Maybe<Equals<T>>, listeners: Set<Callback>, batcher: Collector$1<Callback>, collector: Collector$1<ReadonlySignal<unknown>>);
|
|
140
127
|
read(): T;
|
|
141
128
|
write(value: T): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ type BatchCollectorFactory = () => Collector$1<Callback>;
|
|
|
30
30
|
|
|
31
31
|
declare function collector<T>(): Collector$1<T>;
|
|
32
32
|
declare class Collector<T> implements Collector$1<T> {
|
|
33
|
-
private
|
|
33
|
+
#private;
|
|
34
34
|
constructor(values: Set<T> | null);
|
|
35
35
|
collecting(): boolean;
|
|
36
36
|
add(value: T): void;
|
|
@@ -69,16 +69,8 @@ declare namespace computed$1 {
|
|
|
69
69
|
}
|
|
70
70
|
type ComputedCollectorFactory = () => Collector$1<ReadonlySignal<unknown>>;
|
|
71
71
|
declare class Computed<T> implements ReadonlySignal<T> {
|
|
72
|
-
private
|
|
73
|
-
private value;
|
|
74
|
-
private values;
|
|
75
|
-
private dependencies;
|
|
76
|
-
private readonly compute;
|
|
77
|
-
private readonly equalsFn;
|
|
78
|
-
private readonly listeners;
|
|
79
|
-
private readonly collector;
|
|
72
|
+
#private;
|
|
80
73
|
constructor(empty: boolean, value: T | undefined, values: [ReadonlySignal<unknown>, unknown][], dependencies: Set<ReadonlySignal<unknown>>, listeners: Set<Callback>, collector: Collector$1<ReadonlySignal<unknown>>, compute: () => T, equals: Maybe<Equals<T>>);
|
|
81
|
-
private dirty;
|
|
82
74
|
read(): T;
|
|
83
75
|
equals(other: T): boolean;
|
|
84
76
|
subscribe(callback: Callback): Callback;
|
|
@@ -93,8 +85,7 @@ declare namespace composed$1 {
|
|
|
93
85
|
var collector: Factory<ComposedCollectorFactory>;
|
|
94
86
|
}
|
|
95
87
|
declare class Composed<T> extends Computed<T> implements Signal$1<T> {
|
|
96
|
-
private
|
|
97
|
-
private readonly writeFn;
|
|
88
|
+
#private;
|
|
98
89
|
constructor(empty: boolean, value: T | undefined, values: [ReadonlySignal<unknown>, unknown][], dependencies: Set<ReadonlySignal<unknown>>, listeners: Set<Callback>, batcher: Collector$1<Callback>, collector: Collector$1<ReadonlySignal<unknown>>, compute: () => T, write: (value: T) => void, equals: Maybe<Equals<T>>);
|
|
99
90
|
write(value: T): void;
|
|
100
91
|
}
|
|
@@ -131,11 +122,7 @@ declare namespace signal {
|
|
|
131
122
|
var collector: Factory<SignalCollectorFactory>;
|
|
132
123
|
}
|
|
133
124
|
declare class Signal<T> implements Signal$1<T> {
|
|
134
|
-
private
|
|
135
|
-
private readonly equalsFn;
|
|
136
|
-
private readonly listeners;
|
|
137
|
-
private readonly batcher;
|
|
138
|
-
private readonly collector;
|
|
125
|
+
#private;
|
|
139
126
|
constructor(value: T, equals: Maybe<Equals<T>>, listeners: Set<Callback>, batcher: Collector$1<Callback>, collector: Collector$1<ReadonlySignal<unknown>>);
|
|
140
127
|
read(): T;
|
|
141
128
|
write(value: T): void;
|
package/dist/index.js
CHANGED
|
@@ -97,30 +97,30 @@ function collector2() {
|
|
|
97
97
|
return new Collector(null);
|
|
98
98
|
}
|
|
99
99
|
var Collector = class {
|
|
100
|
-
values;
|
|
100
|
+
#values;
|
|
101
101
|
constructor(values) {
|
|
102
|
-
this
|
|
102
|
+
this.#values = values;
|
|
103
103
|
}
|
|
104
104
|
collecting() {
|
|
105
|
-
return this
|
|
105
|
+
return this.#values !== null;
|
|
106
106
|
}
|
|
107
107
|
add(value) {
|
|
108
|
-
if (!this.values) return;
|
|
109
|
-
this
|
|
108
|
+
if (!this.collecting() || !this.#values) return;
|
|
109
|
+
this.#values.add(value);
|
|
110
110
|
}
|
|
111
111
|
collect(callback) {
|
|
112
|
-
const current = this
|
|
113
|
-
this
|
|
112
|
+
const current = this.#values;
|
|
113
|
+
this.#values = /* @__PURE__ */ new Set();
|
|
114
114
|
callback();
|
|
115
|
-
const collected = this
|
|
116
|
-
this
|
|
115
|
+
const collected = this.#values;
|
|
116
|
+
this.#values = current;
|
|
117
117
|
return collected;
|
|
118
118
|
}
|
|
119
119
|
ignore(callback) {
|
|
120
|
-
const current = this
|
|
121
|
-
this
|
|
120
|
+
const current = this.#values;
|
|
121
|
+
this.#values = null;
|
|
122
122
|
callback();
|
|
123
|
-
this
|
|
123
|
+
this.#values = current;
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
126
|
|
|
@@ -139,54 +139,54 @@ function computed2(compute, equals) {
|
|
|
139
139
|
}
|
|
140
140
|
computed2.collector = factory("computed.collector");
|
|
141
141
|
var Computed = class {
|
|
142
|
-
empty;
|
|
143
|
-
value;
|
|
144
|
-
values;
|
|
145
|
-
dependencies;
|
|
146
|
-
compute;
|
|
147
|
-
|
|
148
|
-
listeners;
|
|
149
|
-
collector;
|
|
142
|
+
#empty;
|
|
143
|
+
#value;
|
|
144
|
+
#values;
|
|
145
|
+
#dependencies;
|
|
146
|
+
#compute;
|
|
147
|
+
#equals;
|
|
148
|
+
#listeners;
|
|
149
|
+
#collector;
|
|
150
150
|
constructor(empty, value, values, dependencies, listeners, collector3, compute, equals) {
|
|
151
|
-
this
|
|
152
|
-
this
|
|
153
|
-
this
|
|
154
|
-
this
|
|
155
|
-
this
|
|
156
|
-
this
|
|
157
|
-
this
|
|
158
|
-
this
|
|
151
|
+
this.#empty = empty;
|
|
152
|
+
this.#value = value;
|
|
153
|
+
this.#values = values;
|
|
154
|
+
this.#dependencies = dependencies;
|
|
155
|
+
this.#listeners = listeners;
|
|
156
|
+
this.#collector = collector3;
|
|
157
|
+
this.#compute = compute;
|
|
158
|
+
this.#equals = equals;
|
|
159
159
|
}
|
|
160
|
-
dirty() {
|
|
161
|
-
if (this
|
|
162
|
-
return this
|
|
160
|
+
#dirty() {
|
|
161
|
+
if (this.#empty) return true;
|
|
162
|
+
return this.#values.some(([dep, value]) => !dep.equals(value));
|
|
163
163
|
}
|
|
164
164
|
read() {
|
|
165
|
-
this
|
|
166
|
-
if (!this
|
|
167
|
-
const current = this
|
|
168
|
-
const next = this
|
|
169
|
-
this
|
|
170
|
-
this
|
|
171
|
-
this
|
|
172
|
-
if (!current.size && !next.size) return this
|
|
173
|
-
if (!this
|
|
174
|
-
current.forEach((dep) => !next.has(dep) && this
|
|
175
|
-
next.forEach((dep) => !current.has(dep) && this
|
|
176
|
-
return this
|
|
165
|
+
this.#collector.add(this);
|
|
166
|
+
if (!this.#dirty()) return this.#value;
|
|
167
|
+
const current = this.#dependencies;
|
|
168
|
+
const next = this.#collector.collect(() => this.#value = this.#compute());
|
|
169
|
+
this.#dependencies = next;
|
|
170
|
+
this.#values = Array.from(next).map((dep) => [dep, dep.read()]);
|
|
171
|
+
this.#empty = false;
|
|
172
|
+
if (!current.size && !next.size) return this.#value;
|
|
173
|
+
if (!this.#listeners.size) return this.#value;
|
|
174
|
+
current.forEach((dep) => !next.has(dep) && this.#listeners.forEach((listener) => dep.unsubscribe(listener)));
|
|
175
|
+
next.forEach((dep) => !current.has(dep) && this.#listeners.forEach((listener) => dep.subscribe(listener)));
|
|
176
|
+
return this.#value;
|
|
177
177
|
}
|
|
178
178
|
equals(other) {
|
|
179
|
-
if (this
|
|
179
|
+
if (this.#equals) return this.#equals(this.read(), other);
|
|
180
180
|
return this.read() === other;
|
|
181
181
|
}
|
|
182
182
|
subscribe(callback) {
|
|
183
|
-
this
|
|
184
|
-
this
|
|
183
|
+
this.#listeners.add(callback);
|
|
184
|
+
this.#dependencies.forEach((dep) => dep.subscribe(callback));
|
|
185
185
|
return this.unsubscribe.bind(this, callback);
|
|
186
186
|
}
|
|
187
187
|
unsubscribe(callback) {
|
|
188
|
-
this
|
|
189
|
-
this
|
|
188
|
+
this.#listeners.delete(callback);
|
|
189
|
+
this.#dependencies.forEach((dep) => dep.unsubscribe(callback));
|
|
190
190
|
}
|
|
191
191
|
};
|
|
192
192
|
|
|
@@ -208,16 +208,16 @@ function composed2(compute, write, equals) {
|
|
|
208
208
|
composed2.batcher = factory("composed.batcher");
|
|
209
209
|
composed2.collector = factory("composed.collector");
|
|
210
210
|
var Composed = class extends Computed {
|
|
211
|
-
batcher;
|
|
212
|
-
|
|
211
|
+
#batcher;
|
|
212
|
+
#write;
|
|
213
213
|
constructor(empty, value, values, dependencies, listeners, batcher, collector3, compute, write, equals) {
|
|
214
214
|
super(empty, value, values, dependencies, listeners, collector3, compute, equals);
|
|
215
|
-
this
|
|
216
|
-
this
|
|
215
|
+
this.#batcher = batcher;
|
|
216
|
+
this.#write = write;
|
|
217
217
|
}
|
|
218
218
|
write(value) {
|
|
219
219
|
if (this.equals(value)) return;
|
|
220
|
-
batch(() => this
|
|
220
|
+
batch(() => this.#write(value), this.#batcher);
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
|
|
@@ -257,38 +257,38 @@ function signal2(value, equals) {
|
|
|
257
257
|
signal2.batcher = factory("signal.batcher");
|
|
258
258
|
signal2.collector = factory("signal.collector");
|
|
259
259
|
var Signal = class {
|
|
260
|
-
value;
|
|
261
|
-
|
|
262
|
-
listeners;
|
|
263
|
-
batcher;
|
|
264
|
-
collector;
|
|
260
|
+
#value;
|
|
261
|
+
#equals;
|
|
262
|
+
#listeners;
|
|
263
|
+
#batcher;
|
|
264
|
+
#collector;
|
|
265
265
|
constructor(value, equals, listeners, batcher, collector3) {
|
|
266
|
-
this
|
|
267
|
-
this
|
|
268
|
-
this
|
|
269
|
-
this
|
|
270
|
-
this
|
|
266
|
+
this.#value = value;
|
|
267
|
+
this.#equals = equals;
|
|
268
|
+
this.#listeners = listeners;
|
|
269
|
+
this.#batcher = batcher;
|
|
270
|
+
this.#collector = collector3;
|
|
271
271
|
}
|
|
272
272
|
read() {
|
|
273
|
-
this
|
|
274
|
-
return this
|
|
273
|
+
this.#collector.add(this);
|
|
274
|
+
return this.#value;
|
|
275
275
|
}
|
|
276
276
|
write(value) {
|
|
277
277
|
if (this.equals(value)) return;
|
|
278
|
-
this
|
|
279
|
-
if (this
|
|
280
|
-
else this
|
|
278
|
+
this.#value = value;
|
|
279
|
+
if (this.#batcher.collecting()) this.#listeners.forEach((listener) => this.#batcher.add(listener));
|
|
280
|
+
else this.#listeners.forEach((listener) => listener());
|
|
281
281
|
}
|
|
282
282
|
equals(other) {
|
|
283
|
-
if (this
|
|
284
|
-
return this
|
|
283
|
+
if (this.#equals) return this.#equals(this.#value, other);
|
|
284
|
+
return this.#value === other;
|
|
285
285
|
}
|
|
286
286
|
subscribe(callback) {
|
|
287
|
-
this
|
|
287
|
+
this.#listeners.add(callback);
|
|
288
288
|
return this.unsubscribe.bind(this, callback);
|
|
289
289
|
}
|
|
290
290
|
unsubscribe(callback) {
|
|
291
|
-
this
|
|
291
|
+
this.#listeners.delete(callback);
|
|
292
292
|
}
|
|
293
293
|
};
|
|
294
294
|
|
package/dist/index.mjs
CHANGED
|
@@ -68,30 +68,30 @@ function collector2() {
|
|
|
68
68
|
return new Collector(null);
|
|
69
69
|
}
|
|
70
70
|
var Collector = class {
|
|
71
|
-
values;
|
|
71
|
+
#values;
|
|
72
72
|
constructor(values) {
|
|
73
|
-
this
|
|
73
|
+
this.#values = values;
|
|
74
74
|
}
|
|
75
75
|
collecting() {
|
|
76
|
-
return this
|
|
76
|
+
return this.#values !== null;
|
|
77
77
|
}
|
|
78
78
|
add(value) {
|
|
79
|
-
if (!this.values) return;
|
|
80
|
-
this
|
|
79
|
+
if (!this.collecting() || !this.#values) return;
|
|
80
|
+
this.#values.add(value);
|
|
81
81
|
}
|
|
82
82
|
collect(callback) {
|
|
83
|
-
const current = this
|
|
84
|
-
this
|
|
83
|
+
const current = this.#values;
|
|
84
|
+
this.#values = /* @__PURE__ */ new Set();
|
|
85
85
|
callback();
|
|
86
|
-
const collected = this
|
|
87
|
-
this
|
|
86
|
+
const collected = this.#values;
|
|
87
|
+
this.#values = current;
|
|
88
88
|
return collected;
|
|
89
89
|
}
|
|
90
90
|
ignore(callback) {
|
|
91
|
-
const current = this
|
|
92
|
-
this
|
|
91
|
+
const current = this.#values;
|
|
92
|
+
this.#values = null;
|
|
93
93
|
callback();
|
|
94
|
-
this
|
|
94
|
+
this.#values = current;
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
97
|
|
|
@@ -110,54 +110,54 @@ function computed2(compute, equals) {
|
|
|
110
110
|
}
|
|
111
111
|
computed2.collector = factory("computed.collector");
|
|
112
112
|
var Computed = class {
|
|
113
|
-
empty;
|
|
114
|
-
value;
|
|
115
|
-
values;
|
|
116
|
-
dependencies;
|
|
117
|
-
compute;
|
|
118
|
-
|
|
119
|
-
listeners;
|
|
120
|
-
collector;
|
|
113
|
+
#empty;
|
|
114
|
+
#value;
|
|
115
|
+
#values;
|
|
116
|
+
#dependencies;
|
|
117
|
+
#compute;
|
|
118
|
+
#equals;
|
|
119
|
+
#listeners;
|
|
120
|
+
#collector;
|
|
121
121
|
constructor(empty, value, values, dependencies, listeners, collector3, compute, equals) {
|
|
122
|
-
this
|
|
123
|
-
this
|
|
124
|
-
this
|
|
125
|
-
this
|
|
126
|
-
this
|
|
127
|
-
this
|
|
128
|
-
this
|
|
129
|
-
this
|
|
122
|
+
this.#empty = empty;
|
|
123
|
+
this.#value = value;
|
|
124
|
+
this.#values = values;
|
|
125
|
+
this.#dependencies = dependencies;
|
|
126
|
+
this.#listeners = listeners;
|
|
127
|
+
this.#collector = collector3;
|
|
128
|
+
this.#compute = compute;
|
|
129
|
+
this.#equals = equals;
|
|
130
130
|
}
|
|
131
|
-
dirty() {
|
|
132
|
-
if (this
|
|
133
|
-
return this
|
|
131
|
+
#dirty() {
|
|
132
|
+
if (this.#empty) return true;
|
|
133
|
+
return this.#values.some(([dep, value]) => !dep.equals(value));
|
|
134
134
|
}
|
|
135
135
|
read() {
|
|
136
|
-
this
|
|
137
|
-
if (!this
|
|
138
|
-
const current = this
|
|
139
|
-
const next = this
|
|
140
|
-
this
|
|
141
|
-
this
|
|
142
|
-
this
|
|
143
|
-
if (!current.size && !next.size) return this
|
|
144
|
-
if (!this
|
|
145
|
-
current.forEach((dep) => !next.has(dep) && this
|
|
146
|
-
next.forEach((dep) => !current.has(dep) && this
|
|
147
|
-
return this
|
|
136
|
+
this.#collector.add(this);
|
|
137
|
+
if (!this.#dirty()) return this.#value;
|
|
138
|
+
const current = this.#dependencies;
|
|
139
|
+
const next = this.#collector.collect(() => this.#value = this.#compute());
|
|
140
|
+
this.#dependencies = next;
|
|
141
|
+
this.#values = Array.from(next).map((dep) => [dep, dep.read()]);
|
|
142
|
+
this.#empty = false;
|
|
143
|
+
if (!current.size && !next.size) return this.#value;
|
|
144
|
+
if (!this.#listeners.size) return this.#value;
|
|
145
|
+
current.forEach((dep) => !next.has(dep) && this.#listeners.forEach((listener) => dep.unsubscribe(listener)));
|
|
146
|
+
next.forEach((dep) => !current.has(dep) && this.#listeners.forEach((listener) => dep.subscribe(listener)));
|
|
147
|
+
return this.#value;
|
|
148
148
|
}
|
|
149
149
|
equals(other) {
|
|
150
|
-
if (this
|
|
150
|
+
if (this.#equals) return this.#equals(this.read(), other);
|
|
151
151
|
return this.read() === other;
|
|
152
152
|
}
|
|
153
153
|
subscribe(callback) {
|
|
154
|
-
this
|
|
155
|
-
this
|
|
154
|
+
this.#listeners.add(callback);
|
|
155
|
+
this.#dependencies.forEach((dep) => dep.subscribe(callback));
|
|
156
156
|
return this.unsubscribe.bind(this, callback);
|
|
157
157
|
}
|
|
158
158
|
unsubscribe(callback) {
|
|
159
|
-
this
|
|
160
|
-
this
|
|
159
|
+
this.#listeners.delete(callback);
|
|
160
|
+
this.#dependencies.forEach((dep) => dep.unsubscribe(callback));
|
|
161
161
|
}
|
|
162
162
|
};
|
|
163
163
|
|
|
@@ -179,16 +179,16 @@ function composed2(compute, write, equals) {
|
|
|
179
179
|
composed2.batcher = factory("composed.batcher");
|
|
180
180
|
composed2.collector = factory("composed.collector");
|
|
181
181
|
var Composed = class extends Computed {
|
|
182
|
-
batcher;
|
|
183
|
-
|
|
182
|
+
#batcher;
|
|
183
|
+
#write;
|
|
184
184
|
constructor(empty, value, values, dependencies, listeners, batcher, collector3, compute, write, equals) {
|
|
185
185
|
super(empty, value, values, dependencies, listeners, collector3, compute, equals);
|
|
186
|
-
this
|
|
187
|
-
this
|
|
186
|
+
this.#batcher = batcher;
|
|
187
|
+
this.#write = write;
|
|
188
188
|
}
|
|
189
189
|
write(value) {
|
|
190
190
|
if (this.equals(value)) return;
|
|
191
|
-
batch(() => this
|
|
191
|
+
batch(() => this.#write(value), this.#batcher);
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
194
|
|
|
@@ -228,38 +228,38 @@ function signal2(value, equals) {
|
|
|
228
228
|
signal2.batcher = factory("signal.batcher");
|
|
229
229
|
signal2.collector = factory("signal.collector");
|
|
230
230
|
var Signal = class {
|
|
231
|
-
value;
|
|
232
|
-
|
|
233
|
-
listeners;
|
|
234
|
-
batcher;
|
|
235
|
-
collector;
|
|
231
|
+
#value;
|
|
232
|
+
#equals;
|
|
233
|
+
#listeners;
|
|
234
|
+
#batcher;
|
|
235
|
+
#collector;
|
|
236
236
|
constructor(value, equals, listeners, batcher, collector3) {
|
|
237
|
-
this
|
|
238
|
-
this
|
|
239
|
-
this
|
|
240
|
-
this
|
|
241
|
-
this
|
|
237
|
+
this.#value = value;
|
|
238
|
+
this.#equals = equals;
|
|
239
|
+
this.#listeners = listeners;
|
|
240
|
+
this.#batcher = batcher;
|
|
241
|
+
this.#collector = collector3;
|
|
242
242
|
}
|
|
243
243
|
read() {
|
|
244
|
-
this
|
|
245
|
-
return this
|
|
244
|
+
this.#collector.add(this);
|
|
245
|
+
return this.#value;
|
|
246
246
|
}
|
|
247
247
|
write(value) {
|
|
248
248
|
if (this.equals(value)) return;
|
|
249
|
-
this
|
|
250
|
-
if (this
|
|
251
|
-
else this
|
|
249
|
+
this.#value = value;
|
|
250
|
+
if (this.#batcher.collecting()) this.#listeners.forEach((listener) => this.#batcher.add(listener));
|
|
251
|
+
else this.#listeners.forEach((listener) => listener());
|
|
252
252
|
}
|
|
253
253
|
equals(other) {
|
|
254
|
-
if (this
|
|
255
|
-
return this
|
|
254
|
+
if (this.#equals) return this.#equals(this.#value, other);
|
|
255
|
+
return this.#value === other;
|
|
256
256
|
}
|
|
257
257
|
subscribe(callback) {
|
|
258
|
-
this
|
|
258
|
+
this.#listeners.add(callback);
|
|
259
259
|
return this.unsubscribe.bind(this, callback);
|
|
260
260
|
}
|
|
261
261
|
unsubscribe(callback) {
|
|
262
|
-
this
|
|
262
|
+
this.#listeners.delete(callback);
|
|
263
263
|
}
|
|
264
264
|
};
|
|
265
265
|
|
package/package.json
CHANGED