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

Missing originalValues for collection of primitive types #78

Open
mahish opened this issue Jun 8, 2023 · 7 comments
Open

Missing originalValues for collection of primitive types #78

mahish opened this issue Jun 8, 2023 · 7 comments

Comments

@mahish
Copy link

mahish commented Jun 8, 2023

Hi,
I wanted to discuss an issue I encountered while working with a collection of primitive types. In my case, when an entity has a DataProperty with dp.isScalar === false, the state of the entity correctly changes to "Modified" when the content of the collection has been changed. However, I haven't noticed any effect of this state change in the originalValues map, as described in the originalValues documentation or here

While investigating this issue, I came across this code snippet in the repository

if (!property.isScalar) {
throw new Error("Nonscalar data properties are readonly - items may be added or removed but the collection may not be changed.");
}

First, I'm not recieving this error in my application. Second, the error message is not 100% clear to me so I would like to confirm my understanding here. Does "items may be added or removed but the collection may not be changed" mean that I can change its content but Im not able to change the collection itself => the reference (memory location)?

  • if true, is the support for originalValues pending and waiting for implementation in case of collection of primitive types?
  • if false, is there no plan to support it at all and I should handle it in my application in whatever way I need to?

I would appreciate any clarification on this matter. Thanks a lot.

@mahish mahish changed the title Missing originalValues for collections of primitive types Missing originalValues for collection of primitive types Jun 8, 2023
@mahish
Copy link
Author

mahish commented Jun 8, 2023

I also noticed a change of collection's content does not trigger propertyChange action.

@steveschmitt
Copy link
Member

Hi @mahish, the message "items may be added or removed but the collection may not be changed" means what you said: that you can change the content of the collection but not the collection itself. In other words, you should not attempt to replace the collection with a new array.

Part of the reason for this is that Breeze collections are not simple arrays; they are "smart" collections that manage the relationships between entities when they are added or removed from collections.

It seems that that updating the originalValuesMap is not part of the behavior when adding or removing elements from a collection of scalar values. This behavior could be added to Breeze. The difficulty might be when an array element is changed in-place.

@mahish
Copy link
Author

mahish commented Jul 7, 2023

@steveschmitt Hi and thank you for the reply. Yeah, I see. Thank you for clarification. I totally understand replacement of the collection itself is not allowed. I was interested in whether a collection's elements has changed (adding, removing). I found out there is _origValues on the collection itself so I use it for my use case alongside the aggregated public entityAspect.originalValues for other data types. Workaround but good enough for now.

I understand the difficulty you mean but I still see a value of adding support for originalValues when manipulating with collections without support for tracking changes of individual collection's elements (eg. observableArray[0] = 'foo'). Quickly checked other libraries with observable arrays and neither of them support such case I believe?

@mahish
Copy link
Author

mahish commented Aug 18, 2023

Recently, I've worked with ObservableArray https://github.com/Breeze/breeze-client/blob/b450f982c78e107a798143344d082f8682465138/src/observable-array.ts . I'm listening arrayChanged event on every primitive collection to automatically check for changes on the collection. I can imagine this event might be used internally by Breeze to trigger official entityChanged event via PropertyChange entity action. This action is not triggered by change of collection at the moment. The result would be much more consistent usage of Breeze regarding tracking of changes.

Is there anything I can do about it? Would you welcome PR from me as a starting point? Thanks.

@steveschmitt
Copy link
Member

Yes, a PR would be great. Thank you.

@steveschmitt
Copy link
Member

@mahish Have you made any progress on this?

@mahish
Copy link
Author

mahish commented Sep 25, 2023

@steveschmitt Hi, we are weeks from important release. Part of the release is my set of helpers handling changes of the collection type. I should be able to transform these helpers to the PR during October.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants