Skip to content

Commit

Permalink
Fixed patch
Browse files Browse the repository at this point in the history
  • Loading branch information
masylum committed Aug 27, 2016
1 parent 5f37e34 commit 4ebf8e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-rest",
"version": "0.0.10",
"version": "0.0.11",
"description": "REST conventions for mobx.",
"repository": {
"type": "git",
Expand Down
11 changes: 7 additions & 4 deletions src/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class Model {
attributes: {},
{optimistic = true, patch = true}: SaveOptions = {}
): Promise<*> {
let data = Object.assign({}, attributes)
let originalAttributes = this.attributes.toJS()
let newAttributes
let data

if (!this.get('id')) {
return this.collection.create(attributes, {optimistic})
Expand All @@ -40,9 +41,11 @@ class Model {
const label: Label = 'updating'

if (patch) {
data = Object.assign({}, originalAttributes, attributes)
newAttributes = Object.assign({}, originalAttributes, attributes)
data = Object.assign({}, attributes)
} else {
data = attributes
newAttributes = Object.assign({}, attributes)
data = Object.assign({}, originalAttributes, attributes)
}

// TODO: use PATCH
Expand All @@ -51,7 +54,7 @@ class Model {
data
)

if (optimistic) this.attributes = asMap(data)
if (optimistic) this.attributes = asMap(newAttributes)

this.request = {label, abort}

Expand Down

0 comments on commit 4ebf8e1

Please sign in to comment.