-
Notifications
You must be signed in to change notification settings - Fork 29
Description
The LocalDataSource usually keeps a reference to the array of data that was loaded:
Lines 16 to 26 in 51d46a5
| constructor(data: Array<any> = []) { | |
| super(); | |
| this.data = data; | |
| } | |
| load(data: Array<any>): Promise<any> { | |
| this.data = data; | |
| return super.load(data); | |
| } |
However, the operations on that array are totally inconsistent.
In the prepend, append, and add case, the elements are added to the referenced array:
Lines 22 to 46 in 51d46a5
| load(data: Array<any>): Promise<any> { | |
| this.data = data; | |
| return super.load(data); | |
| } | |
| prepend(element: any): Promise<any> { | |
| this.reset(true); | |
| this.data.unshift(element); | |
| return super.prepend(element); | |
| } | |
| append(element: any): Promise<any> { | |
| this.reset(true); | |
| this.data.push(element); | |
| return super.append(element); | |
| } | |
| add(element: any): Promise<any> { | |
| this.data.push(element); | |
| return super.add(element); | |
| } |
However, in the remove or empty case, the reference to the original array gets overwritten:
Lines 48 to 49 in 51d46a5
| remove(element: any): Promise<any> { | |
| this.data = this.data.filter(el => el !== element); |
Lines 94 to 95 in 51d46a5
| empty(): Promise<any> { | |
| this.data = []; |
The solution to this would certainly be to not keep a reference to the original array in any case and always work on an own copy.
However, this will most likely break applications which in one way or the other rely on the current, inconsistent, behavior.