aberdeen 1.0.11 → 1.0.12
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/README.md +1 -1
- package/dist/aberdeen.d.ts +38 -17
- package/dist/aberdeen.js +203 -34
- package/dist/aberdeen.js.map +3 -3
- package/dist/prediction.d.ts +2 -2
- package/dist/prediction.js.map +1 -1
- package/dist/route.js +2 -2
- package/dist/route.js.map +3 -3
- package/dist-min/aberdeen.js +5 -5
- package/dist-min/aberdeen.js.map +3 -3
- package/dist-min/prediction.js.map +1 -1
- package/dist-min/route.js +2 -2
- package/dist-min/route.js.map +3 -3
- package/html-to-aberdeen +354 -0
- package/package.json +2 -2
- package/src/aberdeen.ts +321 -99
- package/src/prediction.ts +4 -4
- package/src/route.ts +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Aberdeen's approach is refreshingly simple:
|
|
|
11
11
|
- 🎩 **Simple:** Express UIs naturally in JavaScript/TypeScript, without build steps or JSX, and with a minimal amount of concepts you need to learn.
|
|
12
12
|
- ⏩ **Fast:** No virtual DOM. Aberdeen intelligently updates only the minimal, necessary parts of your UI when proxied data changes.
|
|
13
13
|
- 👥 **Awesome lists**: It's very easy and performant to reactively display data sorted by whatever you like.
|
|
14
|
-
- 🔬 **Tiny:** Around
|
|
14
|
+
- 🔬 **Tiny:** Around 6KB (minimized and gzipped) and with zero runtime dependencies.
|
|
15
15
|
- 🔋 **Batteries included**: Comes with client-side routing, revertible patches for optimistic user-interface updates, component-local CSS, SVG support, helper functions for transforming reactive data (mapping, partitioning, filtering, etc) and hide/unhide transition effects. No bikeshedding required!
|
|
16
16
|
|
|
17
17
|
## Why *not* use Aberdeen?
|
package/dist/aberdeen.d.ts
CHANGED
|
@@ -30,14 +30,6 @@
|
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
export declare function runQueue(): void;
|
|
33
|
-
/**
|
|
34
|
-
* A sort key, as used by {@link onEach}, is a value that determines the order of items. It can
|
|
35
|
-
* be a number, string, or an array of numbers/strings. The sort key is used to sort items
|
|
36
|
-
* based on their values. The sort key can also be `undefined`, which indicates that the item
|
|
37
|
-
* should be ignored.
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
export type SortKeyType = number | string | Array<number | string> | undefined;
|
|
41
33
|
/**
|
|
42
34
|
* Creates a new string that has the opposite sort order compared to the input string.
|
|
43
35
|
*
|
|
@@ -66,7 +58,7 @@ export type SortKeyType = number | string | Array<number | string> | undefined;
|
|
|
66
58
|
* @see {@link onEach} for usage with sorting.
|
|
67
59
|
*/
|
|
68
60
|
export declare function invertString(input: string): string;
|
|
69
|
-
|
|
61
|
+
export declare function onEach<K, T>(target: Map<K, undefined | T>, render: (value: T, key: K) => void, makeKey?: (value: T, key: K) => SortKeyType): void;
|
|
70
62
|
export declare function onEach<T>(target: ReadonlyArray<undefined | T>, render: (value: T, index: number) => void, makeKey?: (value: T, index: number) => SortKeyType): void;
|
|
71
63
|
export declare function onEach<K extends string | number | symbol, T>(target: Record<K, undefined | T>, render: (value: T, index: KeyToString<K>) => void, makeKey?: (value: T, index: KeyToString<K>) => SortKeyType): void;
|
|
72
64
|
/**
|
|
@@ -133,9 +125,9 @@ export interface ValueRef<T> {
|
|
|
133
125
|
* ```
|
|
134
126
|
*/
|
|
135
127
|
export declare function count(proxied: TargetType): ValueRef<number>;
|
|
136
|
-
export declare function proxy<T extends
|
|
128
|
+
export declare function proxy<T extends any>(target: Array<T>): Array<T extends number ? number : T extends string ? string : T extends boolean ? boolean : T>;
|
|
137
129
|
export declare function proxy<T extends object>(target: T): T;
|
|
138
|
-
export declare function proxy<T extends
|
|
130
|
+
export declare function proxy<T extends any>(target: T): ValueRef<T extends number ? number : T extends string ? string : T extends boolean ? boolean : T>;
|
|
139
131
|
/**
|
|
140
132
|
* Returns the original, underlying data target from a reactive proxy created by {@link proxy}.
|
|
141
133
|
* If the input `target` is not a proxy, it is returned directly.
|
|
@@ -180,14 +172,17 @@ export declare function unproxy<T>(target: T): T;
|
|
|
180
172
|
* will recursively copy properties into the existing `dst` object instead of replacing it.
|
|
181
173
|
* This minimizes change notifications for reactive updates.
|
|
182
174
|
* - **Handles Proxies:** Can accept proxied or unproxied objects/arrays for both `dst` and `src`.
|
|
175
|
+
* - **Cross-Type Copying:** Supports copying between Maps and objects. When copying from an object
|
|
176
|
+
* to a Map, object properties become Map entries. When copying from a Map to an object, Map entries
|
|
177
|
+
* become object properties (only for Maps with string/number/symbol keys).
|
|
183
178
|
*
|
|
184
|
-
* @param dst - The destination object/array (proxied or unproxied).
|
|
185
|
-
* @param src - The source object/array (proxied or unproxied). It won't be modified.
|
|
179
|
+
* @param dst - The destination object/array/Map (proxied or unproxied).
|
|
180
|
+
* @param src - The source object/array/Map (proxied or unproxied). It won't be modified.
|
|
186
181
|
* @param flags - Bitmask controlling copy behavior:
|
|
187
182
|
* - {@link MERGE}: Performs a partial update. Properties in `dst` not present in `src` are kept.
|
|
188
183
|
* `null`/`undefined` in `src` delete properties in `dst`. Handles partial array updates via object keys.
|
|
189
184
|
* - {@link SHALLOW}: Performs a shallow copy; when an array/object of the right type doesn't exist in `dst` yet, a reference to the array/object in `src` will be made, instead of creating a copy. If the array/object already exists, it won't be replaced (by a reference), but all items will be individually checked and copied like normal, keeping changes (and therefore UI updates) to a minimum.
|
|
190
|
-
* @template T - The type of the
|
|
185
|
+
* @template T - The type of the destination object.
|
|
191
186
|
* @throws Error if attempting to copy an array into a non-array or vice versa (unless {@link MERGE} is set, allowing for sparse array updates).
|
|
192
187
|
*
|
|
193
188
|
* @example Basic Copy
|
|
@@ -198,6 +193,22 @@ export declare function unproxy<T>(target: T): T;
|
|
|
198
193
|
* console.log(dest); // proxy({ a: 1, b: { c: 2 } })
|
|
199
194
|
* ```
|
|
200
195
|
*
|
|
196
|
+
* @example Map to Object
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const source = new Map([['x', 3], ['y', 4]]);
|
|
199
|
+
* const dest = proxy({});
|
|
200
|
+
* copy(dest, source);
|
|
201
|
+
* console.log(dest); // proxy({ x: 3, y: 4 })
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @example Object to Map
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const source = { x: 3, y: 4 };
|
|
207
|
+
* const dest = proxy(new Map());
|
|
208
|
+
* copy(dest, source);
|
|
209
|
+
* console.log(dest); // proxy(Map([['x', 3], ['y', 4]]))
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
201
212
|
* @example MERGE
|
|
202
213
|
* ```typescript
|
|
203
214
|
* const source = { b: { c: 99 }, d: undefined }; // d: undefined will delete
|
|
@@ -223,6 +234,9 @@ export declare function unproxy<T>(target: T): T;
|
|
|
223
234
|
* console.log(source.nested); // [1, 2, 3] (source was modified)
|
|
224
235
|
* ```
|
|
225
236
|
*/
|
|
237
|
+
export declare function copy<K, V>(dst: Map<K, V>, src: Record<K extends string | number | symbol ? K : never, V> | Partial<Record<K extends string | number | symbol ? K : never, V>>, flags?: number): void;
|
|
238
|
+
export declare function copy<K, V>(dst: Map<K, V>, src: Map<K, V> | Partial<Map<K, V>>, flags?: number): void;
|
|
239
|
+
export declare function copy<T extends Record<string | number | symbol, any>>(dst: T, src: Map<keyof T, T[keyof T]>, flags?: number): void;
|
|
226
240
|
export declare function copy<T extends object>(dst: T, src: Partial<T>, flags?: number): void;
|
|
227
241
|
/** Flag to {@link copy} causing it to use merge semantics. See {@link copy} for details. */
|
|
228
242
|
export declare const MERGE = 1;
|
|
@@ -685,22 +699,30 @@ export declare function unmountAll(): void;
|
|
|
685
699
|
*
|
|
686
700
|
*/
|
|
687
701
|
export declare function peek<T>(func: () => T): T;
|
|
702
|
+
/** When using a Map as `source`. */
|
|
703
|
+
export declare function map<K, IN, OUT>(source: Map<K, IN>, func: (value: IN, key: K) => undefined | OUT): Map<K, OUT>;
|
|
688
704
|
/** When using an object as `source`. */
|
|
689
705
|
export declare function map<IN, const IN_KEY extends string | number | symbol, OUT>(source: Record<IN_KEY, IN>, func: (value: IN, index: KeyToString<IN_KEY>) => undefined | OUT): Record<string | symbol, OUT>;
|
|
690
706
|
/** When using an array as `source`. */
|
|
691
707
|
export declare function map<IN, OUT>(source: Array<IN>, func: (value: IN, index: number) => undefined | OUT): Array<OUT>;
|
|
692
708
|
/** When using an array as `source`. */
|
|
693
709
|
export declare function multiMap<IN, OUT extends {
|
|
694
|
-
[key: string | symbol]:
|
|
710
|
+
[key: string | symbol]: any;
|
|
695
711
|
}>(source: Array<IN>, func: (value: IN, index: number) => OUT | undefined): OUT;
|
|
696
712
|
/** When using an object as `source`. */
|
|
697
713
|
export declare function multiMap<K extends string | number | symbol, IN, OUT extends {
|
|
698
|
-
[key: string | symbol]:
|
|
714
|
+
[key: string | symbol]: any;
|
|
699
715
|
}>(source: Record<K, IN>, func: (value: IN, index: KeyToString<K>) => OUT | undefined): OUT;
|
|
716
|
+
/** When using a Map as `source`. */
|
|
717
|
+
export declare function multiMap<K, IN, OUT extends {
|
|
718
|
+
[key: string | symbol]: any;
|
|
719
|
+
}>(source: Map<K, IN>, func: (value: IN, key: K) => OUT | undefined): OUT;
|
|
700
720
|
/** When using an object as `array`. */
|
|
701
721
|
export declare function partition<OUT_K extends string | number | symbol, IN_V>(source: IN_V[], func: (value: IN_V, key: number) => undefined | OUT_K | OUT_K[]): Record<OUT_K, Record<number, IN_V>>;
|
|
702
722
|
/** When using an object as `source`. */
|
|
703
723
|
export declare function partition<IN_K extends string | number | symbol, OUT_K extends string | number | symbol, IN_V>(source: Record<IN_K, IN_V>, func: (value: IN_V, key: IN_K) => undefined | OUT_K | OUT_K[]): Record<OUT_K, Record<IN_K, IN_V>>;
|
|
724
|
+
/** When using a Map as `source`. */
|
|
725
|
+
export declare function partition<IN_K extends string | number | symbol, OUT_K extends string | number | symbol, IN_V>(source: Map<IN_K, IN_V>, func: (value: IN_V, key: IN_K) => undefined | OUT_K | OUT_K[]): Record<OUT_K, Record<IN_K, IN_V>>;
|
|
704
726
|
/**
|
|
705
727
|
* Renders a live, recursive dump of a proxied data structure (or any value)
|
|
706
728
|
* into the DOM at the current {@link $} insertion point.
|
|
@@ -729,4 +751,3 @@ export declare function partition<IN_K extends string | number | symbol, OUT_K e
|
|
|
729
751
|
* ```
|
|
730
752
|
*/
|
|
731
753
|
export declare function dump<T>(data: T): T;
|
|
732
|
-
export {};
|
package/dist/aberdeen.js
CHANGED
|
@@ -388,8 +388,8 @@ class OnEachScope extends Scope {
|
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
} else {
|
|
391
|
-
for (const key
|
|
392
|
-
if (
|
|
391
|
+
for (const [key, value] of getEntries(target)) {
|
|
392
|
+
if (value !== undefined) {
|
|
393
393
|
new OnEachItemScope(this, key, false);
|
|
394
394
|
}
|
|
395
395
|
}
|
|
@@ -410,7 +410,13 @@ class OnEachScope extends Scope {
|
|
|
410
410
|
const oldScope = this.byIndex.get(index);
|
|
411
411
|
if (oldScope)
|
|
412
412
|
oldScope.remove();
|
|
413
|
-
|
|
413
|
+
let hasValue;
|
|
414
|
+
if (this.target instanceof Map) {
|
|
415
|
+
hasValue = this.target.has(index);
|
|
416
|
+
} else {
|
|
417
|
+
hasValue = this.target[index] !== undefined;
|
|
418
|
+
}
|
|
419
|
+
if (!hasValue) {
|
|
414
420
|
this.byIndex.delete(index);
|
|
415
421
|
} else {
|
|
416
422
|
new OnEachItemScope(this, index, true);
|
|
@@ -490,17 +496,25 @@ class OnEachItemScope extends ContentScope {
|
|
|
490
496
|
topRedrawScope = undefined;
|
|
491
497
|
}
|
|
492
498
|
redraw() {
|
|
493
|
-
|
|
499
|
+
let value;
|
|
500
|
+
const target = this.parent.target;
|
|
501
|
+
let itemIndex = this.itemIndex;
|
|
502
|
+
if (target instanceof Map) {
|
|
503
|
+
value = optProxy(target.get(itemIndex));
|
|
504
|
+
itemIndex = optProxy(itemIndex);
|
|
505
|
+
} else {
|
|
506
|
+
value = optProxy(target[itemIndex]);
|
|
507
|
+
}
|
|
494
508
|
const savedScope = currentScope;
|
|
495
509
|
currentScope = this;
|
|
496
510
|
let sortKey;
|
|
497
511
|
try {
|
|
498
512
|
if (this.parent.makeSortKey) {
|
|
499
|
-
const rawSortKey = this.parent.makeSortKey(value,
|
|
513
|
+
const rawSortKey = this.parent.makeSortKey(value, itemIndex);
|
|
500
514
|
if (rawSortKey != null)
|
|
501
515
|
sortKey = rawSortKey instanceof Array ? rawSortKey.map(partToStr).join("") : rawSortKey;
|
|
502
516
|
} else {
|
|
503
|
-
sortKey =
|
|
517
|
+
sortKey = itemIndex;
|
|
504
518
|
}
|
|
505
519
|
if (typeof sortKey === "number")
|
|
506
520
|
sortKey = partToStr(sortKey);
|
|
@@ -509,7 +523,7 @@ class OnEachItemScope extends ContentScope {
|
|
|
509
523
|
this.sortKey = sortKey;
|
|
510
524
|
}
|
|
511
525
|
if (sortKey != null)
|
|
512
|
-
this.parent.renderer(value,
|
|
526
|
+
this.parent.renderer(value, itemIndex);
|
|
513
527
|
} catch (e) {
|
|
514
528
|
handleError(e, sortKey != null);
|
|
515
529
|
}
|
|
@@ -541,6 +555,7 @@ var ROOT_SCOPE = new RootScope;
|
|
|
541
555
|
var currentScope = ROOT_SCOPE;
|
|
542
556
|
var ANY_SYMBOL = Symbol("any");
|
|
543
557
|
var TARGET_SYMBOL = Symbol("target");
|
|
558
|
+
var MAP_SIZE_SYMBOL = Symbol("mapSize");
|
|
544
559
|
var subscribers = new WeakMap;
|
|
545
560
|
var peeking = 0;
|
|
546
561
|
function subscribe(target, index, observer = currentScope) {
|
|
@@ -586,6 +601,13 @@ function isEmpty(proxied) {
|
|
|
586
601
|
});
|
|
587
602
|
return !target.length;
|
|
588
603
|
}
|
|
604
|
+
if (target instanceof Map) {
|
|
605
|
+
subscribe(target, MAP_SIZE_SYMBOL, (index, newData, oldData) => {
|
|
606
|
+
if (!newData !== !oldData)
|
|
607
|
+
queue(scope);
|
|
608
|
+
});
|
|
609
|
+
return !target.size;
|
|
610
|
+
}
|
|
589
611
|
const result = isObjEmpty(target);
|
|
590
612
|
subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
|
|
591
613
|
if (result ? oldData === undefined : newData === undefined)
|
|
@@ -596,6 +618,8 @@ function isEmpty(proxied) {
|
|
|
596
618
|
function count(proxied) {
|
|
597
619
|
if (proxied instanceof Array)
|
|
598
620
|
return ref(proxied, "length");
|
|
621
|
+
if (proxied instanceof Map)
|
|
622
|
+
return ref(proxied, "size");
|
|
599
623
|
const target = proxied[TARGET_SYMBOL] || proxied;
|
|
600
624
|
let cnt = 0;
|
|
601
625
|
for (const k in target)
|
|
@@ -707,6 +731,88 @@ var arrayHandler = {
|
|
|
707
731
|
return arraySet(target, prop, undefined);
|
|
708
732
|
}
|
|
709
733
|
};
|
|
734
|
+
var mapMethodHandlers = {
|
|
735
|
+
get(key) {
|
|
736
|
+
const target = this[TARGET_SYMBOL];
|
|
737
|
+
subscribe(target, key);
|
|
738
|
+
return optProxy(target.get(key));
|
|
739
|
+
},
|
|
740
|
+
set(key, newData) {
|
|
741
|
+
const target = this[TARGET_SYMBOL];
|
|
742
|
+
if (typeof newData === "object" && newData)
|
|
743
|
+
newData = newData[TARGET_SYMBOL] || newData;
|
|
744
|
+
const oldData = target.get(key);
|
|
745
|
+
if (newData !== oldData) {
|
|
746
|
+
target.set(key, newData);
|
|
747
|
+
emit(target, key, newData, oldData);
|
|
748
|
+
emit(target, MAP_SIZE_SYMBOL, target.size, target.size - (oldData === undefined ? 1 : 0));
|
|
749
|
+
runImmediateQueue();
|
|
750
|
+
}
|
|
751
|
+
return this;
|
|
752
|
+
},
|
|
753
|
+
delete(key) {
|
|
754
|
+
const target = this[TARGET_SYMBOL];
|
|
755
|
+
const oldData = target.get(key);
|
|
756
|
+
const result = target.delete(key);
|
|
757
|
+
if (result) {
|
|
758
|
+
emit(target, key, undefined, oldData);
|
|
759
|
+
emit(target, MAP_SIZE_SYMBOL, target.size, target.size + 1);
|
|
760
|
+
runImmediateQueue();
|
|
761
|
+
}
|
|
762
|
+
return result;
|
|
763
|
+
},
|
|
764
|
+
clear() {
|
|
765
|
+
const target = this[TARGET_SYMBOL];
|
|
766
|
+
const oldSize = target.size;
|
|
767
|
+
for (const key of target.keys()) {
|
|
768
|
+
const oldData = target.get(key);
|
|
769
|
+
emit(target, key, undefined, oldData);
|
|
770
|
+
}
|
|
771
|
+
target.clear();
|
|
772
|
+
emit(target, MAP_SIZE_SYMBOL, 0, oldSize);
|
|
773
|
+
runImmediateQueue();
|
|
774
|
+
},
|
|
775
|
+
has(key) {
|
|
776
|
+
const target = this[TARGET_SYMBOL];
|
|
777
|
+
subscribe(target, key);
|
|
778
|
+
return target.has(key);
|
|
779
|
+
},
|
|
780
|
+
keys() {
|
|
781
|
+
const target = this[TARGET_SYMBOL];
|
|
782
|
+
subscribe(target, ANY_SYMBOL);
|
|
783
|
+
return target.keys();
|
|
784
|
+
},
|
|
785
|
+
values() {
|
|
786
|
+
const target = this[TARGET_SYMBOL];
|
|
787
|
+
subscribe(target, ANY_SYMBOL);
|
|
788
|
+
return target.values();
|
|
789
|
+
},
|
|
790
|
+
entries() {
|
|
791
|
+
const target = this[TARGET_SYMBOL];
|
|
792
|
+
subscribe(target, ANY_SYMBOL);
|
|
793
|
+
return target.entries();
|
|
794
|
+
},
|
|
795
|
+
[Symbol.iterator]() {
|
|
796
|
+
const target = this[TARGET_SYMBOL];
|
|
797
|
+
subscribe(target, ANY_SYMBOL);
|
|
798
|
+
return target[Symbol.iterator]();
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
var mapHandler = {
|
|
802
|
+
get(target, prop) {
|
|
803
|
+
if (prop === TARGET_SYMBOL)
|
|
804
|
+
return target;
|
|
805
|
+
if (prop in mapMethodHandlers) {
|
|
806
|
+
return mapMethodHandlers[prop];
|
|
807
|
+
}
|
|
808
|
+
if (prop === "size") {
|
|
809
|
+
subscribe(target, MAP_SIZE_SYMBOL);
|
|
810
|
+
return target.size;
|
|
811
|
+
}
|
|
812
|
+
subscribe(target, prop);
|
|
813
|
+
return optProxy(target[prop]);
|
|
814
|
+
}
|
|
815
|
+
};
|
|
710
816
|
var proxyMap = new WeakMap;
|
|
711
817
|
function optProxy(value) {
|
|
712
818
|
if (typeof value !== "object" || !value || value[TARGET_SYMBOL] !== undefined) {
|
|
@@ -715,7 +821,15 @@ function optProxy(value) {
|
|
|
715
821
|
let proxied = proxyMap.get(value);
|
|
716
822
|
if (proxied)
|
|
717
823
|
return proxied;
|
|
718
|
-
|
|
824
|
+
let handler;
|
|
825
|
+
if (value instanceof Array) {
|
|
826
|
+
handler = arrayHandler;
|
|
827
|
+
} else if (value instanceof Map) {
|
|
828
|
+
handler = mapHandler;
|
|
829
|
+
} else {
|
|
830
|
+
handler = objectHandler;
|
|
831
|
+
}
|
|
832
|
+
proxied = new Proxy(value, handler);
|
|
719
833
|
proxyMap.set(value, proxied);
|
|
720
834
|
return proxied;
|
|
721
835
|
}
|
|
@@ -740,10 +854,21 @@ var SHALLOW = 2;
|
|
|
740
854
|
var COPY_SUBSCRIBE = 32;
|
|
741
855
|
var COPY_EMIT = 64;
|
|
742
856
|
function clone(src, flags = 0) {
|
|
743
|
-
|
|
857
|
+
let dst;
|
|
858
|
+
if (src instanceof Map) {
|
|
859
|
+
dst = new Map;
|
|
860
|
+
} else {
|
|
861
|
+
dst = Object.create(Object.getPrototypeOf(src));
|
|
862
|
+
}
|
|
744
863
|
copyRecurse(dst, src, flags);
|
|
745
864
|
return dst;
|
|
746
865
|
}
|
|
866
|
+
function getEntries(subject) {
|
|
867
|
+
return subject instanceof Map ? subject.entries() : Object.entries(subject);
|
|
868
|
+
}
|
|
869
|
+
function getKeys(subject) {
|
|
870
|
+
return subject instanceof Map ? subject.keys() : Object.keys(subject);
|
|
871
|
+
}
|
|
747
872
|
function copyRecurse(dst, src, flags) {
|
|
748
873
|
let unproxied = dst[TARGET_SYMBOL];
|
|
749
874
|
if (unproxied) {
|
|
@@ -764,7 +889,7 @@ function copyRecurse(dst, src, flags) {
|
|
|
764
889
|
const dstLen = dst.length;
|
|
765
890
|
const srcLen = src.length;
|
|
766
891
|
for (let i = 0;i < srcLen; i++) {
|
|
767
|
-
copyValue(dst,
|
|
892
|
+
copyValue(dst, i, src[i], flags);
|
|
768
893
|
}
|
|
769
894
|
if (srcLen !== dstLen) {
|
|
770
895
|
if (flags & COPY_EMIT) {
|
|
@@ -780,25 +905,41 @@ function copyRecurse(dst, src, flags) {
|
|
|
780
905
|
}
|
|
781
906
|
}
|
|
782
907
|
} else {
|
|
783
|
-
for (const
|
|
784
|
-
copyValue(dst,
|
|
908
|
+
for (const [key, value] of getEntries(src)) {
|
|
909
|
+
copyValue(dst, key, value, flags);
|
|
785
910
|
}
|
|
786
911
|
if (!(flags & MERGE)) {
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
912
|
+
if (src instanceof Map) {
|
|
913
|
+
for (const key of getKeys(dst)) {
|
|
914
|
+
if (!src.has(key)) {
|
|
915
|
+
deleteKey(dst, key, flags);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
} else {
|
|
919
|
+
for (const key of getKeys(dst)) {
|
|
920
|
+
if (!(key in src)) {
|
|
921
|
+
deleteKey(dst, key, flags);
|
|
793
922
|
}
|
|
794
923
|
}
|
|
795
924
|
}
|
|
796
925
|
}
|
|
797
926
|
}
|
|
798
927
|
}
|
|
799
|
-
function
|
|
800
|
-
|
|
801
|
-
|
|
928
|
+
function deleteKey(dst, key, flags) {
|
|
929
|
+
let old;
|
|
930
|
+
if (dst instanceof Map) {
|
|
931
|
+
old = dst.get(key);
|
|
932
|
+
dst.delete(key);
|
|
933
|
+
} else {
|
|
934
|
+
old = dst[key];
|
|
935
|
+
delete dst[key];
|
|
936
|
+
}
|
|
937
|
+
if (flags & COPY_EMIT && old !== undefined) {
|
|
938
|
+
emit(dst, key, undefined, old);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
function copyValue(dst, index, srcValue, flags) {
|
|
942
|
+
const dstValue = dst instanceof Map ? dst.get(index) : dst[index];
|
|
802
943
|
if (srcValue !== dstValue) {
|
|
803
944
|
if (srcValue && dstValue && typeof srcValue === "object" && typeof dstValue === "object" && (srcValue.constructor === dstValue.constructor || flags & MERGE && dstValue instanceof Array)) {
|
|
804
945
|
copyRecurse(dstValue, srcValue, flags);
|
|
@@ -809,13 +950,19 @@ function copyValue(dst, src, index, flags) {
|
|
|
809
950
|
copyRecurse(copy2, srcValue, 0);
|
|
810
951
|
srcValue = copy2;
|
|
811
952
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
953
|
+
if (dst instanceof Map) {
|
|
954
|
+
if (flags & MERGE && srcValue == null)
|
|
955
|
+
dst.delete(index);
|
|
956
|
+
else
|
|
957
|
+
dst.set(index, srcValue);
|
|
958
|
+
} else {
|
|
959
|
+
if (flags & MERGE && srcValue == null)
|
|
960
|
+
delete dst[index];
|
|
961
|
+
else
|
|
962
|
+
dst[index] = srcValue;
|
|
963
|
+
}
|
|
817
964
|
if (flags & COPY_EMIT)
|
|
818
|
-
emit(dst, index, srcValue,
|
|
965
|
+
emit(dst, index, srcValue, dstValue);
|
|
819
966
|
}
|
|
820
967
|
}
|
|
821
968
|
var refHandler = {
|
|
@@ -1105,14 +1252,28 @@ function peek(func) {
|
|
|
1105
1252
|
}
|
|
1106
1253
|
}
|
|
1107
1254
|
function map(source, func) {
|
|
1108
|
-
|
|
1255
|
+
let out;
|
|
1256
|
+
if (source instanceof Array) {
|
|
1257
|
+
out = optProxy([]);
|
|
1258
|
+
} else if (source instanceof Map) {
|
|
1259
|
+
out = optProxy(new Map);
|
|
1260
|
+
} else {
|
|
1261
|
+
out = optProxy({});
|
|
1262
|
+
}
|
|
1109
1263
|
onEach(source, (item, key) => {
|
|
1110
1264
|
const value = func(item, key);
|
|
1111
1265
|
if (value !== undefined) {
|
|
1112
|
-
out
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1266
|
+
if (out instanceof Map) {
|
|
1267
|
+
out.set(key, value);
|
|
1268
|
+
clean(() => {
|
|
1269
|
+
out.delete(key);
|
|
1270
|
+
});
|
|
1271
|
+
} else {
|
|
1272
|
+
out[key] = value;
|
|
1273
|
+
clean(() => {
|
|
1274
|
+
delete out[key];
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1116
1277
|
}
|
|
1117
1278
|
});
|
|
1118
1279
|
return out;
|
|
@@ -1160,7 +1321,15 @@ function partition(source, func) {
|
|
|
1160
1321
|
}
|
|
1161
1322
|
function dump(data) {
|
|
1162
1323
|
if (data && typeof data === "object") {
|
|
1163
|
-
|
|
1324
|
+
let label;
|
|
1325
|
+
if (data instanceof Array) {
|
|
1326
|
+
label = "<array>";
|
|
1327
|
+
} else if (data instanceof Map) {
|
|
1328
|
+
label = "<Map>";
|
|
1329
|
+
} else {
|
|
1330
|
+
label = "<object>";
|
|
1331
|
+
}
|
|
1332
|
+
$({ text: label });
|
|
1164
1333
|
$("ul", () => {
|
|
1165
1334
|
onEach(data, (value, key) => {
|
|
1166
1335
|
$(`li:${JSON.stringify(key)}: `, () => {
|
|
@@ -1228,5 +1397,5 @@ export {
|
|
|
1228
1397
|
$
|
|
1229
1398
|
};
|
|
1230
1399
|
|
|
1231
|
-
//# debugId=
|
|
1400
|
+
//# debugId=273356BBA2542BE564756E2164756E21
|
|
1232
1401
|
//# sourceMappingURL=aberdeen.js.map
|