The LocalDataSource usually keeps a reference to the array of data that was loaded:
|
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:
|
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:
|
remove(element: any): Promise<any> { |
|
this.data = this.data.filter(el => el !== element); |
|
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.
The
LocalDataSourceusually keeps a reference to the array of data that was loaded:angular2-smart-table/projects/angular2-smart-table/src/lib/lib/data-source/local/local.data-source.ts
Lines 16 to 26 in 51d46a5
However, the operations on that array are totally inconsistent.
In the
prepend,append, andaddcase, the elements are added to the referenced array:angular2-smart-table/projects/angular2-smart-table/src/lib/lib/data-source/local/local.data-source.ts
Lines 22 to 46 in 51d46a5
However, in the
removeoremptycase, the reference to the original array gets overwritten:angular2-smart-table/projects/angular2-smart-table/src/lib/lib/data-source/local/local.data-source.ts
Lines 48 to 49 in 51d46a5
angular2-smart-table/projects/angular2-smart-table/src/lib/lib/data-source/local/local.data-source.ts
Lines 94 to 95 in 51d46a5
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.