Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone-relational with Require.js (AMD)

I'm working on a fairly large web app in which I am going to be using require.js so I can compile it once it's ready for production, but I would like to use backbone-relational. I am also going to be using backbone-marionette, but I am not sure how it would be included in the define function of modules.

Does anyone have any experience with this?

like image 273
Tom Brunoli Avatar asked Jul 18 '26 14:07

Tom Brunoli


1 Answers

I'm using Backbone Marionette with Relational and loading them with Require.js. The basic idea is that you need to ensure Relational is loaded. One way to do it is to include Relational as a requirement whenever you define a Relational model.

In my project, I created a simple script called bbloader.js (Backbone Loader) that loads all the relevant backbone models:

define([
  'backbone',
  'iosync',
  'iobind',
  'relational',
  'marionette',
  'marionette.async'
  ], function(Backbone) {
    return Backbone;
});

And then throughout the project, I require bbloader instead of Backbone. For example:

define([
  'jquery',
  'underscore',
  'bbloader',
  // ...
], function($, _, Backbone) {
  // ...
});

Backbone Relational is already AMD compatible, so you shouldn't need to do anything extra there.

like image 173
Tony Abou-Assaleh Avatar answered Jul 22 '26 02:07

Tony Abou-Assaleh