Skip to content

Commit 7316bfe

Browse files
committed
Minor perf improvement on computed property binding
1 parent c0655aa commit 7316bfe

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/create-store-internals.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function createStoreInternals({
5656
const defaultState = initialState || {};
5757
let selectorId = 0;
5858

59-
const computedProperties = {};
59+
const computedProperties = [];
6060

6161
const actionCreatorDict = {};
6262
const actionCreators = {};
@@ -203,7 +203,7 @@ export default function createStoreInternals({
203203
});
204204
};
205205
createComputedProperty(target);
206-
set(path, computedProperties, createComputedProperty);
206+
computedProperties.push({ key, parentPath, createComputedProperty });
207207
} else if (value[selectorSymbol]) {
208208
selectorId += 1;
209209
const selectorInstanceId = selectorId;
@@ -559,17 +559,11 @@ export default function createStoreInternals({
559559
: stateAfterCustomReducers;
560560
const result = selectorsReducer(stateAfterSelect);
561561
isInReducer = false;
562-
const recursiveRebindComputedProperties = (currentPath, obj) => {
563-
const updatedCurrent = get(currentPath, result);
564-
Object.keys(obj).forEach(key => {
565-
if (typeof obj[key] === 'function') {
566-
obj[key](updatedCurrent);
567-
} else {
568-
recursiveRebindComputedProperties([...currentPath, key], obj[key]);
569-
}
562+
if (result !== state) {
563+
computedProperties.forEach(({ parentPath, createComputedProperty }) => {
564+
createComputedProperty(get(parentPath, result));
570565
});
571-
};
572-
recursiveRebindComputedProperties([], computedProperties);
566+
}
573567
return result;
574568
};
575569

0 commit comments

Comments
 (0)