Tom Brunoli
Tom Brunoli

Reputation: 3466

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?

Upvotes: 3

Views: 1978

Answers (2)

Tony Abou-Assaleh
Tony Abou-Assaleh

Reputation: 3040

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.

Upvotes: 7

Derick Bailey
Derick Bailey

Reputation: 72858

Marionette 100% supports AMD. There's a few wiki pages on getting it up and running, and it's pretty simple:

https://github.com/derickbailey/backbone.marionette/wiki/Using-marionette-with-requirejs

I would assume BB-R works as well, but I don't use this plugin so I'm not 100% certain.

Upvotes: 0

Related Questions