@adbl/cells 0.0.1 → 0.0.2
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/library/classes.js +49 -4
- package/package.json +1 -1
- package/types/library/classes.d.ts +2 -2
- package/adbl-cells-0.0.0.tgz +0 -0
package/library/classes.js
CHANGED
|
@@ -326,7 +326,7 @@ export class Cell {
|
|
|
326
326
|
update() {
|
|
327
327
|
// Run watchers.
|
|
328
328
|
for (const effect of this.__effects) {
|
|
329
|
-
|
|
329
|
+
const watcher = effect.callback;
|
|
330
330
|
if (watcher === undefined) continue;
|
|
331
331
|
|
|
332
332
|
if (root.batchNestingLevel > 0) {
|
|
@@ -593,6 +593,8 @@ export class Cell {
|
|
|
593
593
|
|
|
594
594
|
async function run(input = initialInput) {
|
|
595
595
|
pending.value = true;
|
|
596
|
+
error.value = null;
|
|
597
|
+
data.value = null;
|
|
596
598
|
try {
|
|
597
599
|
initialInput = input;
|
|
598
600
|
const result = await getter(/** @type {X} */ (input));
|
|
@@ -713,7 +715,7 @@ export class SourceCell extends Cell {
|
|
|
713
715
|
|
|
714
716
|
const isEqual = this.options.equals
|
|
715
717
|
? this.options.equals(oldValue, value)
|
|
716
|
-
: oldValue
|
|
718
|
+
: deepEqual(oldValue, value);
|
|
717
719
|
|
|
718
720
|
if (isEqual) return;
|
|
719
721
|
|
|
@@ -728,7 +730,7 @@ export class SourceCell extends Cell {
|
|
|
728
730
|
}
|
|
729
731
|
}
|
|
730
732
|
|
|
731
|
-
this.setValue(value);
|
|
733
|
+
this.setValue(this.options?.shallowProxied ? value : this.proxy(value));
|
|
732
734
|
this.update();
|
|
733
735
|
}
|
|
734
736
|
|
|
@@ -750,10 +752,53 @@ export class SourceCell extends Cell {
|
|
|
750
752
|
return this.proxy(Reflect.get(target, prop));
|
|
751
753
|
},
|
|
752
754
|
set: (target, prop, value) => {
|
|
755
|
+
const formerValue = Reflect.get(target, prop);
|
|
753
756
|
Reflect.set(target, prop, value);
|
|
754
|
-
|
|
757
|
+
|
|
758
|
+
const isEqual = deepEqual(formerValue, value);
|
|
759
|
+
if (!isEqual) this.update();
|
|
760
|
+
|
|
755
761
|
return true;
|
|
756
762
|
},
|
|
757
763
|
});
|
|
758
764
|
}
|
|
759
765
|
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Recursively compares two values for deep equality.
|
|
769
|
+
* @param {any} a - The first value to compare.
|
|
770
|
+
* @param {any} b - The second value to compare.
|
|
771
|
+
* @returns {boolean} - True if the values are deeply equal, false otherwise.
|
|
772
|
+
*/
|
|
773
|
+
function deepEqual(a, b) {
|
|
774
|
+
if (a === b) return true;
|
|
775
|
+
|
|
776
|
+
if (
|
|
777
|
+
typeof a !== typeof b ||
|
|
778
|
+
typeof a !== 'object' ||
|
|
779
|
+
a === null ||
|
|
780
|
+
b === null
|
|
781
|
+
)
|
|
782
|
+
return false;
|
|
783
|
+
|
|
784
|
+
if (Array.isArray(a)) {
|
|
785
|
+
const aLength = a.length;
|
|
786
|
+
if (!Array.isArray(b) || aLength !== b.length) return false;
|
|
787
|
+
|
|
788
|
+
for (let i = 0; i < aLength; i++) {
|
|
789
|
+
if (!deepEqual(a[i], b[i])) return false;
|
|
790
|
+
}
|
|
791
|
+
} else {
|
|
792
|
+
const keysA = Object.keys(a);
|
|
793
|
+
const keysB = Object.keys(b);
|
|
794
|
+
const keysALength = keysA.length;
|
|
795
|
+
if (keysALength !== keysB.length) return false;
|
|
796
|
+
|
|
797
|
+
for (let i = 0; i < keysALength; i++) {
|
|
798
|
+
const key = keysA[i];
|
|
799
|
+
if (a === b) return true;
|
|
800
|
+
if (!(key in b) || !deepEqual(a[key], b[key])) return false;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return true;
|
|
804
|
+
}
|
package/package.json
CHANGED
|
@@ -147,10 +147,10 @@ export class Cell<T> {
|
|
|
147
147
|
*/
|
|
148
148
|
protected __effects: Array<Effect<T>>;
|
|
149
149
|
/**
|
|
150
|
-
* @type {Array<WeakRef<
|
|
150
|
+
* @type {Array<[WeakRef<DerivedCell<any>>, () => any]>}
|
|
151
151
|
* @protected
|
|
152
152
|
*/
|
|
153
|
-
protected __derivedCells: Array<WeakRef<
|
|
153
|
+
protected __derivedCells: Array<[WeakRef<DerivedCell<any>>, () => any]>;
|
|
154
154
|
/**
|
|
155
155
|
* @readonly
|
|
156
156
|
*/
|
package/adbl-cells-0.0.0.tgz
DELETED
|
Binary file
|