Skip to content

Commit

Permalink
Merge pull request #43 from artemis-ag/set-previous-snapshot-in-creat…
Browse files Browse the repository at this point in the history
…e-or-update-model

Set previous snapshot in create or update model
  • Loading branch information
Joe Torreggiani authored Apr 13, 2020
2 parents 2860c85 + 19862d8 commit 5ea18c8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dist/mobx-async-store.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,8 @@ function () {
}
});
}

record.setPreviousSnapshot();
} else {
record = this.createModel(type, id, {
attributes: attributes,
Expand Down
2 changes: 2 additions & 0 deletions dist/mobx-async-store.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,8 @@ function () {
}
});
}

record.setPreviousSnapshot();
} else {
record = this.createModel(type, id, {
attributes: attributes,
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": "@artemisag/mobx-async-store",
"version": "1.0.19",
"version": "1.0.20",
"module": "dist/mobx-async-store.esm.js",
"browser": "dist/mobx-async-store.cjs.js",
"main": "dist/mobx-async-store.cjs.js",
Expand Down
16 changes: 16 additions & 0 deletions spec/Store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,22 @@ describe('Store', () => {
})
})

describe('createOrUpdateModel', () => {
it('sets previous snapshot', () => {
store.add('notes', { id: 3, text: 'hi' })

const record = store.createOrUpdateModel({
id: 3,
type: 'notes',
attributes: {
text: 'yo'
}
})

expect(record.previousSnapshot.attributes.text).toEqual('yo')
})
})

describe('createModelsFromData', () => {
it('creates a list of model objs from a list of data objs', () => {
const dataObjs = [
Expand Down
2 changes: 2 additions & 0 deletions src/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ class Store {
}
})
}

record.setPreviousSnapshot()
} else {
record = this.createModel(type, id, { attributes, relationships })
this.data[type].records[record.id] = record
Expand Down

0 comments on commit 5ea18c8

Please sign in to comment.