noveogroup / backbone.iobind

Bind socket.io events to backbone models & collections. Also includes a drop-in replacement for Backbone.sync using socket.io.
https://noveogroup.github.io/backbone.iobind/
582 stars 65 forks source link

Handle both normal Backbone.sync and socket.io sync #43

Closed ghost closed 10 years ago

ghost commented 11 years ago

I only have part of my api that is using socket.io. The other part is a pure reset AJAX model. How can I support a normal Backbone fetch but also utilize backbone.iobind for socket.io calls. Since backbone.iobind is overwriting Backbone.sync, it looks to be not possible. Any suggestions?

ghost commented 11 years ago

I've made a fix by returning the original sync if no socket is passed in

https://github.com/blairvanderhoof/backbone.iobind/commit/02e6f5dbb933351d5d8b44804b73f39a125fe10e#dist/backbone.iosync.js

(Based off mauron85/backbone.iobind since i also need the requirejs support)

corpulent commented 10 years ago

@blairvanderhoof this seems to only work on initial load, subsequent fetches on a normal Backbone.sync collections fail. I added this to my backbone.iosync.js, and it is working for me,

        if (false === model.socket) {
            return origSync(method, model, options);
        }

However, I still have to add a socket: false property to my regular backbone model.

mahnunchik commented 10 years ago

@corpulent @blairvanderhoof implemented in verison 0.4.8