Skip to content

Commit

Permalink
fix(store): merge nested model data when it is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Nov 23, 2021
1 parent d199d94 commit cc3c735
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/store.js
Expand Up @@ -587,7 +587,17 @@ function setupModel(Model, nested) {
}
resultModel = nestedData;
} else {
resultModel = nestedConfig.create(nestedData);
const lastNestedModel = cache.getEntry(
nestedConfig,
data[key].id,
).value;
resultModel = nestedConfig.create(
nestedData,
lastNestedModel &&
nestedConfig.isInstance(lastNestedModel)
? lastNestedModel
: undefined,
);
syncCache(nestedConfig, resultModel.id, resultModel);
}
}
Expand Down Expand Up @@ -775,7 +785,15 @@ function setupListModel(Model, nested) {
throw TypeError("Model instance must match the definition");
}
} else {
model = modelConfig.create(data);
const lastModel =
modelConfig.enumerable &&
cache.getEntry(modelConfig, data.id).value;
model = modelConfig.create(
data,
lastModel && modelConfig.isInstance(lastModel)
? lastModel
: undefined,
);
if (modelConfig.enumerable) {
id = model.id;
syncCache(modelConfig, id, model, invalidate);
Expand Down

0 comments on commit cc3c735

Please sign in to comment.