Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 525c1e21-bd67-4735-ac99-b4b0e5262290/865667 to your computer and use it in GitHub Desktop.
Save 525c1e21-bd67-4735-ac99-b4b0e5262290/865667 to your computer and use it in GitHub Desktop.
node.connect (remote) ->
client.__remote__ = remote
Backbone.sync = (args...) ->
[method, model, options] = args
packet =
method: method
callback: (response) ->
options.success response
options: options
switch method
when 'create'
packet.collection_handle = model.collection.handle
packet.model_name = model.collection.model.name
packet.attributes = model.toJSON()
when 'read'
packet.collection_handle = model.handle
remote.sync packet
@sync = (args) ->
{collection_handle, model, method, attributes, callback} = args
switch method
when 'create'
collection = db[collection_handle]
new_model = collection.create attributes
collection.add new_model
new_model.id = idea.uuid()
new_model.save()
response = new Object
response.id = new_model.id
callback response
when 'read'
collection = db[collection_handle]
response = new Array
for model in collection.models
model_response = model.toJSON()
model_response.id = model.id
response.push model_response
callback response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment