Skip to content

LocalDataSource is inconsistent with keeping a reference to the loaded array #171

@uap-universe

Description

@uap-universe

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);

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.

Metadata

Metadata

Assignees

Labels

breaking-changeResolving this issue will introduce a breaking change.bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions