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 ac36525 commit 5f37e34
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ REST conventions for mobx.

![](https://media.giphy.com/media/b9QBHfcNpvqDK/giphy.gif)

## TODO

Make API dependency injectable

## Installation

```
Expand Down
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.9",
"version": "0.0.10",
"description": "REST conventions for mobx.",
"repository": {
"type": "git",
Expand Down
5 changes: 4 additions & 1 deletion src/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ class Model {
): Promise<*> {
let data = Object.assign({}, attributes)
let originalAttributes = this.attributes.toJS()

if (!this.get('id')) {
return this.collection.create(attributes, {optimistic})
}

const label: Label = 'updating'

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

// TODO: use PATCH
Expand Down
2 changes: 1 addition & 1 deletion test/ModelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 5f37e34

Please sign in to comment.