3

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?

Tom Brunoli
  • 3,436
  • 9
  • 36
  • 54

2 Answers2

7

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.

Tony Abou-Assaleh
  • 3,000
  • 2
  • 25
  • 37
  • if backbone-relational is AMD compliant, why is there an AMD fork? https://github.com/dexnode/Backbone-relational – ckarbass Mar 08 '13 at 00:29
  • I'm curious what your require.config setup looks like, specifically how you shim these modules. – adekom Apr 20 '13 at 01:49
0

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.

Derick Bailey
  • 72,004
  • 22
  • 206
  • 219
  • Yeah I got marionette working nicely already. I'm just not sure how well it with work with backbone-relational also. I couldn't find any up-to-date info on having it work as an AMD module, and even if I did, I don't 100% understand how it would be included (to override the default backbone stuff). Thanks for the quick response! – Tom Brunoli Aug 09 '12 at 00:43
  • i see. i know bb-r works with marionette, as several of my clients are using them together. but otherwise, i can't say much about bb-r. – Derick Bailey Aug 09 '12 at 00:48
  • 1
    Backbone relational works with require.js. I used it on my last project and it I didn't have a problem. Here is a link to how to wrap up relational as a module. [AMD BBRelational](https://github.com/PaulUithol/Backbone-relational/issues/57) – jmk2142 Aug 09 '12 at 19:49
  • Under what authority can you say that: "Marionette 100% supports AMD"? – benhowdle89 Nov 30 '12 at 15:12