Skip to content

Commit

Permalink
fix(store): prevent iterating over the previous model props
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Jun 14, 2022
1 parent 7a86cbc commit f5a5673
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,15 @@ function valueWithValidation(
return defaultValue;
}

function cloneModel(model) {
const config = definitions.get(model);
const clone = Object.freeze(Object.create(model));

definitions.set(clone, config);

return clone;
}

function store(Model, options = {}) {
const config = bootstrap(Model);

Expand Down Expand Up @@ -1518,7 +1527,7 @@ function store(Model, options = {}) {
const nextValue = get(Model, id);

if (nextValue !== value && ready(value) && !ready(nextValue)) {
const tempValue = config.create(value);
const tempValue = cloneModel(value);
cache.set(tempValue, "state", () => getModelState(nextValue));
return tempValue;
}
Expand Down

0 comments on commit f5a5673

Please sign in to comment.