scttnlsn / backbone.io

Backbone.js sync via Socket.IO
http://scttnlsn.github.io/backbone.io
541 stars 66 forks source link

allow io injection respecting IOC #28

Closed Incubatio closed 9 years ago

Incubatio commented 11 years ago

socket.io should be properly injected and certainly not encapsulating its initialization in backbone.io

scttnlsn commented 11 years ago

I think we should probably do the same thing client-side to keep things consistent.

Agree?

Incubatio commented 11 years ago

I do :).

Incubatio commented 11 years ago

To be more precise in my answer, I was thinking doing it that way:

// Server
var io = require('socket.io').listen(80);
var backboneio = require('backbone.io');
io.static.add('/backbone.io.js', { file: __dirname + '/browser.js' });

var backend = backboneio.createBackend();
backend.use(backboneio.middleware.memoryStore());

backboneio.listen(io, { mybackend1: backend1, mybackend2: backend2, [...] });

Note: I did put io.static.add outside because the user should be able to choose to load backbone.io another way, also putting adding the client script to socket.io from the client script of backbone.io did puzzled me ^^.

// Client
socket = io.connect('http://localhost');
backboneio.connect(Backbone, socket);
Backbone.io = Backbone.IO = backboneio.connect(socket);

Note2: Also if you intend to modify Bacbone object by adding io to it, i would recommend to do it from the outside. (if several of extensions do that, it could create conflict between names, and also let the user think backbone.io is "an official plugin" that should have some reference in Backbone source code, I think it's better if the user do it himself.

What do you think ?

scttnlsn commented 9 years ago

I'm deprecating backbone.io and continuing development on a similar project: data.io Please see the README for more information.

If you'd still like to address this in the context of data.io please open an issue/pull-request for that project.

Thanks, Scott