Skip to content

Commit

Permalink
fix(Model): fix unset to flush the path changes up to the removed key
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Nov 1, 2016
1 parent 5bd0ce1 commit 3697f97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/cerebral/src/Model.js
Expand Up @@ -205,6 +205,7 @@ class Model {
})
}
unset (path) {
this.changedPaths.push(path.slice())
const key = path.pop()

this.updateIn(path, (obj) => {
Expand Down
9 changes: 9 additions & 0 deletions packages/cerebral/src/Model.test.js
Expand Up @@ -114,6 +114,15 @@ describe('Model', () => {
model.unset(['foo'])
assert.deepEqual(model.get(), {})
})
it('should flush unset paths', () => {
const model = new Model({
foo: {
bar: 'value'
}
})
model.unset(['foo', 'bar'])
assert.deepEqual(model.flush(), {foo: {bar: true}})
})
})
describe('CONCAT', () => {
it('should be able to concat array', () => {
Expand Down

0 comments on commit 3697f97

Please sign in to comment.