-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patching Model and Collection directly
- Loading branch information
1 parent
c32bd9d
commit 79d58b4
Showing
5 changed files
with
35 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(function(Backbone) { | ||
|
||
// The original Backbone.Collection that we're extending | ||
var proto = Backbone.Collection.prototype; | ||
|
||
Backbone.ViewCollection = Backbone.Collection.extend({ | ||
// TODO: ViewCollection methods | ||
}); | ||
|
||
// Add tracking to Backbone.Collection | ||
function extendCollection(name) { | ||
Backbone.ViewCollection.prototype[name] = function() { | ||
// Trigger an update on any write operation... | ||
Backbone.Virtual.track(this, 'add remove reset change create sort'); | ||
return proto[name].apply(this, arguments); | ||
}; | ||
} | ||
// ...if a Virtual function performs a Collection read operation: | ||
_.each(['get', 'getByCid', 'where', 'pluck', 'clone', 'at', 'toJSON'], extendCollection); | ||
|
||
// Alias back to Collection | ||
Backbone.Collection.prototype = Backbone.ViewCollection.prototype; | ||
|
||
})(Backbone); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters