scttnlsn / backbone.io

Backbone.js sync via Socket.IO

Home Page:http://scttnlsn.github.io/backbone.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AMD Support

jackp opened this issue · comments

Hi Scott,

I'm currently getting this error when trying to sync my model. In one of my backbone view, when I run (this.model.save()), I get the above error on line 19 of backbone.io.js.

Any idea what I'm missing?

Here is the code:

Server:

/*====================================================
  Backbone.io Configuration
  ====================================================*/
var backboneio = require('backbone.io');

// Session Backend
var session = backboneio.createBackend();
session.use(backboneio.middleware.cookieParser());
session.use(backboneio.middleware.session({ store: sessionStore }));
session.use('create', 'update', 'delete', auth);

// Users Backend
var users = backboneio.createBackend();

users.use(backboneio.middleware.mongooseStore(mongoose.model('Users')));
users.use('update', 'delete', auth);
var sio = backboneio.listen(app, { sessions: session, users: users });

Client:

define([
'underscore',
'backbone',
'socketio',
'backboneio'
], function(_, Backbone, sio, bio) {
var UserModel = Backbone.Model.extend({

// Override Backbone model identifier to match that of MongoDB
idAttribute: "_id",

// Sets backend in Backbone.io
backend: "users",

defaults: {
  firstName: "Jack",
  lastName: "Parker"
},

initialize: function() {

}

});
return UserModel;
});

I'm guessing that the problem has something to do with the way you are loading scripts. Currently Backbone.IO expects Backbone to be available in the global namespace when it is loaded. How are you defining backbone and backboneio AMD modules?

Hi Scott,

Thanks for getting back to me.

Yes, I'm currently using RequireJS to load scripts, which uses AMD modules.
I'll try taking them out and loading them directly and see what happens.

-Jack

On Thu, Mar 22, 2012 at 11:56 AM, Scott Nelson <
reply@reply.github.com

wrote:

I'm guessing that the problem has something to do with the way you are
loading scripts. Currently Backbone.IO expects Backbone to be available
in the global namespace when it is loaded. How are you defining backbone
and backboneio AMD modules?


Reply to this email directly or view it on GitHub:
#8 (comment)

Well, for the life of me I just can't get it working. Ideally I'd like Backbone.io to work with RequireJS and the two AMD versions of backbone and underscore in this repo https://github.com/amdjs . Those claim that they put Backbone in the global namespace for modules like this that are looking for it there, but it doesnt seem to be picking it up.

I know this is probably well outside of your scope, but if you have any ideas on how to have this library work in RequireJS I'd love to hear them.

Thanks

I'm not sure about the samantics of RequireJS but could it be returning a copy of the Backbone module each time it is required? Backbone.io extends some core Backbone classes but only in the Backbone module from the global namespace. Just a thought. It would be nice to get this working with AMD.

Hi Scott,

I'm still trying to figure that out myself. I've built a working testbed at https://github.com/jackp/Backbone.io-AMD-test if you want to check it out. I'm new to AMD myself, but I'm going to try and see how to get backbone.io working with it because I definitely want to use it in my project.

im running into this exact same error... Backbone is available in the global namespace.

I set some breakpoints in my console and it would appear that the assignment on line 15 of backbone.is.js is not returning the correct thing

var backend = model.backend || (model.collection && model.collection.backend);

is giving me just "messages" (a string)

any help would be greatly appreciated... this library is perfect for my needs!

Hi there,

are there any updates on this? The https://github.com/jackp/Backbone.io-AMD-test is a 404 right now. Would be very cool if you could get this working with AMD.

Greetings

What was the error message? It looks like the issue has been updated and the original title has changed.

I get a Backbone is not defined error when running the js file built by the r.js optimiser. I'm using shim like so:

shim:
{
    backboneio: ['backbone', 'socketio']
}

Does this work for you guys? https://github.com/lboynton/backbone.io/tree/amd

All I've done is wrap it in an AMD define so that you don't have to use the shim config.

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