-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (22 loc) · 961 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
Backbone Child Collection 1.1.0
Used for REST collection that is child of a parent model.
@author Kevin Jantzer, Blackstone Audio
@since 2015-07-08
https://github.com/kjantzer/backbone-child-collection
TODO
- what happenns if the parentModel is new? should collection not fetch/save?
- if the model is destroyed, we should probably clean up all child collections
- allow for urlPath to be used to set a url on this model
*/
import Backbone from 'backbone'
Backbone.Collection.prototype.getOrCreate = require('./getOrCreate')
Backbone.Collection.prototype.getOrFetch = require('./getOrFetch')
// we're about to override these, so keep a reference to them
let orig = {
Set: Backbone.Model.prototype.set,
Get: Backbone.Model.prototype.get,
Fetch: Backbone.Model.prototype.fetch
}
Backbone.ChildCollection = Backbone.Collection.extend(require('./child-collection'))
Object.assign(Backbone.Model.prototype, require('./child-model')(orig))