5 ms·
My thoughts: > 1) You can pass a {wait:True} as the second argument to collection.create(), and the add event won't be fired until after a successful sync. If
by jcampbell1 14y ago
My thoughts:
> 1) You can pass a {wait:True} as the second argument to collection.create(), and the add event won't be fired until after a successful sync. If you want error code, you add error:funciton(){..} to the create options hash.
This is problematic. Now you completely lose the "add" event, so if you wanted to do something like add a spinner while the request is in flight, that is not possible.
> 2) You can change the event listened for from 'add', to 'sync', and still have the error handling code in the options hash.
But now you are asking about the sync status from a collection. It doesn't seem relevant to ask a collection about it's sync status when you are interested in the status of a form submission.
> 3) You can manually create the model, call save() and have the success callback be code to add the model to the collection, and the error code do something else.
This seems to be the best option to me. It puts the success, error, and model all in the same frame, which puts us in the same place as the original jQuery.
The jQuery code was far more elegant that the author would have you believe. At the core, you are handling a user interaction which comes in units of a "submission". The jquery code, wraps a "submit" into a singe activation frame and handles it.
The backbone wraps this "submit" unit up, passes it through a collection, some automated saving, and now you have no way to reason about what comes out the other end. When you submit 5 times, and have 2 failures, what do you do? What is a collection going to know?
I recognize the problem with the original jquery, but this ain't the right solution.
- sophacles 14y agoLook, I don't really care if you like backbone or not, but try to actually object to it with facts, not projections based on word semantics. All of your objections are made on incorrect assumptions of what information is provided, and what actually happens. 1) the add event isn't lost. It just doesn't fire until a success. Want to add a spinner, have it fire in the appropriate view as a response to the "submit form" event. 2) That isn't how sync is defined, and sure there may be a better name for it, but this isn't what it means. Lots of information is passed into the callback. Useful information, stuff that contradicts your objections. 3) Not the same as JQuery - you can reason about what comes out the other end, because the information is actually in the collection, with an api for getting it. The events have a great set of arguments for them. Muddling the conversation with such incorrect assertions (aka FUD) is counter-productive.