Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
uap-universe opened this issue Dec 12, 2024 · 1 comment
Assignees
Labels
breaking-change Resolving this issue will introduce a breaking change. bug Something isn't working

Comments

@uap-universe
Copy link
Collaborator

uap-universe commented Dec 12, 2024

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.

@uap-universe uap-universe added bug Something isn't working investigation-needed An issue needs to be analyzed labels Dec 12, 2024
@uap-universe uap-universe added this to the v3.5.0 milestone Dec 12, 2024
@uap-universe uap-universe self-assigned this Dec 12, 2024
@uap-universe uap-universe changed the title State of LocalDataSource during handling of CreateConfirm event inconsistent - depending on whether the array was empty State of array used in a LocalDataSource during handling of CreateConfirm event inconsistent - depending on whether the array was empty Dec 12, 2024
@uap-universe uap-universe changed the title State of array used in a LocalDataSource during handling of CreateConfirm event inconsistent - depending on whether the array was empty LocalDataSource is inconsistent with keeping a reference to the loaded array Dec 13, 2024
@uap-universe uap-universe removed this from the v3.5.0 milestone Dec 13, 2024
@uap-universe uap-universe added breaking-change Resolving this issue will introduce a breaking change. and removed investigation-needed An issue needs to be analyzed labels Dec 13, 2024
@uap-universe
Copy link
Collaborator Author

Updated the description with the results of the investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Resolving this issue will introduce a breaking change. bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant