angular2-smart-table icon indicating copy to clipboard operation
angular2-smart-table copied to clipboard

LocalDataSource is inconsistent with keeping a reference to the loaded array

Open uap-universe opened this issue 10 months ago • 1 comments

The LocalDataSource usually keeps a reference to the array of data that was loaded:

https://github.com/dj-fiorex/angular2-smart-table/blob/51d46a563c186cd5c31d53e63602b801f71357e4/projects/angular2-smart-table/src/lib/lib/data-source/local/local.data-source.ts#L16-L26

However, the operations on that array are totally inconsistent.

In the prepend, append, and add case, the elements are added to the referenced array:

https://github.com/dj-fiorex/angular2-smart-table/blob/51d46a563c186cd5c31d53e63602b801f71357e4/projects/angular2-smart-table/src/lib/lib/data-source/local/local.data-source.ts#L22-L46

However, in the remove or empty case, the reference to the original array gets overwritten:

https://github.com/dj-fiorex/angular2-smart-table/blob/51d46a563c186cd5c31d53e63602b801f71357e4/projects/angular2-smart-table/src/lib/lib/data-source/local/local.data-source.ts#L48-L49

https://github.com/dj-fiorex/angular2-smart-table/blob/51d46a563c186cd5c31d53e63602b801f71357e4/projects/angular2-smart-table/src/lib/lib/data-source/local/local.data-source.ts#L94-L95

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.

uap-universe avatar Dec 12 '24 20:12 uap-universe