backbone.js - Backbone with websockets (sockjs) (changing Backbone.ajax vs Backbone.sync) -


i have confusion - if implementing websockets (sockjs) on top of backbone , marionette, then, in opinion, should require change in backbone.ajax function socket.emit , socket.on supported in place of model.save (or collection.save) , model.fetch (or collection.fetch).

however, when did research , found not case. came across -
1. derick bailey's article:
https://lostechies.com/derickbailey/2012/04/19/decoupling-backbone-apps-from-websockets/
doesn't talk changing backbone.ajax or backbone.sync, instead suggests event aggregation - part of solution of using websockets misses whole point of syncing models , collections. ok, talk backbone.iobind mentions "alternative" approach event aggregation (however, reading of article, might have missed something!).

2. , christopher keefer's article:
http://artandlogic.com/2014/06/websockets-for-backbone/
want (on socket.io) job changing parts of backbone.sync except backbone.ajax!

question whether backbone can work sockjs changing backbone.ajax function?

if want change persistence methods, should override backbone.sync

backbone.sync

you can override in order use different persistence strategy, such websockets, xml transport, or local storage.

(emphasis mine)

backbone.sync gateway persistence layer. default handled using ajax, , in cases uses jquery ajax.


backbone.ajax

if want use custom ajax function, or endpoint doesn't support jquery.ajax api , need tweak things, can setting backbone.ajax.

(emphasis mine)

backbone.ajax proxy jquery ajax:

backbone.ajax = function() {   return backbone.$.ajax.apply(backbone.$, arguments); } 

the docs says when want override backbone.ajax. unrealistic example when you're using dom manipulation library in place of jquery doesn't have built in ajax support exposed using ajax method.


backbone.sync method contains code assumes you're using ajax (it manipulates xhr object). that's should override. using ajax method isn't ajax doesn't make sense.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -