Skip to content

Commit

Permalink
First commit to get data/main.datareel loaded by default
Browse files Browse the repository at this point in the history
  • Loading branch information
marchant committed Jan 7, 2019
1 parent 55097e1 commit f432853
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 49 deletions.
14 changes: 11 additions & 3 deletions core/serialization/deserializer/montage-reviver.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,15 +968,23 @@ var MontageReviver = exports.MontageReviver = Montage.specialize(/** @lends Mont
value: function (locationId) {
var moduleId,
objectName,
bracketIndex = locationId.indexOf("[");
bracketIndex = locationId.indexOf("["),
mjsonIndex, slashIndex;

if (bracketIndex > 0) {
moduleId = locationId.substr(0, bracketIndex);
objectName = locationId.slice(bracketIndex + 1, -1);
} else {
}
else {
moduleId = locationId;
this._findObjectNameRegExp.test(locationId);
objectName = RegExp.$1.replace(

objectName = RegExp.$1;
if((mjsonIndex = objectName.indexOf(".mjson")) !== -1) {
objectName = objectName.substr((slashIndex = objectName.indexOf("/")) === -1 ? 0 : slashIndex+1, mjsonIndex-(slashIndex+1));
}

objectName = objectName.replace(
this._toCamelCaseRegExp,
this._replaceToCamelCase
);
Expand Down
119 changes: 73 additions & 46 deletions montage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
function finallyHandler() {
// remove clutter
if (script.parentNode) {
script.parentNode.removeChild(script);
script.parentNode.removeChild(script);
}
}

Expand All @@ -64,11 +64,11 @@
}
} else {
throw new Error("Platform not supported");
}
}
}

exports.initBrowser = function initBrowser() {

return {

resolveUrl: (function makeResolveUrl() {
Expand Down Expand Up @@ -131,7 +131,7 @@

if (!params) {
params = this._params = {};

// Find the <script> that loads us, so we can divine our
// parameters from its attributes.
var i, j, match, script, attr, name,
Expand Down Expand Up @@ -189,7 +189,7 @@

return params;
},

loadPackage: function (dependency, config, packageDescription) {
return mr.loadPackage(dependency, config, packageDescription);
},
Expand Down Expand Up @@ -237,8 +237,8 @@
var module = dependencies[id];

if (
module &&
moduleHasExport(module) === false &&
module &&
moduleHasExport(module) === false &&
typeof module.factory === "function"
) {
module.exports = module.factory(bootModule, (module.exports = {})) || module.exports;
Expand All @@ -257,9 +257,9 @@
if (!dependencies.hasOwnProperty(id)) {
return;
}

dependencies[id].factory = factory;

for (id in dependencies) {
if (dependencies.hasOwnProperty(id)) {
// this causes the function to exit if there are any remaining
Expand All @@ -278,7 +278,7 @@

// Restore inital Boostrap
if (initalBoostrap) {
global.bootstrap = initalBoostrap;
global.bootstrap = initalBoostrap;
}

// At least bootModule in order
Expand All @@ -288,16 +288,16 @@

mrRequire.delegate = exports;
exports.mrPromise = mrPromise;

callback(mrRequire, mrPromise, miniURL);
}

// This define if the script should be loaded has "nested" of "flat" dependencies in packagesLocation.
// Change to "nested" for npm 2 support or add data-packages-strategy="nested" on montage.js script tag.
var defaultStrategy = params.packagesStrategy || 'nested';
var defaultStrategy = params.packagesStrategy || 'nested';

function bootstrapModuleScript(module, strategy) {
module.strategy = strategy || defaultStrategy;
module.strategy = strategy || defaultStrategy;
var locationRoot = strategy === "flat" ? params.packagesLocation : params.location;
module.script = resolveUrl(locationRoot, module.location);
loadScript(module.script, function (err, script) {
Expand All @@ -312,7 +312,7 @@
defaultStrategy = module.strategy;
bootstrapModule(module.id, function (bootRequire, exports) {
if (module.export) {
exports[module.export] = global[module.global];
exports[module.export] = global[module.global];
} else {
return global[module.global];
}
Expand All @@ -338,11 +338,11 @@
location: module
};
} else {
module.id = id;
module.id = id;
}

// Update dependency
dependencies[id] = module;
dependencies[id] = module;
// Update locatiom from param
module.location = params.hasOwnProperty(paramModuleLocation) ? params[paramModuleLocation] : module.location;

Expand All @@ -355,7 +355,7 @@
bootstrapModuleScript(module);
}
}
}
}
}
};
};
Expand Down Expand Up @@ -393,10 +393,10 @@
params.location = params[paramNamespace + 'Location'] = location;
// Detect command line
if (
typeof process !== "undefined" &&
typeof process !== "undefined" &&
typeof process.argv !== "undefined"
) {

var command, module, modulePackage,
args = process.argv.slice(1);

Expand All @@ -411,14 +411,14 @@
}

params.module = PATH.basename(module);
params.package = PATH.dirname(FS.realpathSync(module)) + "/";
params.package = PATH.dirname(FS.realpathSync(module)) + "/";
}
}
}

return params;
return params;
},

loadPackage: function (dependency, config, packageDescription) {
return mr.loadPackage(dependency, config, packageDescription);
},
Expand Down Expand Up @@ -460,7 +460,7 @@
exports.initMontageCustomElement = function () {

if (
typeof customElements === 'undefined' ||
typeof customElements === 'undefined' ||
typeof Reflect === 'undefined'
) {
return void 0;
Expand Down Expand Up @@ -603,7 +603,7 @@
mainEnterDocument = component.enterDocument,
mainTemplateDidLoad = component.templateDidLoad,
proxyElement = this.findProxyForElement(this);

if (proxyElement) {
var observedAttributes = this.observedAttributes,
observedAttribute,
Expand All @@ -619,7 +619,7 @@
}
}
}

this.application.eventManager.registerTargetForActivation(shadowRoot);

component.templateDidLoad = function () {
Expand Down Expand Up @@ -678,7 +678,7 @@
location = params.location,
applicationModuleId = params.module || "",
applicationLocation = miniURL.resolve(platform.getLocation(), params.package || ".");

// Exports mrRequire as Require
exports.Require = mrRequire;

Expand All @@ -690,11 +690,11 @@
var getDefinition = function (name) {
return (bundleDefinitions[name] = bundleDefinitions[name] || Promise.resolve());
};

global.bundleLoaded = function (name) {
return getDefinition(name).resolve();
};

var preloading = Promise.resolve();
config.preloaded = preloading.promise;

Expand Down Expand Up @@ -775,7 +775,7 @@
window.addEventListener("message", messageCallback);
});


// TODO need test
applicationRequirePromise = trigger.spread(function (location, injections) {
var promise = mrRequire.loadPackage({
Expand Down Expand Up @@ -882,10 +882,10 @@
var Montage = montageRequire("core/core").Montage;
var EventManager = montageRequire("core/event/event-manager").EventManager;
var defaultEventManager = montageRequire("core/event/event-manager").defaultEventManager;
var MontageDeserializer = montageRequire("core/serialization/deserializer/montage-deserializer").MontageDeserializer;
var MontageDeserializer = montageRequire("core/serialization/deserializer/montage-deserializer").MontageDeserializer;
var MontageReviver = montageRequire("core/serialization/deserializer/montage-reviver").MontageReviver;
var logger = montageRequire("core/logger").logger;


exports.MontageDeserializer = new MontageDeserializer; // Create instance once only

Expand All @@ -904,28 +904,55 @@
appModulePromise = montageRequire.async("core/application");
}

// Load main.datareel/main.mjson
var mainDatareel = applicationRequire.packageDescription.mainDatareel,
mainDatareelLocation, mainDatareelModulePromise;

if (mainDatareel) {
mainDatareelLocation = MontageReviver.parseObjectLocationId(mainDatareel);
mainDatareelModulePromise = applicationRequire.async(mainDatareelLocation.moduleId);
} else {
//mainDatareelModulePromise = applicationRequire.makeRequire("data/main.datareel/main.mjson").async("data/main.datareel/main.mjson");
mainDatareelLocation = "data/main.datareel/main.mjson";
mainDatareelModulePromise = applicationRequire.async("data/main.datareel/main.mjson");
//mainDatareelModulePromise = mrPromise.resolve();
}


return appModulePromise.then(function (exports) {

var Application = exports[(applicationLocation ? applicationLocation.objectName : "Application")];
var application = new Application();
defaultEventManager.application = application;
application.eventManager = defaultEventManager;

return application._load(applicationRequire, function() {

// If a module was specified in the config then we initialize it now
if (applicationModuleId) {
applicationRequire.async(applicationModuleId);
}
return mainDatareelModulePromise.then(function(mainDataServiceExport) {
// fulfillment
application.service = mainDataServiceExport.montageObject;
return application;
}, function(reason) {
// rejection
console.log("App failed to load datareel at location:",mainDatareelLocation,reason);
return application;
}).finally(function() {

return application._load(applicationRequire, function() {

// If a module was specified in the config then we initialize it now
if (applicationModuleId) {
applicationRequire.async(applicationModuleId);
}

if (typeof global.montageDidLoad === "function") {
global.montageDidLoad();
}
if (typeof global.montageDidLoad === "function") {
global.montageDidLoad();
}

if (typeof window !== "undefined" && window && window.MontageElement) {
MontageElement.applicationReady(application, MontageReviver);
}
if (typeof window !== "undefined" && window && window.MontageElement) {
MontageElement.applicationReady(application, MontageReviver);
}
});
});

});
});
});
Expand Down Expand Up @@ -962,12 +989,12 @@
exports.compileMJSONFile = function (mjson, require, moduleId) {
return exports.getMontageDeserializer().then(function (deserializer) {
deserializer.init(mjson, require, void 0, require.location + moduleId);
return deserializer.deserializeObject();
return deserializer.deserializeObject();
});
};

if (
typeof window !== "undefined" ||
typeof window !== "undefined" ||
(typeof module === 'object' && module.exports &&
typeof require !== "undefined")
) {
Expand All @@ -984,4 +1011,4 @@
}

return exports;
}));
}));
1 change: 1 addition & 0 deletions test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ module.exports = require("montage-testing").run(require, [
{name: "spec/data/raw-data-service"},
{name: "spec/data/raw-data-type-mapping-spec"},
{name: "spec/data/integration", node: false},
{name: "spec/data/core-integration"},

// Meta
{name: "spec/meta/module-object-descriptor-spec"},
Expand Down
11 changes: 11 additions & 0 deletions test/spec/data/core-integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var Deserializer = require("montage/core/serialization/deserializer/montage-deserializer").MontageDeserializer,
serialization = require("spec/data/logic/service/montage-data.mjson");


describe("Core Integration", function() {

it("Main Datareel is deserialized", function () {
var service = application.service;
expect(service).toBeDefined();
});
});

0 comments on commit f432853

Please sign in to comment.