Skip to content

Instantly share code, notes, and snippets.

@svasva
Created November 13, 2013 13:11
Show Gist options
  • Save svasva/7448875 to your computer and use it in GitHub Desktop.
Save svasva/7448875 to your computer and use it in GitHub Desktop.
@h.setupPusher = (store, model, key) ->
manyHash = (d) ->
h = {}
h[model.pluralize()] = [d]
return h
c = pusher.subscribe(key)
c.bind "#{model}#new", (o) ->
Ember.run.later ->
return if store.getById(model, o.id)
store.pushPayload(model, manyHash(o))
c.bind "#{model}#update", (o) ->
Ember.run.later ->
o = store.getById(model, o.id)
return if o?.get('updatedAt') > new Date(o.updated_at)
store.pushPayload model, manyHash(o)
c.bind "#{model}#delete", (o) ->
Ember.run.later ->
store.getById(model, o.id)?.deleteRecord()
return c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment