backbone-ws
backbone-ws copied to clipboard
create tutorial
It would be cool to do a test project(backbone.ws)
In the pipe... :construction_worker: Thanks @goti2!
Is there any news?
Hey @smalot, thanks for the kind ping (: Unfortunately I can't seem to be able to get to my projects, but if there's an interest I'll do my best.
Many thanks, because it's very clear howto to connect multiple mode object and/or a collection
Does this plugin support bi-directional communication ? Backbone => WS WS => Backbone
@smalot let me see if I understand your question correctly:
With BBWS (Backbone.WS) you can handle server-client bi-directional communication:
- server => client: using
ws:message
events - and of course with custom routing you can achieve more complex scenarios). - client => server: either by using
.send()
method on the Model/Collection, or by settingsync: true
and simply calling.save()
. The later will send data sent to.save()
or default to the entire attributes of the model.
Indeed, Gorgeous API ! But I confirm, a tuto is a must
@smalot thanks! will do my best...
One quick remark.
When I create a new model object on client side and then call the .save()
function, the following request is transferred:
{
"id":null,
"board_id":0,
"title":"title",
"created":0,
"updated":0,
"method":"create" //
}
I note that the method
attribute has been added by the API. But when method
is defined nothing is sent.
Prefixing it by an underscore should be a good idea, or a better solution would be to create a 2 levels structure with the data in a key, and the method in another one.
{
"data": {
"id":null,
"board_id":0,
"title":"title",
"created":0,
"updated":0
},
"method": "update"
}
@smalot correct, right here.
What do you mean by "nothing is sent"? From what I see it should send everything just the same, only using your predefined method
instead of adding Backbone's method
.
What kind of behavior exactly do you see?
Honestly, I don't remember what I wanted to say by "But when method is defined nothing is sent.".
My main remark was to separate the real data extracted from the model (via toJSON()) against the method (create/update/...).
The second solution seems to be the best and is quite similar to the message exchanged from server to the client ({data: [], type: ''}
).
I'm still working on your API to understand how everything is working.
@ydaniv can I use you lib to sync a collection ? I'm encountering xhr issues
-- edited --
my goal is to push to server a collection
of model
for a global insert
or update
in order to avoid multiple calls
@smalot if you call collection.send()
this should work as expected.
If what you want is to call collection.save()
together with useSync: true
and have it persist to the server, this should also work as expected, except for the method
property, which now I see is not handled correctly. It's only handled for Model
s, and I should change it to add method
prop to each model sent.
Currently it will send the entire collection, unless you specify the data sent explicitly.
What exactly is your use case?