-
Notifications
You must be signed in to change notification settings - Fork 0
/
rxcollection.coffee
55 lines (39 loc) · 1.14 KB
/
rxcollection.coffee
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict'
define (require) ->
Phos = {}
Helpers = require "./helpers/_helpers_"
###
RXCollection
###
class Phos.RXCollection
###
Console logging
@property {Phos.Helpers.Logger}
###
logger = new Helpers.Logger()
###
The Model to use for this Collection.
The Model name must be a different name than the Collection. It is preferrable
and best practice that the Collection is the plural version of the name used
for the Model.
eg. Collection --> People, Model --> Person
@property {Phos.RXModel}
###
model: null
collection: null
###
Constructor
@param collection {Backbone.Collection}
@param RXModel {Phos.RXModel} RXModel constructor
###
constructor: (collection, RXModel) ->
# Backbone collection
@collection = collection
# RXModel constructor
@model = RXModel
rc = rx.array(_.map collection.models, (model) => new @model(model) )
@collection.on(
add: (model) => rc.push new @model(model)
remove: (model, collection, options) -> rc.removeAt(options.index)
)
_.extend @, rc