backbone.js - requireJS in multiple context -
i'm having bit of trouble contexts in requirejs. have 2 js project based on requirejs , backbone. work perfect if work on own page. context conflict each others if put them same page.
both projects follow similar module name convention.
project a:
main.js:
require.config({ baseurl : "javascript/app1/", waitseconds : 20, paths : { jquerypb : "jquery-1.10.1.min", underscore : "underscore", backbone : "backbone-min", }, shim : { underscore : { exports : "_" }, backbone : { deps : [ "underscore", "jquerypb" ], exports : "backbone" } } }); require([ "app" ], function(app) { app.startup(); });
app.js
define([ "jquerypb", "backbone", "underscore", "models/app", "views/app" ], function($jpb, backbone, _, appmodel, appview) { var appinfo = new appmodel(); var app = new appview({ model : appinfo }); return app; });
views/app.js
define( ["jquerypb", "backbone", "views/moduleb"], function($jpb, backbone, moduleb) { var appview = backbone.view.extend({ ....
views/moduleb
in moduleb, need access properties of app instance (project a). use var app = require("app");
project b:
the project b has similar module structure project a. renamed app.js appb. there modulec need access properties of app instance (project b)
var appb = require("appb")
i got following error when access them host html page:
uncaught error: module name "app" has not been loaded yet context: _. use require([])
or error on loading project b sometimes:
uncaught error: module name "appb" has not been loaded yet context: _. use require([])
it looks trying load module each other's context or global context, 1 app instance stored in there.
how set modules live in own project context?
thanks
Comments
Post a Comment