Skip to content

Commit 65b1cdb

Browse files
authored
fix(core): Observable splice index > length (NativeScript#8900)
* fix for splice index > length In javascript you can call splice with an index > length. The result is a push. But when you do that ObservableArray index will be wrong and thus user logic will fail. Example: ```ts // obsarray = [0]; obsarray.splice(2, 0, 1); // this works, the inner array is now [0,1] // however 'change' is called with index = 2 // when the use tries to do obsarray.getItem(eventData.index) -> crash ``` * fix to handle delete too
1 parent af6336d commit 65b1cdb

File tree

1 file changed

+1
-1
lines changed
  • packages/core/data/observable-array

1 file changed

+1
-1
lines changed

packages/core/data/observable-array/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export class ObservableArray<T> extends Observable {
246246
eventName: CHANGE,
247247
object: this,
248248
action: ChangeType.Splice,
249-
index: start,
249+
index: Math.min(start, this._array.length-1),
250250
removed: result,
251251
addedCount: this._array.length + result.length - length,
252252
});

0 commit comments

Comments
 (0)