Created
March 11, 2011 09:25
-
-
Save 525c1e21-bd67-4735-ac99-b4b0e5262290/865667 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
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 |
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
@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