Skip to content

Commit

Permalink
copy instead of mutate observe messages
Browse files Browse the repository at this point in the history
  • Loading branch information
svidgen committed Nov 16, 2021
1 parent 86d8596 commit fadc51d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/datastore/src/datastore/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1311,20 +1311,21 @@ class DataStore {
// the `element` for UPDATE events isn't an instance of `modelConstructor`.
// however, `executivePredicate` expects an instance that supports lazy loaded
// associations. customers will presumably expect the same!
let message = item;
if (
isModelConstructor(modelConstructor) &&
!(item.element instanceof modelConstructor)
) {
item.element = modelInstanceCreator(
modelConstructor,
item.element
);
message = {
...message,
element: modelInstanceCreator(modelConstructor, item.element),
};
}
if (
!executivePredicate ||
(await executivePredicate.matches(item.element))
(await executivePredicate.matches(message.element))
) {
observer.next(item as SubscriptionMessage<T>);
observer.next(message as SubscriptionMessage<T>);
}
},
error: (err) => observer.error(err),
Expand Down

0 comments on commit fadc51d

Please sign in to comment.