informa 5.0.9 → 5.0.11
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/EventEmitter.d.ts +34 -0
- package/dist/EventEmitter.d.ts.map +1 -0
- package/dist/EventEmitter.js +184 -0
- package/dist/EventEmitter.js.map +1 -0
- package/dist/high.js +3 -3
- package/dist/high.js.map +1 -1
- package/dist/low.d.ts +3 -3
- package/dist/low.d.ts.map +1 -1
- package/dist/low.js +73 -106
- package/dist/low.js.map +1 -1
- package/dist/quirks/basestatified.d.ts.map +1 -1
- package/dist/quirks/basestatified.js +5 -1
- package/dist/quirks/basestatified.js.map +1 -1
- package/dist/quirks/map.d.ts.map +1 -1
- package/dist/quirks/map.js +6 -1
- package/dist/quirks/map.js.map +1 -1
- package/dist/quirks/set.d.ts.map +1 -1
- package/dist/quirks/set.js +6 -1
- package/dist/quirks/set.js.map +1 -1
- package/package.json +1 -1
- package/src/EventEmitter.ts +220 -0
- package/src/high.ts +3 -3
- package/src/low.ts +84 -74
- package/src/quirks/basestatified.ts +7 -2
- package/src/quirks/map.ts +7 -1
- package/src/quirks/set.ts +7 -1
package/src/low.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { exitProxySymbol, getGlobalStateMode, getMetadataOf, isStatifiedArrayKey, isStatifiedMapKey, isStatifiedSetKey, proxyMemoized, setGlobalStateMode, setMetadataOf, statifySealKey, type Statify } from "./internals.js";
|
|
2
|
-
import { EventEmitter } from "
|
|
2
|
+
import { EventEmitter } from "./EventEmitter.js";
|
|
3
3
|
import { StatifiedSet } from "./quirks/set.js";
|
|
4
4
|
import { isListInGrid } from "./utils.js";
|
|
5
5
|
import { EnumerableWeakMap } from "./EnumerableWeakMap.js";
|
|
@@ -107,8 +107,6 @@ export class StateMetadata extends EventEmitter<ProxyEventEmitterEvents> {
|
|
|
107
107
|
eventName: string | E,
|
|
108
108
|
...args: E extends string
|
|
109
109
|
? ProxyEventEmitterEvents[E]
|
|
110
|
-
: E extends keyof EventEmitter.EventEmitterEventMap
|
|
111
|
-
? EventEmitter.EventEmitterEventMap[E]
|
|
112
110
|
: any[]
|
|
113
111
|
): boolean {
|
|
114
112
|
let result = super.emit(eventName, ...args);
|
|
@@ -129,7 +127,10 @@ export class StateMetadata extends EventEmitter<ProxyEventEmitterEvents> {
|
|
|
129
127
|
else seen.set(ancestor, [path]);
|
|
130
128
|
|
|
131
129
|
const target = ancestor.eventEmitterAtPathMaybe(path);
|
|
132
|
-
if (target)
|
|
130
|
+
if (target) {
|
|
131
|
+
const targetResult = target.emitAt(path, eventName, ...args);
|
|
132
|
+
result = targetResult || result;
|
|
133
|
+
}
|
|
133
134
|
|
|
134
135
|
ancestor.#pushParents(queue, path);
|
|
135
136
|
}
|
|
@@ -158,90 +159,99 @@ export type Statified<T extends StatifiableProp> = T extends object
|
|
|
158
159
|
: Statify<{ [K in keyof T]: Statified<T[K]> }>
|
|
159
160
|
: T;
|
|
160
161
|
|
|
161
|
-
export function emitCollectionTransition(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
162
|
+
export function emitCollectionTransition(
|
|
163
|
+
oldVal: unknown,
|
|
164
|
+
nextVal: unknown,
|
|
165
|
+
emitter?: StateMetadata | null,
|
|
166
|
+
prop?: string | symbol,
|
|
167
|
+
): void {
|
|
168
|
+
if (!emitter || oldVal === nextVal) return;
|
|
169
|
+
|
|
170
|
+
const emit = (event: string, ...args: any[]) => {
|
|
171
|
+
if (prop !== undefined) {
|
|
172
|
+
emitter.emitAt([prop], event, ...args);
|
|
173
|
+
} else {
|
|
174
|
+
emitter.emit(event as any, ...args);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const oldIsSet = Boolean(oldVal && typeof oldVal === "object" && (oldVal as any)[isStatifiedSetKey]);
|
|
179
|
+
const nextIsSet = Boolean(nextVal && typeof nextVal === "object" && (nextVal as any)[isStatifiedSetKey]);
|
|
180
|
+
if (oldIsSet || nextIsSet) {
|
|
181
|
+
const oldSet = oldIsSet ? (oldVal as Set<unknown>) : undefined;
|
|
182
|
+
const nextSet = nextIsSet ? (nextVal as Set<unknown>) : undefined;
|
|
173
183
|
let changed = false;
|
|
174
|
-
|
|
175
|
-
|
|
184
|
+
|
|
185
|
+
if (oldSet) {
|
|
186
|
+
for (const item of oldSet) {
|
|
187
|
+
if (!nextSet?.has(item)) {
|
|
188
|
+
emit("deleteItem", item);
|
|
189
|
+
changed = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
176
192
|
}
|
|
177
|
-
|
|
178
|
-
|
|
193
|
+
if (nextSet) {
|
|
194
|
+
for (const item of nextSet) {
|
|
195
|
+
if (!oldSet?.has(item)) {
|
|
196
|
+
emit("addItem", item);
|
|
197
|
+
changed = true;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
179
200
|
}
|
|
180
|
-
if (changed)
|
|
201
|
+
if (changed) emit("cardChanged");
|
|
181
202
|
return;
|
|
182
|
-
} else if (oldIsSet) {
|
|
183
|
-
const oldSet = old as StatifiedSet<unknown>;
|
|
184
|
-
const oldMeta = getMetadataOf(oldSet as Statify<{}>);
|
|
185
|
-
let changed = false;
|
|
186
|
-
for (const item of oldSet) { oldMeta.emit("deleteItem", item); changed = true; }
|
|
187
|
-
if (changed) oldMeta.emit("cardChanged");
|
|
188
|
-
} else if (nextIsSet) {
|
|
189
|
-
const nextSet = next as StatifiedSet<unknown>;
|
|
190
|
-
const nextMeta = getMetadataOf(nextSet as Statify<{}>);
|
|
191
|
-
let changed = false;
|
|
192
|
-
for (const item of nextSet) { nextMeta.emit("addItem", item); changed = true; }
|
|
193
|
-
if (changed) nextMeta.emit("cardChanged");
|
|
194
203
|
}
|
|
195
204
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
205
|
+
const oldIsMap = Boolean(oldVal && typeof oldVal === "object" && (oldVal as any)[isStatifiedMapKey]);
|
|
206
|
+
const nextIsMap = Boolean(nextVal && typeof nextVal === "object" && (nextVal as any)[isStatifiedMapKey]);
|
|
207
|
+
if (oldIsMap || nextIsMap) {
|
|
208
|
+
const oldMap = oldIsMap ? (oldVal as Map<unknown, unknown>) : undefined;
|
|
209
|
+
const nextMap = nextIsMap ? (nextVal as Map<unknown, unknown>) : undefined;
|
|
210
|
+
let changed = false;
|
|
211
|
+
|
|
212
|
+
if (oldMap) {
|
|
213
|
+
for (const [k, v] of oldMap) {
|
|
214
|
+
if (!nextMap?.has(k)) {
|
|
215
|
+
emit("deleteEntry", k, v);
|
|
216
|
+
changed = true;
|
|
217
|
+
} else if (nextMap.get(k) !== v) {
|
|
218
|
+
emit("replaceEntry", k, nextMap.get(k));
|
|
219
|
+
emit("setEntry", k, nextMap.get(k));
|
|
220
|
+
changed = true;
|
|
203
221
|
}
|
|
204
|
-
oldMeta.emit("lengthChanged");
|
|
205
222
|
}
|
|
206
223
|
}
|
|
207
|
-
if (
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
224
|
+
if (nextMap) {
|
|
225
|
+
for (const [k, v] of nextMap) {
|
|
226
|
+
if (!oldMap?.has(k)) {
|
|
227
|
+
emit("addEntry", k, v);
|
|
228
|
+
emit("setEntry", k, v);
|
|
229
|
+
changed = true;
|
|
213
230
|
}
|
|
214
|
-
nextMeta.emit("lengthChanged");
|
|
215
231
|
}
|
|
216
232
|
}
|
|
233
|
+
if (changed) emit("sizeChanged");
|
|
234
|
+
return;
|
|
217
235
|
}
|
|
218
236
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
237
|
+
const oldIsArray = Boolean(oldVal && typeof oldVal === "object" && (oldVal as any)[isStatifiedArrayKey]);
|
|
238
|
+
const nextIsArray = Boolean(nextVal && typeof nextVal === "object" && (nextVal as any)[isStatifiedArrayKey]);
|
|
239
|
+
if (oldIsArray || nextIsArray) {
|
|
240
|
+
const oldArr = oldIsArray ? (oldVal as unknown[]) : undefined;
|
|
241
|
+
const nextArr = nextIsArray ? (nextVal as unknown[]) : undefined;
|
|
242
|
+
|
|
243
|
+
if (oldArr && oldArr.length > 0) {
|
|
244
|
+
for (let i = oldArr.length - 1; i >= 0; i--) {
|
|
245
|
+
emit("spliceOutElement", oldArr[i], i);
|
|
246
|
+
}
|
|
247
|
+
emit("lengthChanged");
|
|
227
248
|
}
|
|
228
|
-
|
|
229
|
-
|
|
249
|
+
if (nextArr && nextArr.length > 0) {
|
|
250
|
+
for (let i = 0; i < nextArr.length; i++) {
|
|
251
|
+
emit("spliceInElement", nextArr[i], i);
|
|
252
|
+
}
|
|
253
|
+
emit("lengthChanged");
|
|
230
254
|
}
|
|
231
|
-
if (changed) oldMeta.emit("sizeChanged");
|
|
232
|
-
return;
|
|
233
|
-
} else if (oldIsMap) {
|
|
234
|
-
const oldMap = old as StatifiedMap<unknown, unknown>;
|
|
235
|
-
const oldMeta = getMetadataOf(oldMap as Statify<{}>);
|
|
236
|
-
let changed = false;
|
|
237
|
-
for (const [k, v] of oldMap) { oldMeta.emit("deleteEntry", k, v); changed = true; }
|
|
238
|
-
if (changed) oldMeta.emit("sizeChanged");
|
|
239
|
-
} else if (nextIsMap) {
|
|
240
|
-
const nextMap = next as StatifiedMap<unknown, unknown>;
|
|
241
|
-
const nextMeta = getMetadataOf(nextMap as Statify<{}>);
|
|
242
|
-
let changed = false;
|
|
243
|
-
for (const [k, v] of nextMap) { nextMeta.emit("addEntry", k, v); nextMeta.emit("setEntry", k, v); changed = true; }
|
|
244
|
-
if (changed) nextMeta.emit("sizeChanged");
|
|
245
255
|
}
|
|
246
256
|
}
|
|
247
257
|
|
|
@@ -303,8 +313,6 @@ export function statifyObject<T extends { [k: string | symbol]: Statified<Statif
|
|
|
303
313
|
unhook(stateMetadata, prop, oldValMetadata);
|
|
304
314
|
}
|
|
305
315
|
|
|
306
|
-
emitCollectionTransition(oldVal, newVal);
|
|
307
|
-
|
|
308
316
|
if (
|
|
309
317
|
typeof prop !== "symbol" &&
|
|
310
318
|
Number.isInteger(Number(prop)) &&
|
|
@@ -326,6 +334,8 @@ export function statifyObject<T extends { [k: string | symbol]: Statified<Statif
|
|
|
326
334
|
stateMetadata.emit('addProp', newVal, prop);
|
|
327
335
|
}
|
|
328
336
|
|
|
337
|
+
emitCollectionTransition(oldVal, newVal, stateMetadata.eventEmitterAtPathMaybe([prop]), prop);
|
|
338
|
+
|
|
329
339
|
stateMetadata.emit('setProp', newVal, prop);
|
|
330
340
|
|
|
331
341
|
const maybeEventEmitterAtVal = stateMetadata.eventEmitterAtPathMaybe([prop]);
|
|
@@ -103,6 +103,11 @@ export function makeStatified<
|
|
|
103
103
|
|
|
104
104
|
return result;
|
|
105
105
|
},
|
|
106
|
+
|
|
107
|
+
has(target, p) {
|
|
108
|
+
const dataLayer = getDataLayer(inst);
|
|
109
|
+
return Reflect.has(dataLayer, p) || Reflect.has(target, p);
|
|
110
|
+
},
|
|
106
111
|
});
|
|
107
112
|
|
|
108
113
|
if (!dataLayers.has(inst)) {
|
|
@@ -169,8 +174,6 @@ export function makeStatified<
|
|
|
169
174
|
unhook(stateMetadata, prop, oldValMetadata);
|
|
170
175
|
}
|
|
171
176
|
|
|
172
|
-
emitCollectionTransition(oldVal, newVal);
|
|
173
|
-
|
|
174
177
|
if (
|
|
175
178
|
typeof prop !== "symbol" &&
|
|
176
179
|
Number.isInteger(Number(prop)) &&
|
|
@@ -192,6 +195,8 @@ export function makeStatified<
|
|
|
192
195
|
stateMetadata.emit('addProp', newVal, prop);
|
|
193
196
|
}
|
|
194
197
|
|
|
198
|
+
emitCollectionTransition(oldVal, newVal, stateMetadata.eventEmitterAtPathMaybe([prop]), prop);
|
|
199
|
+
|
|
195
200
|
stateMetadata.emit('setProp', newVal, prop);
|
|
196
201
|
|
|
197
202
|
const maybeEventEmitterAtVal = stateMetadata.eventEmitterAtPathMaybe([prop]);
|
package/src/quirks/map.ts
CHANGED
|
@@ -13,9 +13,15 @@ export class StatifiedMap<K, V> extends Map<K, V> implements Statify<Map<K, V>>
|
|
|
13
13
|
#metadata: StateMetadata;
|
|
14
14
|
|
|
15
15
|
constructor(args?: Iterable<[K, V]> | null) {
|
|
16
|
-
super(
|
|
16
|
+
super();
|
|
17
17
|
|
|
18
18
|
this.#metadata = setMetadataOf(this, new StateMetadata());
|
|
19
|
+
|
|
20
|
+
if (args) {
|
|
21
|
+
for (const [key, value] of args) {
|
|
22
|
+
super.set(key, value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
clear(): void {
|
package/src/quirks/set.ts
CHANGED
|
@@ -13,9 +13,15 @@ export class StatifiedSet<T extends StatifiableProp> extends Set<T> implements S
|
|
|
13
13
|
#metadata: StateMetadata;
|
|
14
14
|
|
|
15
15
|
constructor(args?: Iterable<T> | null) {
|
|
16
|
-
super(
|
|
16
|
+
super();
|
|
17
17
|
|
|
18
18
|
this.#metadata = setMetadataOf(this, new StateMetadata());
|
|
19
|
+
|
|
20
|
+
if (args) {
|
|
21
|
+
for (const item of args) {
|
|
22
|
+
super.add(item);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
add(value: T): this {
|