Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
david-mcafee committed Mar 29, 2022
1 parent 40ee89b commit 9d3a937
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions packages/datastore/src/datastore/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,15 +1129,15 @@ class DataStore {
.observe(modelConstructor, predicate)
.filter(({ model }) => namespaceResolver(model) === USER)
.map((event: SubscriptionMessage<T>): SubscriptionMessage<T> => {
// Storage's `save` only returns updated fields - intercept the
// event to combine the updated fields with the original, so
// that first snapshot returned to the consumer contains all fields
const { opType, element, model, condition, originalElement } =
// The `element` returned by storage only contains updated fields.
// Intercept the event to send the `savedElement` so that the first
// snapshot returned to the consumer contains all fields
const { opType, model, condition, savedElement } =
event;

const updated = {
opType,
element: { ...originalElement, ...element },
element: savedElement,
model,
condition,
};
Expand Down
10 changes: 5 additions & 5 deletions packages/datastore/src/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class StorageClass implements StorageFacade {
const result = await this.adapter.save(model, condition);

result.forEach(r => {
const [originalElement, opType] = r;
const [savedElement, opType] = r;

// truthy when save is called by the Merger
const syncResponse = !!mutator;
Expand All @@ -122,7 +122,7 @@ class StorageClass implements StorageFacade {
if (opType === OpType.UPDATE && !syncResponse) {
updateMutationInput = this.getUpdateMutationInput(
model,
originalElement,
savedElement,
patchesTuple
);
// // an update without changed user fields
Expand All @@ -132,10 +132,10 @@ class StorageClass implements StorageFacade {
}
}

const element = updateMutationInput || originalElement;
const element = updateMutationInput || savedElement;

const modelConstructor = (
Object.getPrototypeOf(originalElement) as Object
Object.getPrototypeOf(savedElement) as Object
).constructor as PersistentModelConstructor<T>;

this.pushStream.next({
Expand All @@ -144,7 +144,7 @@ class StorageClass implements StorageFacade {
element,
mutator,
condition: ModelPredicateCreator.getPredicates(condition, false),
originalElement,
savedElement,
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/datastore/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export type SubscriptionMessage<T extends PersistentModel> = {
element: T;
model: PersistentModelConstructor<T>;
condition: PredicatesGroup<T> | null;
originalElement?: T;
savedElement?: T;
};

export type DataStoreSnapshot<T extends PersistentModel> = {
Expand Down

0 comments on commit 9d3a937

Please sign in to comment.