Skip to content

Commit f2cf6c9

Browse files
committed
Not checking changes on NestedModel sub Backbone.Model/Collection as it will generate lots of
useless observers, particularly on Backbone.Model._events which may contain huge event binding data
1 parent 1cab0dc commit f2cf6c9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

backbone-nested.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,13 @@
274274
if (!opts.silent && _.isObject(newValue) && isNewValue){
275275
var visited = [];
276276
var checkChanges = function(obj, prefix) {
277-
// Don't choke on circular references
278-
if(_.indexOf(visited, obj) > -1) {
277+
// Not checking changes on sub-Backbone.Models/Collection props
278+
// in order to avoid to put observers on potential heavy objects
279+
// (typically, Backbone.Models have _events properties which may have lots of things inside it, and
280+
// we should not put useless observers on it)
281+
if(obj instanceof Backbone.Model || obj instanceof Backbone.Collection) {
282+
return;
283+
} else if(_.indexOf(visited, obj) > -1) { // Don't choke on circular references
279284
return;
280285
} else {
281286
visited.push(obj);

0 commit comments

Comments
 (0)