From 089cd46645ff7f0e7debd5a6035e88be8932669a Mon Sep 17 00:00:00 2001 From: Vladimir Menshakov Date: Tue, 23 Feb 2021 22:44:42 +0000 Subject: [PATCH] emit update if offset !== 0 due to the change of the model.index --- core/model.js | 2 +- test/update.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/model.js b/core/model.js index 1686cd8c3..e77889ff3 100644 --- a/core/model.js +++ b/core/model.js @@ -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) { diff --git a/test/update.js b/test/update.js index ce4f8f015..e51a8fcc1 100644 --- a/test/update.js +++ b/test/update.js @@ -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() @@ -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() @@ -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) }) })