Skip to content

Commit 45de6bf

Browse files
Saviiochuan6
authored andcommitted
fix: incorrect flag for diff algorithm
1 parent 73bea98 commit 45de6bf

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/utils/diff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export function diff<T>(oldList: T[], newList: T[], pk = '_id'): Ops {
174174
}
175175
}
176176

177-
const arrayIsSame = reused === curr.length && prev.length === curr.length
177+
const arrayIsSame = reused === curr.length && prev.length === curr.length && reused !== 0
178178
return {
179179
type: arrayIsSame ? OpsType.SuccessAndSkip : OpsType.Success,
180180
ops: ret,

test/specs/utils/diff.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ export default describe('Diff Testcase: ', () => {
328328
const result = diff([{ id: 1, a: 1 }], [{ id: 1, a: 1 }], 'id')
329329
expect(result.type).to.equal(2)
330330
})
331+
332+
it('should be able to use old list except reused number is 0: 27', () => {
333+
// when old list is empty & new list is empty
334+
// should not return skip flag
335+
const result = diff([], [], 'id')
336+
expect(result.type).to.equal(1)
337+
})
331338
})
332339

333340
describe('Function: getPatchResult', () => {

0 commit comments

Comments
 (0)