Skip to content

Commit

Permalink
emit update if offset !== 0 due to the change of the model.index
Browse files Browse the repository at this point in the history
  • Loading branch information
whoozle committed Feb 23, 2021
1 parent 46ae9db commit 089cd46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ exports.ModelUpdate.prototype.apply = function(view, skipCheck) {
apply(ModelUpdateInsert, src, src_n - dst_n)
break
} else if (dst === src) {
apply(row[1]? ModelUpdateUpdate: ModelUpdateNothing, src)
apply(row[1] || offset !== 0? ModelUpdateUpdate: ModelUpdateNothing, src)
++src
++dst
} else if (dst > src) {
Expand Down
10 changes: 6 additions & 4 deletions test/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ describe('ModelUpdate', function() {
})

describe('remove from front + insert to back', function() {
it('should call to remove/insert', function() {
it('should call to remove/update/insert because it changes model.index', function() {
model = new Model()
view = new View()

Expand All @@ -364,14 +364,15 @@ describe('ModelUpdate', function() {

sinon.assert.calledOnce(view._removeItems)
sinon.assert.calledWith(view._removeItems, 0, 1)
sinon.assert.calledOnce(view._updateItems)
sinon.assert.calledWith(view._updateItems, 0, 9)
sinon.assert.calledOnce(view._insertItems)
sinon.assert.calledWith(view._insertItems, 9, 10)
sinon.assert.notCalled(view._updateItems)
})
})

describe('insert to front + remove from back', function() {
it('should call to remove/insert', function() {
it('should call to remove/update/insert because it changes model.index', function() {
model = new Model()
view = new View()

Expand All @@ -388,9 +389,10 @@ describe('ModelUpdate', function() {

sinon.assert.calledOnce(view._insertItems)
sinon.assert.calledWith(view._insertItems, 0, 1)
sinon.assert.calledOnce(view._updateItems)
sinon.assert.calledWith(view._updateItems, 1, 10)
sinon.assert.calledOnce(view._removeItems)
sinon.assert.calledWith(view._removeItems, 10, 11)
sinon.assert.notCalled(view._updateItems)
})
})

Expand Down

0 comments on commit 089cd46

Please sign in to comment.