diff --git a/README.md b/README.md index 7aef943..5321e90 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ REST conventions for mobx. ![](https://media.giphy.com/media/b9QBHfcNpvqDK/giphy.gif) +## TODO + +Make API dependency injectable + ## Installation ``` diff --git a/package.json b/package.json index 87965e1..e466aeb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mobx-rest", - "version": "0.0.9", + "version": "0.0.10", "description": "REST conventions for mobx.", "repository": { "type": "git", diff --git a/src/Model.js b/src/Model.js index 52cd060..1eb84c6 100644 --- a/src/Model.js +++ b/src/Model.js @@ -32,6 +32,7 @@ class Model { ): Promise<*> { let data = Object.assign({}, attributes) let originalAttributes = this.attributes.toJS() + if (!this.get('id')) { return this.collection.create(attributes, {optimistic}) } @@ -39,7 +40,9 @@ class Model { const label: Label = 'updating' if (patch) { - data = Object.assign({}, this.attributes.toJS(), attributes) + data = Object.assign({}, originalAttributes, attributes) + } else { + data = attributes } // TODO: use PATCH diff --git a/test/ModelTest.js b/test/ModelTest.js index 8be98fc..daaa5e5 100644 --- a/test/ModelTest.js +++ b/test/ModelTest.js @@ -71,7 +71,7 @@ describe('Model', () => { context('and its not patching', () => { it('it sets model straight away', () => { - model.save({id: item.id, name}, {patch: false}) + model.save({name}, {patch: false}) assert.equal(model.get('name'), 'dylan') assert.equal(model.get('album'), null) assert.equal(model.request.label, 'updating')