-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
HasMany addArrayObserver arrayWillChange/arrayDidChange unexpected behavior #2981
Comments
Further research seems to yield that it is indeed (currently) the expected behavior, as
So I have two questions:
|
At least as a work around, I was able to using |
I also ran into this problem. My hasMany relationship looked like it was being "reset", by some reason. componentMaterials: Ember.computed('model.someHasManyRelationship.[]', function() {
return DS.PromiseArray.create({
promise: this.get('model.someHasManyRelationship').then(r => {
return Ember.A().addObjects(r);
})
});
}), |
I'm currently running into the same issue. I do have a big process each time a record is added / deleted to a relationship. With the current behavior, whenever i add something, everything is removed then everything is append again. @miguelcobain With your solution, i don't even get the notification from the array observer. Did you find something else ? |
PR #4583 should fix this |
Short answer, yes, this is exactly what is happening. Long answer, it's actually much worse than that but I'm working on refactoring and optimizing that layer. The work from @BryanCrotaz will likely help, but after looking at his approach and the different layers of the onion I suspect a more general array diffing algorithm is what we need but to use one we need to first correct the change flow / triplicated diff that's there right now. |
@runspired I've refactored out a general array diff in PR #4583 |
#4850 was merged, this can be closed. |
I'm trying to use
DS.hasMany.addArrayObserver
to monitor when new elements are inserted (either created client side or loaded from the server). However, the arguments passed toarrayWillChange
andarrayDidChange
are weird, in that if I add one record theremoveCount
is equal to the old HasMany length and theaddCount
is equal to the new HasMany length.In other words, it looks like the "array" is emptied and all new records are added. Is this the expected behavior? If so, what is the proper way to get just the records which are being added/removed?
I have set up an example which demonstrates the difference in behavior between an array and a HasMany relationship: http://emberjs.jsbin.com/hozononusu/1/edit?html,js,console,output
The text was updated successfully, but these errors were encountered: