Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Nov 16, 2018
2 parents 70d5b18 + aaf43b8 commit 8c8b63b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/coalesce-vue/src/viewmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export abstract class ViewModel<

})

/** Whether or not to reload the ViewModel's `$data` with the response received from the server after a call to .$save(). */
public $loadResponseFromSaves = true;

/**
* A function for invoking the `/save` endpoint, and a set of properties about the state of the last call.
*/
Expand All @@ -136,11 +139,19 @@ export abstract class ViewModel<

// The PK *MUST* be loaded so that the PK returned by a creation save call
// will be used by subsequent update calls.
this.$primaryKey = (this.$save.result as Indexable<TModel>)[this.$metadata.keyProp.name]
this.$primaryKey = (this.$save.result as Indexable<TModel>)[this.$metadata.keyProp.name]
} else {
// Only load the save response if the data hasn't changed since we sent it.

// else: Only load the save response if the data hasn't changed since we sent it.
// If the data has changed, loading the response would overwrite users' changes.
updateFromModel(this.$data, this.$save.result);
if (this.$loadResponseFromSaves) {
updateFromModel(this.$data, this.$save.result);
} else {
// The PK *MUST* be loaded so that the PK returned by a creation save call
// will be used by subsequent update calls.
this.$primaryKey = (this.$save.result as Indexable<TModel>)[this.$metadata.keyProp.name]
}

// Set the new state of our data as being clean (since we just made a change to it)
this.$isDirty = false;
}
Expand Down

0 comments on commit 8c8b63b

Please sign in to comment.