From 8fe92b94ce5e1e2857d088752d94e19db7e3d8a8 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Sun, 17 Jun 2012 22:31:44 -0700 Subject: montage v11 merge into ninja Signed-off-by: Valerio Virgillito --- node_modules/montage/montage.js | 90 +++++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 30 deletions(-) (limited to 'node_modules/montage/montage.js') diff --git a/node_modules/montage/montage.js b/node_modules/montage/montage.js index c669f3f1..0906233f 100755 --- a/node_modules/montage/montage.js +++ b/node_modules/montage/montage.js @@ -41,11 +41,8 @@ if (typeof window !== "undefined") { } })(function (require, exports, module) { - // The global context object, works for the browser and for node. - // XXX Will not work in strict mode - var global = (function() { - return this; - })(); + // The global context object + var global = new Function("return this")(); /** * Initializes Montage and creates the application singleton if @@ -106,7 +103,7 @@ if (typeof window !== "undefined") { }); }; - if ('autoPackage' in params) { + if ("autoPackage" in params) { montageRequire.injectPackageDescription(location, { dependencies: { montage: "*" @@ -114,6 +111,16 @@ if (typeof window !== "undefined") { }); } + // handle explicit package.json location + if (location.slice(location.length - 5) === ".json") { + var packageDescriptionLocation = location; + location = URL.resolve(location, "."); + montageRequire.injectPackageDescriptionLocation( + location, + packageDescriptionLocation + ); + } + return montageRequire.loadPackage(location) .then(function (applicationRequire) { global.require = applicationRequire; @@ -149,7 +156,7 @@ if (typeof window !== "undefined") { // avoid attempting to initialize a non-object if (!(object instanceof Object)) { // avoid attempting to reinitialize an aliased property - } else if (object.hasOwnProperty("_montage_metadata")) { + } else if (object.hasOwnProperty("_montage_metadata") && !object._montage_metadata.isInstance) { object._montage_metadata.aliases.push(name); object._montage_metadata.objectName = name; } else if (!Object.isSealed(object)) { @@ -269,7 +276,7 @@ if (typeof window !== "undefined") { getConfig: function() { return { - location: '' + window.location + location: "" + window.location }; }, @@ -379,7 +386,7 @@ if (typeof window !== "undefined") { } }; - global.bootstrap('core/mini-url', urlModuleFactory); + global.bootstrap("core/mini-url", urlModuleFactory); // miniature module system var bootModules = {}; @@ -410,31 +417,54 @@ if (typeof window !== "undefined") { }, initMontage: function (montageRequire, applicationRequire, params) { - // If a module was specified in the config then we initialize it now - if (params.module) { - applicationRequire.async(params.module) - .end(); - } else { - // otherwise we load the application - montageRequire.async("ui/application", function(exports) { - montageRequire.async("core/event/event-manager", function(eventManagerExports) { + var Promise, defaultEventManager, application; + + montageRequire.async("core/promise").then(function(exports) { + Promise = exports.Promise; + Promise.all([ + montageRequire.async("core/event/event-manager"), + montageRequire.async("core/deserializer") + ]).then(function(exportsArray) { + // Load the event-manager + defaultEventManager = exportsArray[0].EventManager.create().initWithWindow(window); + + // montageWillLoad is mostly for testing purposes + if (typeof global.montageWillLoad === "function") { + global.montageWillLoad(); + } - var defaultEventManager = eventManagerExports.defaultEventManager; + // Load the application - // montageWillLoad is mostly for testing purposes - if (typeof global.montageWillLoad === "function") { - global.montageWillLoad(); - } - exports.Application.load(function(application) { - window.document.application = application; - defaultEventManager.application = application; - application.eventManager = defaultEventManager; + var appProto = applicationRequire.packageDescription.applicationPrototype, + applicationDescription, appModulePromise; + if (appProto) { + applicationDescription = exportsArray[1].Deserializer.parseForModuleAndName(appProto); + appModulePromise = applicationRequire.async(applicationDescription.module); + } else { + appModulePromise = montageRequire.async("ui/application"); + } + + if (typeof window !== "undefined") { + montageRequire.async("core/event/binding").end(); + } + + appModulePromise.then(function(exports) { + application = exports[(applicationDescription ? applicationDescription.name : "Application")].create(); + window.document.application = application; + defaultEventManager.application = application; + application.eventManager = defaultEventManager; + application._load(applicationRequire, function() { + if (params.module) { + // If a module was specified in the config then we initialize it now + applicationRequire.async(params.module).end(); + } }); - }); - }); - } - } + }).end(); + }).end(); + + }); + } }; if (typeof window !== "undefined") { -- cgit v1.2.3