-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.coffee
47 lines (37 loc) · 965 Bytes
/
Model.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
define [
'cell/util/type'
'cell/Events'
'cell/util/spy'
], (type, Events, spy)->
Model = Events.extend
constructor: (@_a={})->
Events.call @
@parent = undefined
value.parent = @ for key,value of @_a when value instanceof Events
return
attributes: ->
@_s 'all'
result = {}
for attr of @_a
result[attr] = @_a[attr]
result
get: (key)->
@_s "change:#{key}"
@_a[key]
set: (key, value)->
old_value = @_a[key]
if (type.isS key) and (old_value isnt value)
if old_value instanceof Events
delete old_value.parent
if value instanceof Events
value.parent = @
@trigger "change:#{key}", @, (@_a[key] = value), old_value
true
destroy: ->
Events::destroy.call @
@parent?.remove [@] if @parent
delete @_a
@destroy = @attributes = @get = @set = ->
return
_s: spy.addModel
Model