Jean-Yves Didier

finalized bundle creation from application description

/******/ "use strict";
/******/ var __webpack_modules__ = ([
/* 0 */
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
......@@ -1264,16 +1265,17 @@ __webpack_require__.r(__webpack_exports__);
* @param ctx {object} an object representing data for the context.
*/
let Context = function( ctx ) {
var components = {};
var constants = {};
var factories = {};
var libraries = [];
let components = {};
let constants = {};
let factories = {};
let libraries = [];
//var depLibPromises=[];
var self = this;
let self = this;
var loadLibraries;
var loadDataFile;
var promiseLibrary;
var instanciateComponents;
let preInit = false;
factories.StateMachine = _statemachine_js__WEBPACK_IMPORTED_MODULE_0__.default;
......@@ -1330,9 +1332,8 @@ let Context = function( ctx ) {
return Promise.all(res);
};
var instanciateComponents = function() {
var instanciateComponents = async function() {
var p, promises=[];
for (p in components) {
if (components.hasOwnProperty(p)) {
if (factories[components[p].type] === undefined) {
......@@ -1472,6 +1473,14 @@ let Context = function( ctx ) {
};
this.addFactories = function(obj) {
preInit = true;
for(p in obj) {
if( obj.hasOwnProperty(p))
factories[p] = obj[p];
}
};
this.setFactory = function(key, factory ) {
factories[key] = factory;
};
......@@ -1522,11 +1531,15 @@ let Context = function( ctx ) {
};
// this should return a promise !
this.instanciate = function () {
this.instanciate = async function () {
//! TODO
return loadLibraries().then(instanciateComponents)
.catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); });
try {
if (!preInit)
await loadLibraries();
await instanciateComponents();
} catch(e) {
console.error("[ARCS] Trouble instanciating context", e);
};
};
......@@ -2088,12 +2101,18 @@ let Application = function () {
delete sheets[sName];
};
preProcess = function () {
this.launch = function () {
console.log("[ARCS] Starting application...");
// first, we should instanciate components
var i, temp, sheetList;
temp = context.getComponent(controller); //[controller].instance;
controller = temp;
if (controller === undefined) {
console.error("[ARCS] undefined controller");
return ;
}
// then we should work on sheets
sheetList = Object.keys(sheets);
for (i = 0; i < sheetList.length; i++) {
......@@ -2223,13 +2242,14 @@ let Application = function () {
this.setDependency = function (key) {
dependencies[key] = {};
};
/**
* Starts the application
*/
this.start = function () {
console.log("[ARCS] Starting application...");
context.instanciate().then(preProcess);
this.start = async function () {
console.log("[ARCS] Instanciating components...");
await context.instanciate();
this.launch();
};
};
......
This diff is collapsed. Click to expand it.
......@@ -12,7 +12,7 @@ import ARCS from "./arcs.js";
console.log("[ARCS] Bootstrapping...");
var baseUrl, appDescription, requireMarkup, xhr;
let baseUrl, appDescription, requireMarkup, xhr;
requireMarkup = document.querySelector('[data-arcsapp]');
if (requireMarkup !== undefined) {
......@@ -22,13 +22,13 @@ if (requireMarkup !== undefined) {
(async function toto() {
var description = await(fetch(appDescription));
var applicationObject = await(description.json());
let description = await(fetch(appDescription));
let applicationObject = await(description.json());
console.log("[ARCS] Application description loaded");
var aap = new ARCS.Application();
aap.import(applicationObject);
let aap = new ARCS.Application();
await aap.import(applicationObject);
aap.start();
})();
......
......@@ -62,12 +62,18 @@ let Application = function () {
delete sheets[sName];
};
preProcess = function () {
this.launch = function () {
console.log("[ARCS] Starting application...");
// first, we should instanciate components
var i, temp, sheetList;
temp = context.getComponent(controller); //[controller].instance;
controller = temp;
if (controller === undefined) {
console.error("[ARCS] undefined controller");
return ;
}
// then we should work on sheets
sheetList = Object.keys(sheets);
for (i = 0; i < sheetList.length; i++) {
......@@ -197,13 +203,14 @@ let Application = function () {
this.setDependency = function (key) {
dependencies[key] = {};
};
/**
* Starts the application
*/
this.start = function () {
console.log("[ARCS] Starting application...");
context.instanciate().then(preProcess);
this.start = async function () {
console.log("[ARCS] Instanciating components...");
await context.instanciate();
this.launch();
};
};
......
......@@ -12,7 +12,7 @@ import ARCS from "./arcs.js";
console.log("[ARCS] Bootstrapping...");
var baseUrl, appDescription, requireMarkup, xhr;
let baseUrl, appDescription, requireMarkup, xhr;
requireMarkup = document.querySelector('[data-arcsapp]');
if (requireMarkup !== undefined) {
......@@ -22,13 +22,13 @@ if (requireMarkup !== undefined) {
(async function toto() {
var description = await(fetch(appDescription));
var applicationObject = await(description.json());
let description = await(fetch(appDescription));
let applicationObject = await(description.json());
console.log("[ARCS] Application description loaded");
var aap = new ARCS.Application();
aap.import(applicationObject);
let aap = new ARCS.Application();
await aap.import(applicationObject);
aap.start();
})();
......
......@@ -2,11 +2,35 @@
*
*/
const path=require('path');
module.exports = function arcsappToJs(options, loaderContext, content) {
// content is here our file arcsapp.json
let code = `let descr=${content};`
let descr = JSON.parse(content);
console.log(descr.context.libraries);
let code = `import ARCS from '../../build/arcs.js';\n`;
let libs = [];
let libCnt = 0;
descr.context.libraries.forEach( e => {
let libPath = path.resolve(__dirname, '../build', e);
code += `import __obj${libCnt} from '${libPath}';\n`;
libs.push(`__obj${libCnt}`);
libCnt ++;
});
code += `let descr=${content};\n`;
code += `let aap = new ARCS.Application();\n`;
code += `aap.import(descr);\n`;
libs.forEach( l => {
code += `aap.getContext().addFactories(${l});\n`;
});
code += `aap.start();\n`;
return {
cacheable : true,
......
......@@ -8,16 +8,17 @@ import isInNode from './arcs.js';
* @param ctx {object} an object representing data for the context.
*/
let Context = function( ctx ) {
var components = {};
var constants = {};
var factories = {};
var libraries = [];
let components = {};
let constants = {};
let factories = {};
let libraries = [];
//var depLibPromises=[];
var self = this;
let self = this;
var loadLibraries;
var loadDataFile;
var promiseLibrary;
var instanciateComponents;
let preInit = false;
factories.StateMachine = StateMachine;
......@@ -74,9 +75,8 @@ let Context = function( ctx ) {
return Promise.all(res);
};
var instanciateComponents = function() {
var instanciateComponents = async function() {
var p, promises=[];
for (p in components) {
if (components.hasOwnProperty(p)) {
if (factories[components[p].type] === undefined) {
......@@ -216,6 +216,14 @@ let Context = function( ctx ) {
};
this.addFactories = function(obj) {
preInit = true;
for(p in obj) {
if( obj.hasOwnProperty(p))
factories[p] = obj[p];
}
};
this.setFactory = function(key, factory ) {
factories[key] = factory;
};
......@@ -266,11 +274,15 @@ let Context = function( ctx ) {
};
// this should return a promise !
this.instanciate = function () {
this.instanciate = async function () {
//! TODO
return loadLibraries().then(instanciateComponents)
.catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); });
try {
if (!preInit)
await loadLibraries();
await instanciateComponents();
} catch(e) {
console.error("[ARCS] Trouble instanciating context", e);
};
};
......
<html>
<head>
<title>ARCS engine</title>
<script type="module" src="loop_bundle.js">
</script>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>ARCS in Web Browser</h1>
<div style="height:80vh; overflow: auto; border: solid 1px navy;">
<p id="output" style="margin: 5px; padding: 5px; font-family: monospace;"></p>
<div>
</body>
</html>
......@@ -7,7 +7,7 @@ module.exports = {
output: {
path: path.resolve(__dirname, ''),
filename: "toto.js"
filename: "loop_bundle.js"
},
module: {
rules: [
......