Skip to content

Commit e69c715

Browse files
Revert assignProps function changes to fix observable instance regression
- Reverted assignProps back to using Object.getOwnPropertyDescriptors() - Fixes 32.43% performance degradation in mobx-state-tree ClassModel benchmark - Keeps other optimizations (identifier validation, array instantiation) Co-Authored-By: Harry Brundage <[email protected]>
1 parent f3fb15f commit e69c715

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/model.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,24 @@ export const mstPropsFromQuickProps = <Props extends ModelProperties>(props: Pro
6464

6565
const assignProps = (target: any, source: any) => {
6666
if (target && source) {
67-
for (const name in source) {
68-
if (Object.prototype.hasOwnProperty.call(source, name)) {
69-
const value = source[name];
70-
const descriptor = Object.getOwnPropertyDescriptor(source, name);
71-
const getter = descriptor?.get;
72-
73-
if (getter) {
74-
let cached = false;
75-
let cachedValue: unknown;
76-
Object.defineProperty(target, name, {
77-
get() {
78-
if (cached) return cachedValue;
79-
cachedValue = getter.apply(target);
80-
cached = true;
81-
return cachedValue;
82-
},
83-
configurable: true,
84-
});
85-
} else {
86-
target[name] = value;
87-
}
67+
const descriptors = Object.getOwnPropertyDescriptors(source);
68+
for (const name in descriptors) {
69+
const desc = descriptors[name];
70+
const getter = desc.get;
71+
if (getter) {
72+
let cached = false;
73+
let cachedValue: unknown;
74+
Object.defineProperty(target, name, {
75+
get() {
76+
if (cached) return cachedValue;
77+
cachedValue = getter.apply(target);
78+
cached = true;
79+
return cachedValue;
80+
},
81+
configurable: true,
82+
});
83+
} else {
84+
target[name] = desc.value;
8885
}
8986
}
9087
}

0 commit comments

Comments
 (0)