@legendapp/state 3.0.0-alpha.18 → 3.0.0-alpha.19
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/index.js +19 -14
- package/index.mjs +19 -14
- package/package.json +1 -1
- package/sync-plugins/crud.js +6 -1
- package/sync-plugins/crud.mjs +6 -1
- package/sync-plugins/keel.js +0 -2
- package/sync-plugins/keel.mjs +0 -2
package/index.js
CHANGED
|
@@ -572,6 +572,7 @@ function computeChangesAtNode(changesInBatch, node, isFromPersist, isFromSync, v
|
|
|
572
572
|
const { changes } = changeInBatch;
|
|
573
573
|
if (!isArraySubset(changes[0].path, change.path)) {
|
|
574
574
|
changes.push(change);
|
|
575
|
+
changeInBatch.level = Math.min(changeInBatch.level, level);
|
|
575
576
|
}
|
|
576
577
|
} else {
|
|
577
578
|
changesInBatch.set(node, {
|
|
@@ -1001,12 +1002,17 @@ function observe(selectorOrRun, reactionOrOptions, options) {
|
|
|
1001
1002
|
options = reactionOrOptions;
|
|
1002
1003
|
}
|
|
1003
1004
|
let dispose;
|
|
1005
|
+
let isRunning = false;
|
|
1004
1006
|
const e = { num: 0 };
|
|
1005
1007
|
const update = function() {
|
|
1008
|
+
if (isRunning) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1006
1011
|
if (e.onCleanup) {
|
|
1007
1012
|
e.onCleanup();
|
|
1008
1013
|
e.onCleanup = void 0;
|
|
1009
1014
|
}
|
|
1015
|
+
isRunning = true;
|
|
1010
1016
|
beginBatch();
|
|
1011
1017
|
delete e.value;
|
|
1012
1018
|
dispose == null ? void 0 : dispose();
|
|
@@ -1020,6 +1026,7 @@ function observe(selectorOrRun, reactionOrOptions, options) {
|
|
|
1020
1026
|
e.onCleanupReaction = void 0;
|
|
1021
1027
|
}
|
|
1022
1028
|
endBatch();
|
|
1029
|
+
isRunning = false;
|
|
1023
1030
|
if (reaction && ((options == null ? void 0 : options.fromComputed) || (e.num > 0 || !isEvent(selectorOrRun)) && (e.previous !== e.value || typeof e.value === "object"))) {
|
|
1024
1031
|
reaction(e);
|
|
1025
1032
|
}
|
|
@@ -1565,8 +1572,10 @@ function setKey(node, key, newValue, level) {
|
|
|
1565
1572
|
parent.recursivelyAutoActivated = false;
|
|
1566
1573
|
} while (parent = parent.parent);
|
|
1567
1574
|
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1575
|
+
const notify2 = !equals(savedValue, prevValue);
|
|
1576
|
+
const forceNotify = !notify2 && childNode.isComputing && isObject(savedValue);
|
|
1577
|
+
if (notify2 || forceNotify) {
|
|
1578
|
+
updateNodesAndNotify(node, savedValue, prevValue, childNode, isPrim, isRoot, level, forceNotify);
|
|
1570
1579
|
}
|
|
1571
1580
|
extractFunctionOrComputed(node, key, savedValue);
|
|
1572
1581
|
}
|
|
@@ -1679,20 +1688,20 @@ function handlerMapSet(node, p, value) {
|
|
|
1679
1688
|
};
|
|
1680
1689
|
}
|
|
1681
1690
|
}
|
|
1682
|
-
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level) {
|
|
1691
|
+
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level, forceNotify) {
|
|
1683
1692
|
if (!childNode)
|
|
1684
1693
|
childNode = node;
|
|
1685
1694
|
beginBatch();
|
|
1686
1695
|
if (isPrim === void 0) {
|
|
1687
1696
|
isPrim = isPrimitive(newValue);
|
|
1688
1697
|
}
|
|
1689
|
-
let hasADiff = isPrim;
|
|
1698
|
+
let hasADiff = forceNotify || isPrim;
|
|
1690
1699
|
let whenOptimizedOnlyIf = false;
|
|
1691
1700
|
if (!isPrim || prevValue && !isPrimitive(prevValue)) {
|
|
1692
1701
|
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined") {
|
|
1693
1702
|
__devUpdateNodes.clear();
|
|
1694
1703
|
}
|
|
1695
|
-
hasADiff = updateNodes(childNode, newValue, prevValue);
|
|
1704
|
+
hasADiff = hasADiff || updateNodes(childNode, newValue, prevValue);
|
|
1696
1705
|
if (isArray(newValue)) {
|
|
1697
1706
|
whenOptimizedOnlyIf = (newValue == null ? void 0 : newValue.length) !== (prevValue == null ? void 0 : prevValue.length);
|
|
1698
1707
|
}
|
|
@@ -1962,18 +1971,14 @@ function activateNodeFunction(node, lazyFn) {
|
|
|
1962
1971
|
}
|
|
1963
1972
|
} else {
|
|
1964
1973
|
activatedValue = value;
|
|
1965
|
-
|
|
1974
|
+
const isLoaded = node.state.isLoaded.peek();
|
|
1975
|
+
if (isLoaded || !isFunction(value)) {
|
|
1966
1976
|
node.isComputing = true;
|
|
1967
1977
|
set(node, value);
|
|
1968
1978
|
node.isComputing = false;
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
}
|
|
1973
|
-
node.state.assign({
|
|
1974
|
-
isLoaded: true,
|
|
1975
|
-
error: void 0
|
|
1976
|
-
});
|
|
1979
|
+
}
|
|
1980
|
+
if (!isLoaded) {
|
|
1981
|
+
node.state.assign({ isLoaded: true, error: void 0 });
|
|
1977
1982
|
}
|
|
1978
1983
|
}
|
|
1979
1984
|
}
|
package/index.mjs
CHANGED
|
@@ -570,6 +570,7 @@ function computeChangesAtNode(changesInBatch, node, isFromPersist, isFromSync, v
|
|
|
570
570
|
const { changes } = changeInBatch;
|
|
571
571
|
if (!isArraySubset(changes[0].path, change.path)) {
|
|
572
572
|
changes.push(change);
|
|
573
|
+
changeInBatch.level = Math.min(changeInBatch.level, level);
|
|
573
574
|
}
|
|
574
575
|
} else {
|
|
575
576
|
changesInBatch.set(node, {
|
|
@@ -999,12 +1000,17 @@ function observe(selectorOrRun, reactionOrOptions, options) {
|
|
|
999
1000
|
options = reactionOrOptions;
|
|
1000
1001
|
}
|
|
1001
1002
|
let dispose;
|
|
1003
|
+
let isRunning = false;
|
|
1002
1004
|
const e = { num: 0 };
|
|
1003
1005
|
const update = function() {
|
|
1006
|
+
if (isRunning) {
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1004
1009
|
if (e.onCleanup) {
|
|
1005
1010
|
e.onCleanup();
|
|
1006
1011
|
e.onCleanup = void 0;
|
|
1007
1012
|
}
|
|
1013
|
+
isRunning = true;
|
|
1008
1014
|
beginBatch();
|
|
1009
1015
|
delete e.value;
|
|
1010
1016
|
dispose == null ? void 0 : dispose();
|
|
@@ -1018,6 +1024,7 @@ function observe(selectorOrRun, reactionOrOptions, options) {
|
|
|
1018
1024
|
e.onCleanupReaction = void 0;
|
|
1019
1025
|
}
|
|
1020
1026
|
endBatch();
|
|
1027
|
+
isRunning = false;
|
|
1021
1028
|
if (reaction && ((options == null ? void 0 : options.fromComputed) || (e.num > 0 || !isEvent(selectorOrRun)) && (e.previous !== e.value || typeof e.value === "object"))) {
|
|
1022
1029
|
reaction(e);
|
|
1023
1030
|
}
|
|
@@ -1563,8 +1570,10 @@ function setKey(node, key, newValue, level) {
|
|
|
1563
1570
|
parent.recursivelyAutoActivated = false;
|
|
1564
1571
|
} while (parent = parent.parent);
|
|
1565
1572
|
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1573
|
+
const notify2 = !equals(savedValue, prevValue);
|
|
1574
|
+
const forceNotify = !notify2 && childNode.isComputing && isObject(savedValue);
|
|
1575
|
+
if (notify2 || forceNotify) {
|
|
1576
|
+
updateNodesAndNotify(node, savedValue, prevValue, childNode, isPrim, isRoot, level, forceNotify);
|
|
1568
1577
|
}
|
|
1569
1578
|
extractFunctionOrComputed(node, key, savedValue);
|
|
1570
1579
|
}
|
|
@@ -1677,20 +1686,20 @@ function handlerMapSet(node, p, value) {
|
|
|
1677
1686
|
};
|
|
1678
1687
|
}
|
|
1679
1688
|
}
|
|
1680
|
-
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level) {
|
|
1689
|
+
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level, forceNotify) {
|
|
1681
1690
|
if (!childNode)
|
|
1682
1691
|
childNode = node;
|
|
1683
1692
|
beginBatch();
|
|
1684
1693
|
if (isPrim === void 0) {
|
|
1685
1694
|
isPrim = isPrimitive(newValue);
|
|
1686
1695
|
}
|
|
1687
|
-
let hasADiff = isPrim;
|
|
1696
|
+
let hasADiff = forceNotify || isPrim;
|
|
1688
1697
|
let whenOptimizedOnlyIf = false;
|
|
1689
1698
|
if (!isPrim || prevValue && !isPrimitive(prevValue)) {
|
|
1690
1699
|
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined") {
|
|
1691
1700
|
__devUpdateNodes.clear();
|
|
1692
1701
|
}
|
|
1693
|
-
hasADiff = updateNodes(childNode, newValue, prevValue);
|
|
1702
|
+
hasADiff = hasADiff || updateNodes(childNode, newValue, prevValue);
|
|
1694
1703
|
if (isArray(newValue)) {
|
|
1695
1704
|
whenOptimizedOnlyIf = (newValue == null ? void 0 : newValue.length) !== (prevValue == null ? void 0 : prevValue.length);
|
|
1696
1705
|
}
|
|
@@ -1960,18 +1969,14 @@ function activateNodeFunction(node, lazyFn) {
|
|
|
1960
1969
|
}
|
|
1961
1970
|
} else {
|
|
1962
1971
|
activatedValue = value;
|
|
1963
|
-
|
|
1972
|
+
const isLoaded = node.state.isLoaded.peek();
|
|
1973
|
+
if (isLoaded || !isFunction(value)) {
|
|
1964
1974
|
node.isComputing = true;
|
|
1965
1975
|
set(node, value);
|
|
1966
1976
|
node.isComputing = false;
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
}
|
|
1971
|
-
node.state.assign({
|
|
1972
|
-
isLoaded: true,
|
|
1973
|
-
error: void 0
|
|
1974
|
-
});
|
|
1977
|
+
}
|
|
1978
|
+
if (!isLoaded) {
|
|
1979
|
+
node.state.assign({ isLoaded: true, error: void 0 });
|
|
1975
1980
|
}
|
|
1976
1981
|
}
|
|
1977
1982
|
}
|
package/package.json
CHANGED
package/sync-plugins/crud.js
CHANGED
|
@@ -129,7 +129,12 @@ function syncedCrud(props) {
|
|
|
129
129
|
const deletes = /* @__PURE__ */ new Set();
|
|
130
130
|
const getUpdateValue = (itemValue, prev) => {
|
|
131
131
|
return updatePartial ? Object.assign(
|
|
132
|
-
sync.diffObjects(
|
|
132
|
+
sync.diffObjects(
|
|
133
|
+
prev,
|
|
134
|
+
itemValue,
|
|
135
|
+
/*deep*/
|
|
136
|
+
true
|
|
137
|
+
),
|
|
133
138
|
itemValue[fieldId] ? { [fieldId]: itemValue[fieldId] } : {}
|
|
134
139
|
) : itemValue;
|
|
135
140
|
};
|
package/sync-plugins/crud.mjs
CHANGED
|
@@ -127,7 +127,12 @@ function syncedCrud(props) {
|
|
|
127
127
|
const deletes = /* @__PURE__ */ new Set();
|
|
128
128
|
const getUpdateValue = (itemValue, prev) => {
|
|
129
129
|
return updatePartial ? Object.assign(
|
|
130
|
-
diffObjects(
|
|
130
|
+
diffObjects(
|
|
131
|
+
prev,
|
|
132
|
+
itemValue,
|
|
133
|
+
/*deep*/
|
|
134
|
+
true
|
|
135
|
+
),
|
|
131
136
|
itemValue[fieldId] ? { [fieldId]: itemValue[fieldId] } : {}
|
|
132
137
|
) : itemValue;
|
|
133
138
|
};
|
package/sync-plugins/keel.js
CHANGED
|
@@ -214,7 +214,6 @@ function syncedKeel(props) {
|
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
216
|
const create = createParam ? async (input, params) => {
|
|
217
|
-
console.log(createParam.toString());
|
|
218
217
|
const { data, error } = await createParam(convertObjectToCreate(input));
|
|
219
218
|
if (error) {
|
|
220
219
|
await handleSetError(error, params, input, createParam, "create");
|
|
@@ -222,7 +221,6 @@ function syncedKeel(props) {
|
|
|
222
221
|
return data;
|
|
223
222
|
} : void 0;
|
|
224
223
|
const update = updateParam ? async (input, params) => {
|
|
225
|
-
console.log(updateParam.toString());
|
|
226
224
|
const id = input.id;
|
|
227
225
|
const values = convertObjectToCreate(input);
|
|
228
226
|
delete values.id;
|
package/sync-plugins/keel.mjs
CHANGED
|
@@ -208,7 +208,6 @@ function syncedKeel(props) {
|
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
210
|
const create = createParam ? async (input, params) => {
|
|
211
|
-
console.log(createParam.toString());
|
|
212
211
|
const { data, error } = await createParam(convertObjectToCreate(input));
|
|
213
212
|
if (error) {
|
|
214
213
|
await handleSetError(error, params, input, createParam, "create");
|
|
@@ -216,7 +215,6 @@ function syncedKeel(props) {
|
|
|
216
215
|
return data;
|
|
217
216
|
} : void 0;
|
|
218
217
|
const update = updateParam ? async (input, params) => {
|
|
219
|
-
console.log(updateParam.toString());
|
|
220
218
|
const id = input.id;
|
|
221
219
|
const values = convertObjectToCreate(input);
|
|
222
220
|
delete values.id;
|