Showing
9 changed files
with
123 additions
and
42 deletions
1 | +/******/ "use strict"; | ||
1 | /******/ var __webpack_modules__ = ([ | 2 | /******/ var __webpack_modules__ = ([ |
2 | /* 0 */ | 3 | /* 0 */ |
3 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | 4 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
... | @@ -1264,16 +1265,17 @@ __webpack_require__.r(__webpack_exports__); | ... | @@ -1264,16 +1265,17 @@ __webpack_require__.r(__webpack_exports__); |
1264 | * @param ctx {object} an object representing data for the context. | 1265 | * @param ctx {object} an object representing data for the context. |
1265 | */ | 1266 | */ |
1266 | let Context = function( ctx ) { | 1267 | let Context = function( ctx ) { |
1267 | - var components = {}; | 1268 | + let components = {}; |
1268 | - var constants = {}; | 1269 | + let constants = {}; |
1269 | - var factories = {}; | 1270 | + let factories = {}; |
1270 | - var libraries = []; | 1271 | + let libraries = []; |
1271 | //var depLibPromises=[]; | 1272 | //var depLibPromises=[]; |
1272 | - var self = this; | 1273 | + let self = this; |
1273 | var loadLibraries; | 1274 | var loadLibraries; |
1274 | var loadDataFile; | 1275 | var loadDataFile; |
1275 | var promiseLibrary; | 1276 | var promiseLibrary; |
1276 | var instanciateComponents; | 1277 | var instanciateComponents; |
1278 | + let preInit = false; | ||
1277 | 1279 | ||
1278 | 1280 | ||
1279 | factories.StateMachine = _statemachine_js__WEBPACK_IMPORTED_MODULE_0__.default; | 1281 | factories.StateMachine = _statemachine_js__WEBPACK_IMPORTED_MODULE_0__.default; |
... | @@ -1330,9 +1332,8 @@ let Context = function( ctx ) { | ... | @@ -1330,9 +1332,8 @@ let Context = function( ctx ) { |
1330 | return Promise.all(res); | 1332 | return Promise.all(res); |
1331 | }; | 1333 | }; |
1332 | 1334 | ||
1333 | - var instanciateComponents = function() { | 1335 | + var instanciateComponents = async function() { |
1334 | var p, promises=[]; | 1336 | var p, promises=[]; |
1335 | - | ||
1336 | for (p in components) { | 1337 | for (p in components) { |
1337 | if (components.hasOwnProperty(p)) { | 1338 | if (components.hasOwnProperty(p)) { |
1338 | if (factories[components[p].type] === undefined) { | 1339 | if (factories[components[p].type] === undefined) { |
... | @@ -1472,6 +1473,14 @@ let Context = function( ctx ) { | ... | @@ -1472,6 +1473,14 @@ let Context = function( ctx ) { |
1472 | }; | 1473 | }; |
1473 | 1474 | ||
1474 | 1475 | ||
1476 | + this.addFactories = function(obj) { | ||
1477 | + preInit = true; | ||
1478 | + for(p in obj) { | ||
1479 | + if( obj.hasOwnProperty(p)) | ||
1480 | + factories[p] = obj[p]; | ||
1481 | + } | ||
1482 | + }; | ||
1483 | + | ||
1475 | this.setFactory = function(key, factory ) { | 1484 | this.setFactory = function(key, factory ) { |
1476 | factories[key] = factory; | 1485 | factories[key] = factory; |
1477 | }; | 1486 | }; |
... | @@ -1522,11 +1531,15 @@ let Context = function( ctx ) { | ... | @@ -1522,11 +1531,15 @@ let Context = function( ctx ) { |
1522 | }; | 1531 | }; |
1523 | 1532 | ||
1524 | // this should return a promise ! | 1533 | // this should return a promise ! |
1525 | - this.instanciate = function () { | 1534 | + this.instanciate = async function () { |
1526 | //! TODO | 1535 | //! TODO |
1527 | - return loadLibraries().then(instanciateComponents) | 1536 | + try { |
1528 | - .catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); }); | 1537 | + if (!preInit) |
1529 | - | 1538 | + await loadLibraries(); |
1539 | + await instanciateComponents(); | ||
1540 | + } catch(e) { | ||
1541 | + console.error("[ARCS] Trouble instanciating context", e); | ||
1542 | + }; | ||
1530 | }; | 1543 | }; |
1531 | 1544 | ||
1532 | 1545 | ||
... | @@ -2088,12 +2101,18 @@ let Application = function () { | ... | @@ -2088,12 +2101,18 @@ let Application = function () { |
2088 | delete sheets[sName]; | 2101 | delete sheets[sName]; |
2089 | }; | 2102 | }; |
2090 | 2103 | ||
2091 | - preProcess = function () { | 2104 | + this.launch = function () { |
2105 | + console.log("[ARCS] Starting application..."); | ||
2092 | // first, we should instanciate components | 2106 | // first, we should instanciate components |
2093 | var i, temp, sheetList; | 2107 | var i, temp, sheetList; |
2094 | 2108 | ||
2095 | temp = context.getComponent(controller); //[controller].instance; | 2109 | temp = context.getComponent(controller); //[controller].instance; |
2096 | controller = temp; | 2110 | controller = temp; |
2111 | + | ||
2112 | + if (controller === undefined) { | ||
2113 | + console.error("[ARCS] undefined controller"); | ||
2114 | + return ; | ||
2115 | + } | ||
2097 | // then we should work on sheets | 2116 | // then we should work on sheets |
2098 | sheetList = Object.keys(sheets); | 2117 | sheetList = Object.keys(sheets); |
2099 | for (i = 0; i < sheetList.length; i++) { | 2118 | for (i = 0; i < sheetList.length; i++) { |
... | @@ -2227,9 +2246,10 @@ let Application = function () { | ... | @@ -2227,9 +2246,10 @@ let Application = function () { |
2227 | /** | 2246 | /** |
2228 | * Starts the application | 2247 | * Starts the application |
2229 | */ | 2248 | */ |
2230 | - this.start = function () { | 2249 | + this.start = async function () { |
2231 | - console.log("[ARCS] Starting application..."); | 2250 | + console.log("[ARCS] Instanciating components..."); |
2232 | - context.instanciate().then(preProcess); | 2251 | + await context.instanciate(); |
2252 | + this.launch(); | ||
2233 | }; | 2253 | }; |
2234 | }; | 2254 | }; |
2235 | 2255 | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -12,7 +12,7 @@ import ARCS from "./arcs.js"; | ... | @@ -12,7 +12,7 @@ import ARCS from "./arcs.js"; |
12 | 12 | ||
13 | console.log("[ARCS] Bootstrapping..."); | 13 | console.log("[ARCS] Bootstrapping..."); |
14 | 14 | ||
15 | -var baseUrl, appDescription, requireMarkup, xhr; | 15 | +let baseUrl, appDescription, requireMarkup, xhr; |
16 | 16 | ||
17 | requireMarkup = document.querySelector('[data-arcsapp]'); | 17 | requireMarkup = document.querySelector('[data-arcsapp]'); |
18 | if (requireMarkup !== undefined) { | 18 | if (requireMarkup !== undefined) { |
... | @@ -22,13 +22,13 @@ if (requireMarkup !== undefined) { | ... | @@ -22,13 +22,13 @@ if (requireMarkup !== undefined) { |
22 | 22 | ||
23 | 23 | ||
24 | (async function toto() { | 24 | (async function toto() { |
25 | -var description = await(fetch(appDescription)); | 25 | +let description = await(fetch(appDescription)); |
26 | -var applicationObject = await(description.json()); | 26 | +let applicationObject = await(description.json()); |
27 | 27 | ||
28 | 28 | ||
29 | console.log("[ARCS] Application description loaded"); | 29 | console.log("[ARCS] Application description loaded"); |
30 | 30 | ||
31 | -var aap = new ARCS.Application(); | 31 | +let aap = new ARCS.Application(); |
32 | -aap.import(applicationObject); | 32 | +await aap.import(applicationObject); |
33 | aap.start(); | 33 | aap.start(); |
34 | })(); | 34 | })(); | ... | ... |
... | @@ -62,12 +62,18 @@ let Application = function () { | ... | @@ -62,12 +62,18 @@ let Application = function () { |
62 | delete sheets[sName]; | 62 | delete sheets[sName]; |
63 | }; | 63 | }; |
64 | 64 | ||
65 | - preProcess = function () { | 65 | + this.launch = function () { |
66 | + console.log("[ARCS] Starting application..."); | ||
66 | // first, we should instanciate components | 67 | // first, we should instanciate components |
67 | var i, temp, sheetList; | 68 | var i, temp, sheetList; |
68 | 69 | ||
69 | temp = context.getComponent(controller); //[controller].instance; | 70 | temp = context.getComponent(controller); //[controller].instance; |
70 | controller = temp; | 71 | controller = temp; |
72 | + | ||
73 | + if (controller === undefined) { | ||
74 | + console.error("[ARCS] undefined controller"); | ||
75 | + return ; | ||
76 | + } | ||
71 | // then we should work on sheets | 77 | // then we should work on sheets |
72 | sheetList = Object.keys(sheets); | 78 | sheetList = Object.keys(sheets); |
73 | for (i = 0; i < sheetList.length; i++) { | 79 | for (i = 0; i < sheetList.length; i++) { |
... | @@ -201,9 +207,10 @@ let Application = function () { | ... | @@ -201,9 +207,10 @@ let Application = function () { |
201 | /** | 207 | /** |
202 | * Starts the application | 208 | * Starts the application |
203 | */ | 209 | */ |
204 | - this.start = function () { | 210 | + this.start = async function () { |
205 | - console.log("[ARCS] Starting application..."); | 211 | + console.log("[ARCS] Instanciating components..."); |
206 | - context.instanciate().then(preProcess); | 212 | + await context.instanciate(); |
213 | + this.launch(); | ||
207 | }; | 214 | }; |
208 | }; | 215 | }; |
209 | 216 | ... | ... |
... | @@ -12,7 +12,7 @@ import ARCS from "./arcs.js"; | ... | @@ -12,7 +12,7 @@ import ARCS from "./arcs.js"; |
12 | 12 | ||
13 | console.log("[ARCS] Bootstrapping..."); | 13 | console.log("[ARCS] Bootstrapping..."); |
14 | 14 | ||
15 | -var baseUrl, appDescription, requireMarkup, xhr; | 15 | +let baseUrl, appDescription, requireMarkup, xhr; |
16 | 16 | ||
17 | requireMarkup = document.querySelector('[data-arcsapp]'); | 17 | requireMarkup = document.querySelector('[data-arcsapp]'); |
18 | if (requireMarkup !== undefined) { | 18 | if (requireMarkup !== undefined) { |
... | @@ -22,13 +22,13 @@ if (requireMarkup !== undefined) { | ... | @@ -22,13 +22,13 @@ if (requireMarkup !== undefined) { |
22 | 22 | ||
23 | 23 | ||
24 | (async function toto() { | 24 | (async function toto() { |
25 | -var description = await(fetch(appDescription)); | 25 | +let description = await(fetch(appDescription)); |
26 | -var applicationObject = await(description.json()); | 26 | +let applicationObject = await(description.json()); |
27 | 27 | ||
28 | 28 | ||
29 | console.log("[ARCS] Application description loaded"); | 29 | console.log("[ARCS] Application description loaded"); |
30 | 30 | ||
31 | -var aap = new ARCS.Application(); | 31 | +let aap = new ARCS.Application(); |
32 | -aap.import(applicationObject); | 32 | +await aap.import(applicationObject); |
33 | aap.start(); | 33 | aap.start(); |
34 | })(); | 34 | })(); | ... | ... |
... | @@ -2,11 +2,35 @@ | ... | @@ -2,11 +2,35 @@ |
2 | * | 2 | * |
3 | */ | 3 | */ |
4 | 4 | ||
5 | +const path=require('path'); | ||
6 | + | ||
5 | module.exports = function arcsappToJs(options, loaderContext, content) { | 7 | module.exports = function arcsappToJs(options, loaderContext, content) { |
6 | // content is here our file arcsapp.json | 8 | // content is here our file arcsapp.json |
7 | 9 | ||
8 | 10 | ||
9 | - let code = `let descr=${content};` | 11 | + let descr = JSON.parse(content); |
12 | + console.log(descr.context.libraries); | ||
13 | + | ||
14 | + let code = `import ARCS from '../../build/arcs.js';\n`; | ||
15 | + let libs = []; | ||
16 | + | ||
17 | + | ||
18 | + let libCnt = 0; | ||
19 | + descr.context.libraries.forEach( e => { | ||
20 | + let libPath = path.resolve(__dirname, '../build', e); | ||
21 | + code += `import __obj${libCnt} from '${libPath}';\n`; | ||
22 | + libs.push(`__obj${libCnt}`); | ||
23 | + libCnt ++; | ||
24 | + }); | ||
25 | + | ||
26 | + code += `let descr=${content};\n`; | ||
27 | + code += `let aap = new ARCS.Application();\n`; | ||
28 | + code += `aap.import(descr);\n`; | ||
29 | + | ||
30 | + libs.forEach( l => { | ||
31 | + code += `aap.getContext().addFactories(${l});\n`; | ||
32 | + }); | ||
33 | + code += `aap.start();\n`; | ||
10 | 34 | ||
11 | return { | 35 | return { |
12 | cacheable : true, | 36 | cacheable : true, | ... | ... |
... | @@ -8,16 +8,17 @@ import isInNode from './arcs.js'; | ... | @@ -8,16 +8,17 @@ import isInNode from './arcs.js'; |
8 | * @param ctx {object} an object representing data for the context. | 8 | * @param ctx {object} an object representing data for the context. |
9 | */ | 9 | */ |
10 | let Context = function( ctx ) { | 10 | let Context = function( ctx ) { |
11 | - var components = {}; | 11 | + let components = {}; |
12 | - var constants = {}; | 12 | + let constants = {}; |
13 | - var factories = {}; | 13 | + let factories = {}; |
14 | - var libraries = []; | 14 | + let libraries = []; |
15 | //var depLibPromises=[]; | 15 | //var depLibPromises=[]; |
16 | - var self = this; | 16 | + let self = this; |
17 | var loadLibraries; | 17 | var loadLibraries; |
18 | var loadDataFile; | 18 | var loadDataFile; |
19 | var promiseLibrary; | 19 | var promiseLibrary; |
20 | var instanciateComponents; | 20 | var instanciateComponents; |
21 | + let preInit = false; | ||
21 | 22 | ||
22 | 23 | ||
23 | factories.StateMachine = StateMachine; | 24 | factories.StateMachine = StateMachine; |
... | @@ -74,9 +75,8 @@ let Context = function( ctx ) { | ... | @@ -74,9 +75,8 @@ let Context = function( ctx ) { |
74 | return Promise.all(res); | 75 | return Promise.all(res); |
75 | }; | 76 | }; |
76 | 77 | ||
77 | - var instanciateComponents = function() { | 78 | + var instanciateComponents = async function() { |
78 | var p, promises=[]; | 79 | var p, promises=[]; |
79 | - | ||
80 | for (p in components) { | 80 | for (p in components) { |
81 | if (components.hasOwnProperty(p)) { | 81 | if (components.hasOwnProperty(p)) { |
82 | if (factories[components[p].type] === undefined) { | 82 | if (factories[components[p].type] === undefined) { |
... | @@ -216,6 +216,14 @@ let Context = function( ctx ) { | ... | @@ -216,6 +216,14 @@ let Context = function( ctx ) { |
216 | }; | 216 | }; |
217 | 217 | ||
218 | 218 | ||
219 | + this.addFactories = function(obj) { | ||
220 | + preInit = true; | ||
221 | + for(p in obj) { | ||
222 | + if( obj.hasOwnProperty(p)) | ||
223 | + factories[p] = obj[p]; | ||
224 | + } | ||
225 | + }; | ||
226 | + | ||
219 | this.setFactory = function(key, factory ) { | 227 | this.setFactory = function(key, factory ) { |
220 | factories[key] = factory; | 228 | factories[key] = factory; |
221 | }; | 229 | }; |
... | @@ -266,11 +274,15 @@ let Context = function( ctx ) { | ... | @@ -266,11 +274,15 @@ let Context = function( ctx ) { |
266 | }; | 274 | }; |
267 | 275 | ||
268 | // this should return a promise ! | 276 | // this should return a promise ! |
269 | - this.instanciate = function () { | 277 | + this.instanciate = async function () { |
270 | //! TODO | 278 | //! TODO |
271 | - return loadLibraries().then(instanciateComponents) | 279 | + try { |
272 | - .catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); }); | 280 | + if (!preInit) |
273 | - | 281 | + await loadLibraries(); |
282 | + await instanciateComponents(); | ||
283 | + } catch(e) { | ||
284 | + console.error("[ARCS] Trouble instanciating context", e); | ||
285 | + }; | ||
274 | }; | 286 | }; |
275 | 287 | ||
276 | 288 | ... | ... |
tests/loop/loop_bundle.html
0 → 100644
1 | +<html> | ||
2 | + <head> | ||
3 | + <title>ARCS engine</title> | ||
4 | + <script type="module" src="loop_bundle.js"> | ||
5 | + </script> | ||
6 | + <style> | ||
7 | + body { | ||
8 | + font-family: sans-serif; | ||
9 | + } | ||
10 | + </style> | ||
11 | + </head> | ||
12 | + <body> | ||
13 | + <h1>ARCS in Web Browser</h1> | ||
14 | + <div style="height:80vh; overflow: auto; border: solid 1px navy;"> | ||
15 | + <p id="output" style="margin: 5px; padding: 5px; font-family: monospace;"></p> | ||
16 | + <div> | ||
17 | + </body> | ||
18 | +</html> |
... | @@ -7,7 +7,7 @@ module.exports = { | ... | @@ -7,7 +7,7 @@ module.exports = { |
7 | 7 | ||
8 | output: { | 8 | output: { |
9 | path: path.resolve(__dirname, ''), | 9 | path: path.resolve(__dirname, ''), |
10 | - filename: "toto.js" | 10 | + filename: "loop_bundle.js" |
11 | }, | 11 | }, |
12 | module: { | 12 | module: { |
13 | rules: [ | 13 | rules: [ | ... | ... |
-
Please register or login to post a comment