Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
23 lines (18 sloc) 470 Bytes
$J.ViewModel = $J.Emitter.extend do
constructor: ->
@initialize? ...
@
initialize: ->
@views = {}
@on '$J:sync:start', (view)~>
@views[view.cid] = view
if (_.keys @views)length is 1
@connect!
@on '$J:sync:end', (view)->
delete @views[view.cid]
if (_.keys @views)length is 0
@disconnect!
connect: (->)
disconnect: (-> @stopListening!)
sync: !->
@trigger '$J:sync', ...@@