Skip to content

Commit cc6e2b8

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 b35e22e commit cc6e2b8

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
@@ -267,8 +267,13 @@
267267
if (!opts.silent && _.isObject(newValue) && isNewValue){
268268
var visited = [];
269269
var checkChanges = function(obj, prefix) {
270-
// Don't choke on circular references
271-
if(_.indexOf(visited, obj) > -1) {
270+
// Not checking changes on sub-Backbone.Models/Collection props
271+
// in order to avoid to put observers on potential heavy objects
272+
// (typically, Backbone.Models have _events properties which may have lots of things inside it, and
273+
// we should not put useless observers on it)
274+
if(obj instanceof Backbone.Model || obj instanceof Backbone.Collection) {
275+
return;
276+
} else if(_.indexOf(visited, obj) > -1) { // Don't choke on circular references
272277
return;
273278
} else {
274279
visited.push(obj);

0 commit comments

Comments
 (0)