You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Normal change events are triggered after all changes needed from a call to Backbone.Model.set has been made. However, delegated change events are triggered after each change made to the related attribute.
Example:
varCompany=Backbone.RelationalModel.extend({relations: {employees: Backbone.Collection.extend({})}});varaCompany=newCompany();// Set 1aCompany.set("name","Kinship ltd");// Set 2aCompany.set("employees",[{name: "Martin"},{name: "Gustaf"}]);// Set 3aCompany.set({name: "Kinship.com",employees: [{name: "Henric"},{name: "Mateusz"}]});
With current functionality:
Set 1 triggers 1 change:name event (after all attributes have been changed).
Set 2 triggers 2 change:employees events (one after each added employee).
Set 3 triggers 4 change:employees events (one after each removed and added employee) and 1 change:name event (after all attributes have been changed).
My suggestion is this:
Set 2 triggers 1 change:employees event (after all attributes have been changed).
Set 3 triggers 1 change:employees event and 1 change:name event (after all attributes have been changed).
Also, make sure that Set 2 triggers a change event after all related attributes have changed. (Not sure if this is currently done or not.)
This will bring delegated changes more in line with how normal changes behave (one change event for each changed attribute). Also, the model will be in a completely changed state instead of partial when the change event is triggered, just as with a normal change event.
Normal change events are triggered after all changes needed from a call to Backbone.Model.set has been made. However, delegated change events are triggered after each change made to the related attribute.
Example:
With current functionality:
Set 1 triggers 1
change:name
event (after all attributes have been changed).Set 2 triggers 2
change:employees
events (one after each added employee).Set 3 triggers 4
change:employees
events (one after each removed and added employee) and 1change:name
event (after all attributes have been changed).My suggestion is this:
Set 2 triggers 1
change:employees
event (after all attributes have been changed).Set 3 triggers 1
change:employees
event and 1change:name
event (after all attributes have been changed).Also, make sure that Set 2 triggers a
change
event after all related attributes have changed. (Not sure if this is currently done or not.)This will bring delegated changes more in line with how normal changes behave (one change event for each changed attribute). Also, the model will be in a completely changed state instead of partial when the change event is triggered, just as with a normal change event.
Related to #7
The text was updated successfully, but these errors were encountered: