Created
November 13, 2013 13:11
-
-
Save svasva/7448875 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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