Showing
13 changed files
with
184 additions
and
428 deletions
... | @@ -4,6 +4,14 @@ module.exports = function (grunt) { | ... | @@ -4,6 +4,14 @@ module.exports = function (grunt) { |
4 | // Project configuration. | 4 | // Project configuration. |
5 | grunt.initConfig({ | 5 | grunt.initConfig({ |
6 | pkg: grunt.file.readJSON('package.json'), | 6 | pkg: grunt.file.readJSON('package.json'), |
7 | + copy: { | ||
8 | + dist: { | ||
9 | + files:[ | ||
10 | + {src: 'src/arcs_browser.js', dest: 'build/arcs_browser.js'} | ||
11 | + ] | ||
12 | + | ||
13 | + } | ||
14 | + }, | ||
7 | jsdoc: { | 15 | jsdoc: { |
8 | dist: { | 16 | dist: { |
9 | src: ['src/*.js', 'docs/Readme.md'], //, 'components/*.js'], | 17 | src: ['src/*.js', 'docs/Readme.md'], //, 'components/*.js'], |
... | @@ -43,29 +51,13 @@ module.exports = function (grunt) { | ... | @@ -43,29 +51,13 @@ module.exports = function (grunt) { |
43 | } | 51 | } |
44 | } | 52 | } |
45 | }, | 53 | }, |
46 | - file_minify: { | ||
47 | - build: { | ||
48 | - files: { | ||
49 | - 'build/arcs.min.js': [ | ||
50 | - 'build/arcs.js' | ||
51 | - ], | ||
52 | - 'build/arcs_browser.js': [ | ||
53 | - 'src/arcs_browser.js' | ||
54 | - ], | ||
55 | - 'build/arcseditor.min.js': [ | ||
56 | - 'build/arcseditor.js' | ||
57 | - ] | ||
58 | - | ||
59 | - } | ||
60 | - } | ||
61 | - }, | ||
62 | terser: { | 54 | terser: { |
63 | build: { | 55 | build: { |
64 | files: { | 56 | files: { |
65 | 'build/arcs.min.js': [ | 57 | 'build/arcs.min.js': [ |
66 | 'build/arcs.js' | 58 | 'build/arcs.js' |
67 | ], | 59 | ], |
68 | - 'build/arcs_browser.js': [ | 60 | + 'build/arcs_browser.min.js': [ |
69 | 'src/arcs_browser.js' | 61 | 'src/arcs_browser.js' |
70 | ], | 62 | ], |
71 | 'build/arcseditor.min.js': [ | 63 | 'build/arcseditor.min.js': [ |
... | @@ -101,7 +93,6 @@ module.exports = function (grunt) { | ... | @@ -101,7 +93,6 @@ module.exports = function (grunt) { |
101 | 'src/transitionnetwork.js', | 93 | 'src/transitionnetwork.js', |
102 | 'src/statemachine.js', | 94 | 'src/statemachine.js', |
103 | 'src/application.js', | 95 | 'src/application.js', |
104 | - 'src/arcs_module.js', | ||
105 | 'src/exports.js' | 96 | 'src/exports.js' |
106 | ], | 97 | ], |
107 | dest: 'build/arcs.js' | 98 | dest: 'build/arcs.js' |
... | @@ -124,16 +115,15 @@ module.exports = function (grunt) { | ... | @@ -124,16 +115,15 @@ module.exports = function (grunt) { |
124 | }); | 115 | }); |
125 | 116 | ||
126 | // Load the plugin that provides the "uglify" task. | 117 | // Load the plugin that provides the "uglify" task. |
127 | - grunt.loadNpmTasks('grunt-contrib-obfuscator'); | ||
128 | - grunt.loadNpmTasks('grunt-file-minify'); | ||
129 | grunt.loadNpmTasks('grunt-contrib-concat'); | 118 | grunt.loadNpmTasks('grunt-contrib-concat'); |
119 | + grunt.loadNpmTasks('grunt-contrib-copy'); | ||
130 | grunt.loadNpmTasks('grunt-jsdoc'); | 120 | grunt.loadNpmTasks('grunt-jsdoc'); |
131 | grunt.loadNpmTasks('grunt-jslint'); | 121 | grunt.loadNpmTasks('grunt-jslint'); |
132 | grunt.loadNpmTasks('grunt-terser'); | 122 | grunt.loadNpmTasks('grunt-terser'); |
133 | grunt.loadNpmTasks('grunt-bower-task'); | 123 | grunt.loadNpmTasks('grunt-bower-task'); |
134 | 124 | ||
135 | // Default task(s). | 125 | // Default task(s). |
136 | - grunt.registerTask('default', ['concat','terser'/*'file_minify','obfuscator'*/]); | 126 | + grunt.registerTask('default', ['concat','copy','terser']); |
137 | grunt.registerTask('lint', ['jslint']); | 127 | grunt.registerTask('lint', ['jslint']); |
138 | grunt.registerTask('doc', ['jsdoc']); | 128 | grunt.registerTask('doc', ['jsdoc']); |
139 | }; | 129 | }; | ... | ... |
... | @@ -247,6 +247,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -247,6 +247,7 @@ ARCS.Context = function( ctx ) { |
247 | if (ctx !== undefined) { | 247 | if (ctx !== undefined) { |
248 | libraries = ctx.libraries; | 248 | libraries = ctx.libraries; |
249 | 249 | ||
250 | + var p; | ||
250 | for (p in ctx.components) { | 251 | for (p in ctx.components) { |
251 | if (ctx.components.hasOwnProperty(p)) { | 252 | if (ctx.components.hasOwnProperty(p)) { |
252 | components[p] = ctx.components[p]; | 253 | components[p] = ctx.components[p]; |
... | @@ -263,8 +264,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -263,8 +264,7 @@ ARCS.Context = function( ctx ) { |
263 | 264 | ||
264 | } | 265 | } |
265 | 266 | ||
266 | - //! TODO use fetch API? | 267 | + var loadDataFile =async function(fileName) { |
267 | - loadDataFile =async function(fileName) { | ||
268 | var dataPromise ; | 268 | var dataPromise ; |
269 | 269 | ||
270 | if (ARCS.isInNode()) { | 270 | if (ARCS.isInNode()) { |
... | @@ -281,19 +281,8 @@ ARCS.Context = function( ctx ) { | ... | @@ -281,19 +281,8 @@ ARCS.Context = function( ctx ) { |
281 | return client.json(); | 281 | return client.json(); |
282 | } | 282 | } |
283 | }; | 283 | }; |
284 | - | 284 | + |
285 | - //! TODO not needed anymore? | 285 | + var loadLibraries = function () { |
286 | - /*this.addLibraryPromise = function(p) { | ||
287 | - depLibPromises.push(p); | ||
288 | - };*/ | ||
289 | - | ||
290 | - /*promiseLibrary = function(libName) { | ||
291 | - return import(libName); | ||
292 | - };*/ | ||
293 | - | ||
294 | - //! TODO modify loadLibraries and loadLibrary to directly register | ||
295 | - // factories so that arcs_module is not needed anymore ? | ||
296 | - loadLibraries = function () { | ||
297 | var i; | 286 | var i; |
298 | // we will use different instances of require either the one of node | 287 | // we will use different instances of require either the one of node |
299 | // or the one from require.js | 288 | // or the one from require.js |
... | @@ -301,16 +290,13 @@ ARCS.Context = function( ctx ) { | ... | @@ -301,16 +290,13 @@ ARCS.Context = function( ctx ) { |
301 | 290 | ||
302 | var res=[]; | 291 | var res=[]; |
303 | for(i=0; i < libraries.length; i++) { | 292 | for(i=0; i < libraries.length; i++) { |
304 | - //! TODO | 293 | + res.push(self.loadLibrary(libraries[i])); |
305 | - res.push(loadLibrary(libraries[i])); | ||
306 | - //import(libraries[i])); | ||
307 | } | 294 | } |
308 | return Promise.all(res); | 295 | return Promise.all(res); |
309 | }; | 296 | }; |
310 | 297 | ||
311 | - instanciateComponents = function() { | 298 | + var instanciateComponents = function() { |
312 | var p, promises=[]; | 299 | var p, promises=[]; |
313 | - console.log(components); | ||
314 | 300 | ||
315 | for (p in components) { | 301 | for (p in components) { |
316 | if (components.hasOwnProperty(p)) { | 302 | if (components.hasOwnProperty(p)) { |
... | @@ -319,7 +305,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -319,7 +305,7 @@ ARCS.Context = function( ctx ) { |
319 | console.error("[ARCS] Context dump follows: ", libraries, components, constants); | 305 | console.error("[ARCS] Context dump follows: ", libraries, components, constants); |
320 | return ; | 306 | return ; |
321 | } | 307 | } |
322 | - factory = factories[components[p].type]; | 308 | + var factory = factories[components[p].type]; |
323 | //console.log("instanciating ", p); | 309 | //console.log("instanciating ", p); |
324 | try { | 310 | try { |
325 | if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) { | 311 | if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) { |
... | @@ -368,21 +354,23 @@ ARCS.Context = function( ctx ) { | ... | @@ -368,21 +354,23 @@ ARCS.Context = function( ctx ) { |
368 | libActualName = libName.name; | 354 | libActualName = libName.name; |
369 | libUrl = libName.url; | 355 | libUrl = libName.url; |
370 | } | 356 | } |
371 | - | 357 | + |
372 | - libraries.push(libActualName); | 358 | + if (libraries.indexOf(libActualName) < 0) { |
359 | + libraries.push(libActualName); | ||
360 | + } | ||
373 | // TODO promisify call to cbFunction | 361 | // TODO promisify call to cbFunction |
374 | return import(libUrl).then( function(module) { | 362 | return import(libUrl).then( function(module) { |
375 | // TODO insert here component factories | 363 | // TODO insert here component factories |
376 | - for (p in module) { | 364 | + for (p in module.default) { |
377 | - if (module.hasOwnProperty(p)) { | 365 | + if (module.default.hasOwnProperty(p)) { |
378 | - ARCS.Context.currentContext.setFactory(p,module[p]); | 366 | + ARCS.Context.currentContext.setFactory(p,module.default[p]); |
379 | } | 367 | } |
380 | } | 368 | } |
381 | 369 | ||
382 | if (cbFunction !== undefined) { | 370 | if (cbFunction !== undefined) { |
383 | cbFunction(); | 371 | cbFunction(); |
384 | } | 372 | } |
385 | - }); | 373 | + }).catch( function(msg) { console.error("[ARCS] Trouble loading '",libUrl,"' with reason -", msg) }); |
386 | }; | 374 | }; |
387 | 375 | ||
388 | /** | 376 | /** |
... | @@ -501,7 +489,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -501,7 +489,7 @@ ARCS.Context = function( ctx ) { |
501 | this.instanciate = function () { | 489 | this.instanciate = function () { |
502 | //! TODO | 490 | //! TODO |
503 | return loadLibraries().then(instanciateComponents) | 491 | return loadLibraries().then(instanciateComponents) |
504 | - .catch(function(msg) { console.log("[ARCS] Trouble instanciating context", msg); }); | 492 | + .catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); }); |
505 | 493 | ||
506 | }; | 494 | }; |
507 | 495 | ||
... | @@ -2049,7 +2037,7 @@ ARCS.Application = function () { | ... | @@ -2049,7 +2037,7 @@ ARCS.Application = function () { |
2049 | * Starts the application | 2037 | * Starts the application |
2050 | */ | 2038 | */ |
2051 | this.start = function () { | 2039 | this.start = function () { |
2052 | - console.log("[ARCS] Starting application"); | 2040 | + console.log("[ARCS] Starting application..."); |
2053 | context.instanciate().then(preProcess); | 2041 | context.instanciate().then(preProcess); |
2054 | }; | 2042 | }; |
2055 | }; | 2043 | }; |
... | @@ -2065,103 +2053,6 @@ ARCS.Application.slot("setSheet"); | ... | @@ -2065,103 +2053,6 @@ ARCS.Application.slot("setSheet"); |
2065 | ARCS.Application.slot("finish"); | 2053 | ARCS.Application.slot("finish"); |
2066 | 2054 | ||
2067 | 2055 | ||
2068 | -/** | ||
2069 | - * definition of the main module function: | ||
2070 | - * it takes an anonymous function as a parameter | ||
2071 | - * the anonymous function has one parameter: the object encompassing | ||
2072 | - * ARCS definitions (in order to able to use ARCS.Component.create, ...) | ||
2073 | - * @param moduleDefinition {function} main function of the module. | ||
2074 | - * It should return a list of components | ||
2075 | - * @param deps {mixed[]} dependencies | ||
2076 | - */ | ||
2077 | - | ||
2078 | -// TODO arcs_module seems to be not needed anymore!!!! | ||
2079 | -// more cunning, this time, we export an arcs_module function | ||
2080 | -// that we call later! | ||
2081 | -// still we need to do something about it in order to register | ||
2082 | -// components. | ||
2083 | -// in fact factories should be registered in load library. | ||
2084 | - | ||
2085 | -// reimplementation using native promises | ||
2086 | -arcs_module = function(moduleDefinition, deps) { | ||
2087 | - var storeComponents, i; | ||
2088 | - | ||
2089 | - if (typeof module !== 'undefined') { | ||
2090 | - if (module.parent.exports) { | ||
2091 | - ARCS = module.exports; | ||
2092 | - } | ||
2093 | - } | ||
2094 | - | ||
2095 | - if (deps === undefined) { deps = []; } | ||
2096 | - | ||
2097 | - storeComponents = function (deps) { | ||
2098 | - var mdef, p; | ||
2099 | - // we should insert ARCS at the beginning of deps ! | ||
2100 | - deps.unshift(ARCS); | ||
2101 | - | ||
2102 | - mdef = (typeof moduleDefinition === 'function') ? | ||
2103 | - moduleDefinition.apply(this, deps) : moduleDefinition; | ||
2104 | - | ||
2105 | - if (mdef === undefined) { | ||
2106 | - throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n" +moduleDefinition); | ||
2107 | - } | ||
2108 | - | ||
2109 | - for (p in mdef) { | ||
2110 | - if (mdef.hasOwnProperty(p) && ARCS.Context.currentContext != null) { | ||
2111 | - ARCS.Context.currentContext.setFactory(p,mdef[p]); //.setFactory(ARCS.Application.currentApplication, p, mdef[p]); | ||
2112 | - } | ||
2113 | - } | ||
2114 | - | ||
2115 | - return Promise.resolve(); | ||
2116 | - }; | ||
2117 | - // until now, it is the very same code. | ||
2118 | - | ||
2119 | - // here we create a promise to solve dependency | ||
2120 | - // reject has the dependency name, while resolve has the object | ||
2121 | - var depResolve = function(dep) { | ||
2122 | - return new Promise(function(resolve, reject) { | ||
2123 | - var d,shimConfig; | ||
2124 | - if (ARCS.isInNode()) { | ||
2125 | - d = require(dep); | ||
2126 | - if (d === undefined) { | ||
2127 | - reject(dep); | ||
2128 | - } else { | ||
2129 | - resolve(d); | ||
2130 | - } | ||
2131 | - } else { | ||
2132 | - // this one a little bit trickier since we have to shim. | ||
2133 | - if (dep.name !== undefined) { | ||
2134 | - shimConfig = { shim: {} }; | ||
2135 | - shimConfig.shim[dep.name] = { exports: dep.exports }; | ||
2136 | - if (dep.deps !== undefined) { | ||
2137 | - shimConfig.shim[dep.name].deps = dep.deps; | ||
2138 | - } | ||
2139 | - require.config(shimConfig); | ||
2140 | - dep = dep.name; | ||
2141 | - } | ||
2142 | - // shim performed | ||
2143 | - require([dep], | ||
2144 | - function(d) { resolve(d); }, | ||
2145 | - function(err) { console.log("[ARCS] Trouble with module ", dep); reject(dep, err); } | ||
2146 | - ); | ||
2147 | - } | ||
2148 | - }); | ||
2149 | - }; | ||
2150 | - | ||
2151 | - var depResolves = []; | ||
2152 | - for (i=0; i<deps.length; i++) { | ||
2153 | - depResolves[i] = depResolve(deps[i]); | ||
2154 | - } | ||
2155 | - | ||
2156 | - | ||
2157 | - | ||
2158 | - ARCS.Context.currentContext.addLibraryPromise( | ||
2159 | - Promise.all(depResolves).then(storeComponents, | ||
2160 | - function(reason) { console.error("[ARCS] Failed to load dependency ", reason ); }) | ||
2161 | - | ||
2162 | - ); | ||
2163 | - | ||
2164 | -} | ||
2165 | // no longer needed with the use of imports | 2056 | // no longer needed with the use of imports |
2166 | 2057 | ||
2167 | -export default ARCS; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
2058 | +export { ARCS as default}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -var ARCS=ARCS||{};ARCS.isInNode=function(){return"function"==typeof require&&require.resolve},ARCS.Component={SourceIsNotComponent:{message:"Source is not a component"},UndefinedSignal:{message:"Signal is not defined"},UndefinedSlot:{message:"Slot is not defined"},create:function(n,t,e){return void 0===n.prototype?(console.error("Cannot create such a component"),0):(n.prototype.slots=[],n.prototype.signals={},n.slotList=function(){return n.prototype.slots},n.prototype.slotList=function(){return n.prototype.slots},n.prototype.signalList=function(){var t,e=[];for(t in n.prototype.signals)e.push(t);return e},n.signalList=function(){return n.prototype.signalList()},n.prototype.emit=function(n){var t,e,o,i=Array.prototype.slice.call(arguments,1);for(t in this.signals[n])e=this.signals[n][t].func,o=this.signals[n][t].obj,e.apply(o,i)},n.slot=function(t,e){var o;if(t instanceof Array)for(o=0;o<t.length;o++)n.prototype.slots.push(t[o]);else n.prototype.slots.push(t),void 0!==e&&(n.prototype[t]=e)},n.signal=function(t){var e;if(t instanceof Array)for(e=0;e<t.length;e++)n.prototype.signals[t[e]]=1;else n.prototype.signals[t]=1},void 0!==t&&n.slot(t),void 0!==e&&n.signal(e),n)},check:function(n){return void 0!==n.prototype&&(void 0!==n.prototype.signals&&void 0!==n.prototype.slots)},connect:function(n,t,e,o){var i,r;if(void 0===n.signals)throw ARCS.Component.SourceIsNotComponent;if(void 0===n.signals[t])throw ARCS.Component.UndefinedSignal;if(void 0===e[o])throw ARCS.Component.UndefinedSlot;if(!n.hasOwnProperty("signals"))for(r in i=n.signals,n.signals={},i)n.signals[r]=[];n.signals[t].push({obj:e,func:e[o]})},disconnect:function(n,t,e,o){var i;for(i=0;i<n.signals[t].length;i++)n.signals[t][i].obj===e&&n.signals[t][i].func===e[o]&&(n.signals[t].splice(i,1),i--)},invoke:function(n,t,e){if(void 0===n[t])throw ARCS.Component.UndefinedSlot;n[t].apply(n,e)},config:function(n,t){"function"==typeof n.config&&n.config(t)}},ARCS.Context=function(n){var t,e,o,i={},r={},s={},c=[],a=this;if(s.StateMachine=ARCS.Statemachine,void 0!==n){for(p in c=n.libraries,n.components)n.components.hasOwnProperty(p)&&(i[p]=n.components[p]);if(void 0!==n.constants)for(p in n.constants)n.constants.hasOwnProperty(p)&&(r[p]=n.constants[p])}e=async function(n){return ARCS.isInNode()?new Promise((function(t,e){var o=require(n);void 0!==o?t(o):e("[ARCS] File not found")})):(await fetch(n)).json()},t=function(){var n;ARCS.Context.currentContext=a;var t=[];for(n=0;n<c.length;n++)t.push(loadLibrary(c[n]));return Promise.all(t)},o=function(){var n,t=[];for(n in console.log(i),i)if(i.hasOwnProperty(n)){if(void 0===s[i[n].type])return console.error("[ARCS] Factory "+i[n].type+" not found."),void console.error("[ARCS] Context dump follows: ",c,i,r);factory=s[i[n].type];try{if(void 0!==i[n].value||void 0!==i[n].url||void 0!==i[n].ref){if(void 0!==i[n].value&&(i[n].instance=new factory(i[n].value)),void 0!==i[n].url){console.log("loading data file",i[n].url),t.push(e(i[n].url).then(function(n,t){return function(e){return console.log("instanciating from data file"),i[n].instance=new t(e),Promise.resolve()}}(n,factory)))}void 0!==i[n].ref&&void 0!==r[i[n].ref]&&(i[n].instance=new factory(r[i[n].ref]))}else i[n].instance=new factory}catch(t){console.error("[ARCS] Component of type ",n," not instanciated.",t)}}return Promise.all(t)},this.loadLibrary=function(n,t){var e=n,o=n;return ARCS.Context.currentContext=a,"string"!=typeof n&&(o=n.name,e=n.url),c.push(o),import(e).then((function(n){for(p in n)n.hasOwnProperty(p)&&ARCS.Context.currentContext.setFactory(p,n[p]);void 0!==t&&t()}))},this.getComponentList=function(){var n,t=Object.keys(i);for(n=0;n<t.length;n++)i.hasOwnProperty(t[n])||t.splice(n--,1);return t},this.getConstant=function(n){return r[n]},this.getComponentType=function(n){if(void 0!==i[n])return i[n].type},this.getComponentValue=function(n){if(void 0!==i[n])return i[n].value},this.getComponent=function(n){if(void 0!==i[n])return i[n].instance},this.getComponentName=function(n){var t,e;for(e=i.getComponentList(),t=0;t<e.length;t++)if(i[e[t]].instance===n)return e[t]},this.setFactory=function(n,t){s[n]=t},this.toJSON=function(){var n,t={};for(n in i)i.hasOwnProperty(n)&&(t[n]={type:i[n].type,value:i[n].value});return t},this.setComponentValue=function(n,t){i[n].value=t},this.addComponent=function(n,t,e){var o;i[n]={},i[n].type=t,i[n].value=e;var r=s[t];void 0!==r&&(o=new r(e)),i[n].instance=o},this.removeComponent=function(n){delete i[n]},this.getFactory=function(n){return s[n]},this.getFactoryList=function(){return Object.keys(s)},this.instanciate=function(){return t().then(o).catch((function(n){console.log("[ARCS] Trouble instanciating context",n)}))};var u=function(n,t){var e,o=Object.create(t);for(e in n)n.hasOwnProperty(e)&&(o[e]=n[e]);return o};this.chain=function(n,t,e){return[u(n,i),u(t,r),u(e,s)]},this.setParent=function(n){if(void 0!==n){var t=n.chain(i,r,s);i=t[0],r=t[1],s=t[2]}}},ARCS.Context.currentContext=null,ARCS.Invocation=function(n,t,e){this.getDestination=function(){return n},this.getSlot=function(){return t},this.getValue=function(){return e},this.invoke=function(){var o=n[t];void 0!==o?o.apply(n,e):console.error("Undefined slot %s of component %s",t,n)}},ARCS.Invocation.cast=function(n,t){if(void 0!==n.value){var e=t.getComponent(n.destination);return void 0===e&&console.error("[ARCS] Destination ",n.destination," is undefined"),new ARCS.Invocation(e,n.slot,n.value)}if(void 0!==n.ref)return new ARCS.Invocation(t.getComponent(n.destination),n.slot,t.getConstant(n.ref))},ARCS.Invocation.PRE_CONNECTION=0,ARCS.Invocation.POST_CONNECTION=1,ARCS.Invocation.CLEAN_UP=2,ARCS.Connection=function(n,t,e,o){this.connect=function(){try{ARCS.Component.connect(n,t,e,o)}catch(i){console.log(i,n,t,e,o)}},this.disconnect=function(){ARCS.Component.disconnect(n,t,e,o)},this.getSource=function(){return n},this.getDestination=function(){return e},this.getSlot=function(){return o},this.getSignal=function(){return t}},ARCS.Connection.cast=function(n,t){return new ARCS.Connection(t.getComponent(n.source),n.signal,t.getComponent(n.destination),n.slot)},ARCS.Sheet=function(n){var t,e,o,i,r,s=new ARCS.Context,c=[],a=[],u=[],f=[],l=0,p=0,h=0,d=0;t=function(){var n;for(n=0;n<c.length;n++)c[n].invoke()},e=function(){var n;for(n=0;n<a.length;n++)a[n].invoke()},o=function(){var n;for(n=0;n<u.length;n++)u[n].invoke()},i=function(){var n;for(n=0;n<f.length;n++)f[n].connect()},r=function(){var n;for(n=0;n<f.length;n++)f[n].disconnect()},this.setContext=function(n){s=n},this.activate=function(){s.instanciate().then((function(){t(),i(),e()}))},this.deactivate=function(){r(),o()},this.addPreConnection=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=l++,c.push(t),t.id},this.addPostConnection=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=p++,a.push(t),t.id},this.addCleanup=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=h++,u.push(t),t.id},this.addConnection=function(n){var t=ARCS.Connection.cast(n,s);return t.id=d++,f.push(t),t.id};var C=function(n,t){for(var e=t.length;e--&&t[e].id!==n;);e>=0?t.splice(e,1):console.warn("Could not remove data with id",n)};this.removePreConnection=function(n){C(n,c)},this.removePostConnection=function(n){C(n,a)},this.removeCleanup=function(n){C(n,u)};var v=function(n,t,e){for(var o=e.length;o--&&e[o].id!==n;);o>=0&&(e[o].value=t)};this.changePreConnection=function(n,t){v(n,t,c)},this.changePostConnection=function(n,t){v(n,t,a)},this.changeCleanup=function(n,t){v(n,t,u)},this.removeConnection=function(n){C(n,f)};var g=function(n,t,e){for(var o,i=e.length,r=e.length;i--&&e[i].id!==n;);for(;r--&&e[r].id!==t;);i>=0&&r>=0&&(o=e[i],e[i]=e[r],e[r]=o,e[i].id=n,e[r].id=t)};this.swapConnections=function(n,t){g(n,t,f)},this.swapCleanups=function(n,t){g(n,t,u)},this.swapPreConnections=function(n,t){g(n,t,c)},this.swapPostConnections=function(n,t){g(n,t,a)};this.import=function(t){t.hasOwnProperty("context")&&(s=new ARCS.Context(t.context)).setParent(n),s.instanciate().then((function(){!function(n){var t=0,e=ARCS.Invocation.cast,o=ARCS.Connection.cast;for(t=0;t<n.preconnections.length;t++)c.push(e(n.preconnections[t],s));for(t=0;t<n.postconnections.length;t++)a.push(e(n.postconnections[t],s));for(t=0;t<n.cleanups.length;t++)u.push(e(n.cleanups[t],s));for(t=0;t<n.connections.length;t++)f.push(o(n.connections[t],s))}(t)}))};var S=function(n){return{destination:s.getComponentName(n.getDestination()),slot:n.getSlot(),value:n.getValue()}};this.toJSON=function(){var n,t,e=[],o=[],i=[],r=[];for(n=0;n<f.length;n++)i.push((t=f[n],{source:s.getComponentName(t.getSource()),signal:t.getSignal(),destination:s.getComponentName(t.getDestination()),slot:t.getSlot()}));for(n=0;n<c.length;n++)e.push(S(c[n]));for(n=0;n<a.length;n++)o.push(S(a[n]));for(n=0;n<u.length;n++)r.push(S(u[n]));return{preconnections:e,postconnections:o,connections:i,cleanups:r}},s.setParent(n)},ARCS.EventLogicParser=function(){function n(n,t,e,o,i,r){this.message=n,this.expected=t,this.found=e,this.offset=o,this.line=i,this.column=r,this.name="SyntaxError"}return function(n,t){function e(){this.constructor=n}e.prototype=t.prototype,n.prototype=new e}(n,Error),{SyntaxError:n,parse:function(t){var e,o=arguments.length>1?arguments[1]:{},i={},r={start:D},s=D,c=i,a=function(n,t){return[n].concat(t)},u=function(n){return{and:n}},f=function(n){return{or:n}},l=function(n){return n},p="(",h={type:"literal",value:"(",description:'"("'},d=")",C={type:"literal",value:")",description:'")"'},v=function(n){return[n]},g={type:"other",description:"id"},S=function(n){return n.trim()},m=/^[_a-zA-Z]/,A={type:"class",value:"[_a-zA-Z]",description:"[_a-zA-Z]"},y=/^[_a-zA-Z0-9]/,R={type:"class",value:"[_a-zA-Z0-9]",description:"[_a-zA-Z0-9]"},w="&",x={type:"literal",value:"&",description:'"&"'},P="|",O={type:"literal",value:"|",description:'"|"'},N=/^[ \r\n\t]/,T={type:"class",value:"[ \\r\\n\\t]",description:"[ \\r\\n\\t]"},b=0,k=0,F={line:1,column:1,seenCR:!1},I=0,E=[],L=0;if("startRule"in o){if(!(o.startRule in r))throw new Error("Can't start parsing from rule \""+o.startRule+'".');s=r[o.startRule]}function q(n){return k!==n&&(k>n&&(k=0,F={line:1,column:1,seenCR:!1}),function(n,e,o){var i,r;for(i=e;i<o;i++)"\n"===(r=t.charAt(i))?(n.seenCR||n.line++,n.column=1,n.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(n.line++,n.column=1,n.seenCR=!0):(n.column++,n.seenCR=!1)}(F,k,n),k=n),F}function _(n){b<I||(b>I&&(I=b,E=[]),E.push(n))}function j(e,o,i){var r=q(i),s=i<t.length?t.charAt(i):null;return null!==o&&function(n){var t=1;for(n.sort((function(n,t){return n.description<t.description?-1:n.description>t.description?1:0}));t<n.length;)n[t-1]===n[t]?n.splice(t,1):t++}(o),new n(null!==e?e:function(n,t){var e,o=new Array(n.length);for(e=0;e<n.length;e++)o[e]=n[e].description;return"Expected "+(n.length>1?o.slice(0,-1).join(", ")+" or "+o[n.length-1]:o[0])+" but "+(t?'"'+function(n){function t(n){return n.charCodeAt(0).toString(16).toUpperCase()}return n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,(function(n){return"\\x0"+t(n)})).replace(/[\x10-\x1F\x80-\xFF]/g,(function(n){return"\\x"+t(n)})).replace(/[\u0180-\u0FFF]/g,(function(n){return"\\u0"+t(n)})).replace(/[\u1080-\uFFFF]/g,(function(n){return"\\u"+t(n)}))}(t)+'"':"end of input")+" found."}(o,s),o,s,i,r.line,r.column)}function D(){return U()}function U(){var n,t,e,o;if(n=b,(t=Z())!==i){if(e=[],(o=z())!==i)for(;o!==i;)e.push(o),o=z();else e=c;e!==i?(n,n=t=a(t,e)):(b=n,n=c)}else b=n,n=c;return n===i&&(n=Z()),n}function z(){var n,e;return n=b,function(){var n,e,o,r;n=b,(e=V())!==i?(38===t.charCodeAt(b)?(o=w,b++):(o=i,0===L&&_(x)),o!==i&&(r=V())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c);return n}()!==i&&(e=Z())!==i?(n,n=u(e)):(b=n,n=c),n===i&&(n=b,function(){var n,e,o,r;n=b,(e=V())!==i?(124===t.charCodeAt(b)?(o=P,b++):(o=i,0===L&&_(O)),o!==i&&(r=V())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c);return n}()!==i&&(e=Z())!==i?(n,n=f(e)):(b=n,n=c)),n}function Z(){var n,e,o,r;return n=b,(e=function(){var n,e,o;L++,n=b,e=b,(o=function(){var n,e,o,r,s;if(n=b,(e=V())!==i)if(m.test(t.charAt(b))?(o=t.charAt(b),b++):(o=i,0===L&&_(A)),o!==i){for(r=[],y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));s!==i;)r.push(s),y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));r!==i&&(s=V())!==i?n=e=[e,o,r,s]:(b=n,n=c)}else b=n,n=c;else b=n,n=c;return n}())!==i&&(o=t.substring(e,b));(e=o)!==i&&(n,e=S(e));L--,(n=e)===i&&(e=i,0===L&&_(g));return n}())!==i&&(n,e=l(e)),(n=e)===i&&(n=b,40===t.charCodeAt(b)?(e=p,b++):(e=i,0===L&&_(h)),e!==i&&(o=U())!==i?(41===t.charCodeAt(b)?(r=d,b++):(r=i,0===L&&_(C)),r!==i?(n,n=e=v(o)):(b=n,n=c)):(b=n,n=c)),n}function V(){var n,e;for(n=[],N.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(T));e!==i;)n.push(e),N.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(T));return n}if((e=s())!==i&&b===t.length)return e;throw e!==i&&b<t.length&&_({type:"end",description:"end of input"}),j(null,E,I)}}}(),ARCS.TokenEvent=function(){var n,t;this.promise=new Promise((function(e,o){n=e,t=o})),this.accept=function(){n()},this.abort=function(){t()}},ARCS.TransitionNetwork=function(){this.promise={},this.and=function(n){return this.promise=Promise.all([this.promise,n.promise]),this},this.or=function(n){return this.promise=Promise.race([this.promise,n.promise]),this}},ARCS.TransitionNetwork.build=function(n,t){var e,o,r;if("string"==typeof n){var s;t.hasOwnProperty(n)?s=t[n]:t[n]=s=new ARCS.TokenEvent;var c=new ARCS.TransitionNetwork;return c.promise=s.promise,c}for(e=ARCS.TransitionNetwork.build(n[0],t),i=1;i<n.length;i++)n[i].hasOwnProperty("and")?(r=ARCS.TransitionNetwork.build(n[i].and,t),o=e.and(r)):n[i].hasOwnProperty("or")?(r=ARCS.TransitionNetwork.build(n[i].or,t),o=e.or(r)):console.warn("[ARCS] Illegal tree"),e=o;return e},ARCS.Statemachine=new ARCS.Component.create((function(n){var t="",e="",o={},i="",r=this,s={},c={},a=function(n){var t;r.slots.indexOf(n)<0&&(r.slots.push(n),r[n]=(t=n,function(){r.setToken(t)}))},u=function(n){var t;if(o.hasOwnProperty(n))for(t in c={},o[n])o[n].hasOwnProperty(t)&&ARCS.TransitionNetwork.build(s[t],c).promise.then((function(){var e;for(e in c)c.hasOwnProperty(e)&&c[e].abort();u(o[n][t])}));i=n,r.emit("requestSheet",i),i===e&&r.emit("requestTermination")};this.setInitialState=function(n){i=t=n},this.setFinalState=function(n){e=n},this.addTransition=function(n,t,e){var i,r=/([A-Za-z_]\w*)/g;try{var c;if("string"==typeof(c=ARCS.EventLogicParser.parse(t)))a(c);else for(;null!==(i=r.exec(t));)a(i[0]);s[t]=c,void 0===o[n]&&(o[n]={}),o[n][t]=e}catch(n){}},this.setToken=function(n){c.hasOwnProperty(n)&&c[n].accept()},this.setTransitions=function(n){var t,e;for(t in n)if(n.hasOwnProperty(t))for(e in n[t])n[t].hasOwnProperty(e)&&this.addTransition(t,e,n[t][e])},this.start=function(){console.log("statemachine",this,t,n),u(t)},void 0!==n&&(t=n.initial,e=n.final,this.setTransitions(n.transitions),i="")}),["setToken"],["requestSheet","requestTermination"]),ARCS.Application=function(){var n,t=new ARCS.Context,e={},o={},i=[],r=this,s="";this.export=function(){return{context:t,controller:t.getComponentName(o),sheets:e}},this.getContext=function(){return t},this.getSheetList=function(){return Object.keys(e)},this.getSheet=function(n){return e[n]},this.addSheet=function(n,o){e[n]=o,o.setContext(t)},this.removeSheet=function(n){delete e[n]},n=function(){var n,i,s;for(i=t.getComponent(o),o=i,s=Object.keys(e),n=0;n<s.length;n++)(i=new ARCS.Sheet(t)).import(e[s[n]],t),e[s[n]]=i;ARCS.Component.connect(o,"requestSheet",r,"setSheet"),ARCS.Component.connect(o,"requestTermination",r,"finish"),o.start()},this.setController=function(n){o=t.getComponent(n)},this.setSheet=function(n){e.hasOwnProperty(n)?(s&&e[s].deactivate(),e[s=n].activate()):console.warn("[ARCS] Tried to activate hollow sheet named: "+n)},this.finish=function(){s&&e[s].deactivate()},this.import=function(n){t=new ARCS.Context(n.context),e=n.sheets,void 0===(o=n.controller)&&console.error("[ARCS] Undefined controller. Cannot start application.")},this.setFactory=function(n,t){factories[n]=t},this.setDependency=function(n){i[n]={}},this.start=function(){console.log("[ARCS] Starting application"),t.instanciate().then(n)}},ARCS.Application.setDependency=function(n,t){n.setDependency(t)},ARCS.Component.create(ARCS.Application),ARCS.Application.slot("setSheet"),ARCS.Application.slot("finish"),arcs_module=function(n,t){var e,o;"undefined"!=typeof module&&module.parent.exports&&(ARCS=module.exports),void 0===t&&(t=[]),e=function(t){var e,o;if(t.unshift(ARCS),void 0===(e="function"==typeof n?n.apply(this,t):n))throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n"+n);for(o in e)e.hasOwnProperty(o)&&null!=ARCS.Context.currentContext&&ARCS.Context.currentContext.setFactory(o,e[o]);return Promise.resolve()};var i=function(n){return new Promise((function(t,e){var o,i;ARCS.isInNode()?void 0===(o=require(n))?e(n):t(o):(void 0!==n.name&&((i={shim:{}}).shim[n.name]={exports:n.exports},void 0!==n.deps&&(i.shim[n.name].deps=n.deps),require.config(i),n=n.name),require([n],(function(n){t(n)}),(function(t){console.log("[ARCS] Trouble with module ",n),e(n,t)})))}))},r=[];for(o=0;o<t.length;o++)r[o]=i(t[o]);ARCS.Context.currentContext.addLibraryPromise(Promise.all(r).then(e,(function(n){console.error("[ARCS] Failed to load dependency ",n)})))};export default ARCS; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +var ARCS=ARCS||{};ARCS.isInNode=function(){return"function"==typeof require&&require.resolve},ARCS.Component={SourceIsNotComponent:{message:"Source is not a component"},UndefinedSignal:{message:"Signal is not defined"},UndefinedSlot:{message:"Slot is not defined"},create:function(n,t,e){return void 0===n.prototype?(console.error("Cannot create such a component"),0):(n.prototype.slots=[],n.prototype.signals={},n.slotList=function(){return n.prototype.slots},n.prototype.slotList=function(){return n.prototype.slots},n.prototype.signalList=function(){var t,e=[];for(t in n.prototype.signals)e.push(t);return e},n.signalList=function(){return n.prototype.signalList()},n.prototype.emit=function(n){var t,e,o,i=Array.prototype.slice.call(arguments,1);for(t in this.signals[n])e=this.signals[n][t].func,o=this.signals[n][t].obj,e.apply(o,i)},n.slot=function(t,e){var o;if(t instanceof Array)for(o=0;o<t.length;o++)n.prototype.slots.push(t[o]);else n.prototype.slots.push(t),void 0!==e&&(n.prototype[t]=e)},n.signal=function(t){var e;if(t instanceof Array)for(e=0;e<t.length;e++)n.prototype.signals[t[e]]=1;else n.prototype.signals[t]=1},void 0!==t&&n.slot(t),void 0!==e&&n.signal(e),n)},check:function(n){return void 0!==n.prototype&&(void 0!==n.prototype.signals&&void 0!==n.prototype.slots)},connect:function(n,t,e,o){var i,r;if(void 0===n.signals)throw ARCS.Component.SourceIsNotComponent;if(void 0===n.signals[t])throw ARCS.Component.UndefinedSignal;if(void 0===e[o])throw ARCS.Component.UndefinedSlot;if(!n.hasOwnProperty("signals"))for(r in i=n.signals,n.signals={},i)n.signals[r]=[];n.signals[t].push({obj:e,func:e[o]})},disconnect:function(n,t,e,o){var i;for(i=0;i<n.signals[t].length;i++)n.signals[t][i].obj===e&&n.signals[t][i].func===e[o]&&(n.signals[t].splice(i,1),i--)},invoke:function(n,t,e){if(void 0===n[t])throw ARCS.Component.UndefinedSlot;n[t].apply(n,e)},config:function(n,t){"function"==typeof n.config&&n.config(t)}},ARCS.Context=function(n){var t={},e={},o={},i=[],r=this;if(o.StateMachine=ARCS.Statemachine,void 0!==n){var s;for(s in i=n.libraries,n.components)n.components.hasOwnProperty(s)&&(t[s]=n.components[s]);if(void 0!==n.constants)for(s in n.constants)n.constants.hasOwnProperty(s)&&(e[s]=n.constants[s])}var c=async function(n){return ARCS.isInNode()?new Promise((function(t,e){var o=require(n);void 0!==o?t(o):e("[ARCS] File not found")})):(await fetch(n)).json()},a=function(){var n,r=[];for(n in t)if(t.hasOwnProperty(n)){if(void 0===o[t[n].type])return console.error("[ARCS] Factory "+t[n].type+" not found."),void console.error("[ARCS] Context dump follows: ",i,t,e);var s=o[t[n].type];try{if(void 0!==t[n].value||void 0!==t[n].url||void 0!==t[n].ref){if(void 0!==t[n].value&&(t[n].instance=new s(t[n].value)),void 0!==t[n].url){console.log("loading data file",t[n].url),r.push(c(t[n].url).then(function(n,e){return function(o){return console.log("instanciating from data file"),t[n].instance=new e(o),Promise.resolve()}}(n,s)))}void 0!==t[n].ref&&void 0!==e[t[n].ref]&&(t[n].instance=new s(e[t[n].ref]))}else t[n].instance=new s}catch(t){console.error("[ARCS] Component of type ",n," not instanciated.",t)}}return Promise.all(r)};this.loadLibrary=function(n,t){var e=n,o=n;return ARCS.Context.currentContext=r,"string"!=typeof n&&(o=n.name,e=n.url),i.indexOf(o)<0&&i.push(o),import(e).then((function(n){for(s in n.default)n.default.hasOwnProperty(s)&&ARCS.Context.currentContext.setFactory(s,n.default[s]);void 0!==t&&t()})).catch((function(n){console.error("[ARCS] Trouble loading '",e,"' with reason -",n)}))},this.getComponentList=function(){var n,e=Object.keys(t);for(n=0;n<e.length;n++)t.hasOwnProperty(e[n])||e.splice(n--,1);return e},this.getConstant=function(n){return e[n]},this.getComponentType=function(n){if(void 0!==t[n])return t[n].type},this.getComponentValue=function(n){if(void 0!==t[n])return t[n].value},this.getComponent=function(n){if(void 0!==t[n])return t[n].instance},this.getComponentName=function(n){var e,o;for(o=t.getComponentList(),e=0;e<o.length;e++)if(t[o[e]].instance===n)return o[e]},this.setFactory=function(n,t){o[n]=t},this.toJSON=function(){var n,e={};for(n in t)t.hasOwnProperty(n)&&(e[n]={type:t[n].type,value:t[n].value});return e},this.setComponentValue=function(n,e){t[n].value=e},this.addComponent=function(n,e,i){var r;t[n]={},t[n].type=e,t[n].value=i;var s=o[e];void 0!==s&&(r=new s(i)),t[n].instance=r},this.removeComponent=function(n){delete t[n]},this.getFactory=function(n){return o[n]},this.getFactoryList=function(){return Object.keys(o)},this.instanciate=function(){return function(){var n;ARCS.Context.currentContext=r;var t=[];for(n=0;n<i.length;n++)t.push(r.loadLibrary(i[n]));return Promise.all(t)}().then(a).catch((function(n){console.error("[ARCS] Trouble instanciating context",n)}))};var u=function(n,t){var e,o=Object.create(t);for(e in n)n.hasOwnProperty(e)&&(o[e]=n[e]);return o};this.chain=function(n,i,r){return[u(n,t),u(i,e),u(r,o)]},this.setParent=function(n){if(void 0!==n){var i=n.chain(t,e,o);t=i[0],e=i[1],o=i[2]}}},ARCS.Context.currentContext=null,ARCS.Invocation=function(n,t,e){this.getDestination=function(){return n},this.getSlot=function(){return t},this.getValue=function(){return e},this.invoke=function(){var o=n[t];void 0!==o?o.apply(n,e):console.error("Undefined slot %s of component %s",t,n)}},ARCS.Invocation.cast=function(n,t){if(void 0!==n.value){var e=t.getComponent(n.destination);return void 0===e&&console.error("[ARCS] Destination ",n.destination," is undefined"),new ARCS.Invocation(e,n.slot,n.value)}if(void 0!==n.ref)return new ARCS.Invocation(t.getComponent(n.destination),n.slot,t.getConstant(n.ref))},ARCS.Invocation.PRE_CONNECTION=0,ARCS.Invocation.POST_CONNECTION=1,ARCS.Invocation.CLEAN_UP=2,ARCS.Connection=function(n,t,e,o){this.connect=function(){try{ARCS.Component.connect(n,t,e,o)}catch(i){console.log(i,n,t,e,o)}},this.disconnect=function(){ARCS.Component.disconnect(n,t,e,o)},this.getSource=function(){return n},this.getDestination=function(){return e},this.getSlot=function(){return o},this.getSignal=function(){return t}},ARCS.Connection.cast=function(n,t){return new ARCS.Connection(t.getComponent(n.source),n.signal,t.getComponent(n.destination),n.slot)},ARCS.Sheet=function(n){var t,e,o,i,r,s=new ARCS.Context,c=[],a=[],u=[],f=[],l=0,p=0,h=0,C=0;t=function(){var n;for(n=0;n<c.length;n++)c[n].invoke()},e=function(){var n;for(n=0;n<a.length;n++)a[n].invoke()},o=function(){var n;for(n=0;n<u.length;n++)u[n].invoke()},i=function(){var n;for(n=0;n<f.length;n++)f[n].connect()},r=function(){var n;for(n=0;n<f.length;n++)f[n].disconnect()},this.setContext=function(n){s=n},this.activate=function(){s.instanciate().then((function(){t(),i(),e()}))},this.deactivate=function(){r(),o()},this.addPreConnection=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=l++,c.push(t),t.id},this.addPostConnection=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=p++,a.push(t),t.id},this.addCleanup=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=h++,u.push(t),t.id},this.addConnection=function(n){var t=ARCS.Connection.cast(n,s);return t.id=C++,f.push(t),t.id};var d=function(n,t){for(var e=t.length;e--&&t[e].id!==n;);e>=0?t.splice(e,1):console.warn("Could not remove data with id",n)};this.removePreConnection=function(n){d(n,c)},this.removePostConnection=function(n){d(n,a)},this.removeCleanup=function(n){d(n,u)};var v=function(n,t,e){for(var o=e.length;o--&&e[o].id!==n;);o>=0&&(e[o].value=t)};this.changePreConnection=function(n,t){v(n,t,c)},this.changePostConnection=function(n,t){v(n,t,a)},this.changeCleanup=function(n,t){v(n,t,u)},this.removeConnection=function(n){d(n,f)};var g=function(n,t,e){for(var o,i=e.length,r=e.length;i--&&e[i].id!==n;);for(;r--&&e[r].id!==t;);i>=0&&r>=0&&(o=e[i],e[i]=e[r],e[r]=o,e[i].id=n,e[r].id=t)};this.swapConnections=function(n,t){g(n,t,f)},this.swapCleanups=function(n,t){g(n,t,u)},this.swapPreConnections=function(n,t){g(n,t,c)},this.swapPostConnections=function(n,t){g(n,t,a)};this.import=function(t){t.hasOwnProperty("context")&&(s=new ARCS.Context(t.context)).setParent(n),s.instanciate().then((function(){!function(n){var t=0,e=ARCS.Invocation.cast,o=ARCS.Connection.cast;for(t=0;t<n.preconnections.length;t++)c.push(e(n.preconnections[t],s));for(t=0;t<n.postconnections.length;t++)a.push(e(n.postconnections[t],s));for(t=0;t<n.cleanups.length;t++)u.push(e(n.cleanups[t],s));for(t=0;t<n.connections.length;t++)f.push(o(n.connections[t],s))}(t)}))};var S=function(n){return{destination:s.getComponentName(n.getDestination()),slot:n.getSlot(),value:n.getValue()}};this.toJSON=function(){var n,t,e=[],o=[],i=[],r=[];for(n=0;n<f.length;n++)i.push((t=f[n],{source:s.getComponentName(t.getSource()),signal:t.getSignal(),destination:s.getComponentName(t.getDestination()),slot:t.getSlot()}));for(n=0;n<c.length;n++)e.push(S(c[n]));for(n=0;n<a.length;n++)o.push(S(a[n]));for(n=0;n<u.length;n++)r.push(S(u[n]));return{preconnections:e,postconnections:o,connections:i,cleanups:r}},s.setParent(n)},ARCS.EventLogicParser=function(){function n(n,t,e,o,i,r){this.message=n,this.expected=t,this.found=e,this.offset=o,this.line=i,this.column=r,this.name="SyntaxError"}return function(n,t){function e(){this.constructor=n}e.prototype=t.prototype,n.prototype=new e}(n,Error),{SyntaxError:n,parse:function(t){var e,o=arguments.length>1?arguments[1]:{},i={},r={start:U},s=U,c=i,a=function(n,t){return[n].concat(t)},u=function(n){return{and:n}},f=function(n){return{or:n}},l=function(n){return n},p="(",h={type:"literal",value:"(",description:'"("'},C=")",d={type:"literal",value:")",description:'")"'},v=function(n){return[n]},g={type:"other",description:"id"},S=function(n){return n.trim()},A=/^[_a-zA-Z]/,m={type:"class",value:"[_a-zA-Z]",description:"[_a-zA-Z]"},y=/^[_a-zA-Z0-9]/,R={type:"class",value:"[_a-zA-Z0-9]",description:"[_a-zA-Z0-9]"},w="&",x={type:"literal",value:"&",description:'"&"'},P="|",O={type:"literal",value:"|",description:'"|"'},T=/^[ \r\n\t]/,N={type:"class",value:"[ \\r\\n\\t]",description:"[ \\r\\n\\t]"},b=0,k=0,F={line:1,column:1,seenCR:!1},I=0,E=[],L=0;if("startRule"in o){if(!(o.startRule in r))throw new Error("Can't start parsing from rule \""+o.startRule+'".');s=r[o.startRule]}function j(n){return k!==n&&(k>n&&(k=0,F={line:1,column:1,seenCR:!1}),function(n,e,o){var i,r;for(i=e;i<o;i++)"\n"===(r=t.charAt(i))?(n.seenCR||n.line++,n.column=1,n.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(n.line++,n.column=1,n.seenCR=!0):(n.column++,n.seenCR=!1)}(F,k,n),k=n),F}function _(n){b<I||(b>I&&(I=b,E=[]),E.push(n))}function q(e,o,i){var r=j(i),s=i<t.length?t.charAt(i):null;return null!==o&&function(n){var t=1;for(n.sort((function(n,t){return n.description<t.description?-1:n.description>t.description?1:0}));t<n.length;)n[t-1]===n[t]?n.splice(t,1):t++}(o),new n(null!==e?e:function(n,t){var e,o=new Array(n.length);for(e=0;e<n.length;e++)o[e]=n[e].description;return"Expected "+(n.length>1?o.slice(0,-1).join(", ")+" or "+o[n.length-1]:o[0])+" but "+(t?'"'+function(n){function t(n){return n.charCodeAt(0).toString(16).toUpperCase()}return n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,(function(n){return"\\x0"+t(n)})).replace(/[\x10-\x1F\x80-\xFF]/g,(function(n){return"\\x"+t(n)})).replace(/[\u0180-\u0FFF]/g,(function(n){return"\\u0"+t(n)})).replace(/[\u1080-\uFFFF]/g,(function(n){return"\\u"+t(n)}))}(t)+'"':"end of input")+" found."}(o,s),o,s,i,r.line,r.column)}function U(){return D()}function D(){var n,t,e,o;if(n=b,(t=Z())!==i){if(e=[],(o=z())!==i)for(;o!==i;)e.push(o),o=z();else e=c;e!==i?(n,n=t=a(t,e)):(b=n,n=c)}else b=n,n=c;return n===i&&(n=Z()),n}function z(){var n,e;return n=b,function(){var n,e,o,r;n=b,(e=V())!==i?(38===t.charCodeAt(b)?(o=w,b++):(o=i,0===L&&_(x)),o!==i&&(r=V())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c);return n}()!==i&&(e=Z())!==i?(n,n=u(e)):(b=n,n=c),n===i&&(n=b,function(){var n,e,o,r;n=b,(e=V())!==i?(124===t.charCodeAt(b)?(o=P,b++):(o=i,0===L&&_(O)),o!==i&&(r=V())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c);return n}()!==i&&(e=Z())!==i?(n,n=f(e)):(b=n,n=c)),n}function Z(){var n,e,o,r;return n=b,(e=function(){var n,e,o;L++,n=b,e=b,(o=function(){var n,e,o,r,s;if(n=b,(e=V())!==i)if(A.test(t.charAt(b))?(o=t.charAt(b),b++):(o=i,0===L&&_(m)),o!==i){for(r=[],y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));s!==i;)r.push(s),y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));r!==i&&(s=V())!==i?n=e=[e,o,r,s]:(b=n,n=c)}else b=n,n=c;else b=n,n=c;return n}())!==i&&(o=t.substring(e,b));(e=o)!==i&&(n,e=S(e));L--,(n=e)===i&&(e=i,0===L&&_(g));return n}())!==i&&(n,e=l(e)),(n=e)===i&&(n=b,40===t.charCodeAt(b)?(e=p,b++):(e=i,0===L&&_(h)),e!==i&&(o=D())!==i?(41===t.charCodeAt(b)?(r=C,b++):(r=i,0===L&&_(d)),r!==i?(n,n=e=v(o)):(b=n,n=c)):(b=n,n=c)),n}function V(){var n,e;for(n=[],T.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(N));e!==i;)n.push(e),T.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(N));return n}if((e=s())!==i&&b===t.length)return e;throw e!==i&&b<t.length&&_({type:"end",description:"end of input"}),q(null,E,I)}}}(),ARCS.TokenEvent=function(){var n,t;this.promise=new Promise((function(e,o){n=e,t=o})),this.accept=function(){n()},this.abort=function(){t()}},ARCS.TransitionNetwork=function(){this.promise={},this.and=function(n){return this.promise=Promise.all([this.promise,n.promise]),this},this.or=function(n){return this.promise=Promise.race([this.promise,n.promise]),this}},ARCS.TransitionNetwork.build=function(n,t){var e,o,r;if("string"==typeof n){var s;t.hasOwnProperty(n)?s=t[n]:t[n]=s=new ARCS.TokenEvent;var c=new ARCS.TransitionNetwork;return c.promise=s.promise,c}for(e=ARCS.TransitionNetwork.build(n[0],t),i=1;i<n.length;i++)n[i].hasOwnProperty("and")?(r=ARCS.TransitionNetwork.build(n[i].and,t),o=e.and(r)):n[i].hasOwnProperty("or")?(r=ARCS.TransitionNetwork.build(n[i].or,t),o=e.or(r)):console.warn("[ARCS] Illegal tree"),e=o;return e},ARCS.Statemachine=new ARCS.Component.create((function(n){var t="",e="",o={},i="",r=this,s={},c={},a=function(n){var t;r.slots.indexOf(n)<0&&(r.slots.push(n),r[n]=(t=n,function(){r.setToken(t)}))},u=function(n){var t;if(o.hasOwnProperty(n))for(t in c={},o[n])o[n].hasOwnProperty(t)&&ARCS.TransitionNetwork.build(s[t],c).promise.then((function(){var e;for(e in c)c.hasOwnProperty(e)&&c[e].abort();u(o[n][t])}));i=n,r.emit("requestSheet",i),i===e&&r.emit("requestTermination")};this.setInitialState=function(n){i=t=n},this.setFinalState=function(n){e=n},this.addTransition=function(n,t,e){var i,r=/([A-Za-z_]\w*)/g;try{var c;if("string"==typeof(c=ARCS.EventLogicParser.parse(t)))a(c);else for(;null!==(i=r.exec(t));)a(i[0]);s[t]=c,void 0===o[n]&&(o[n]={}),o[n][t]=e}catch(n){}},this.setToken=function(n){c.hasOwnProperty(n)&&c[n].accept()},this.setTransitions=function(n){var t,e;for(t in n)if(n.hasOwnProperty(t))for(e in n[t])n[t].hasOwnProperty(e)&&this.addTransition(t,e,n[t][e])},this.start=function(){console.log("statemachine",this,t,n),u(t)},void 0!==n&&(t=n.initial,e=n.final,this.setTransitions(n.transitions),i="")}),["setToken"],["requestSheet","requestTermination"]),ARCS.Application=function(){var n,t=new ARCS.Context,e={},o={},i=[],r=this,s="";this.export=function(){return{context:t,controller:t.getComponentName(o),sheets:e}},this.getContext=function(){return t},this.getSheetList=function(){return Object.keys(e)},this.getSheet=function(n){return e[n]},this.addSheet=function(n,o){e[n]=o,o.setContext(t)},this.removeSheet=function(n){delete e[n]},n=function(){var n,i,s;for(i=t.getComponent(o),o=i,s=Object.keys(e),n=0;n<s.length;n++)(i=new ARCS.Sheet(t)).import(e[s[n]],t),e[s[n]]=i;ARCS.Component.connect(o,"requestSheet",r,"setSheet"),ARCS.Component.connect(o,"requestTermination",r,"finish"),o.start()},this.setController=function(n){o=t.getComponent(n)},this.setSheet=function(n){e.hasOwnProperty(n)?(s&&e[s].deactivate(),e[s=n].activate()):console.warn("[ARCS] Tried to activate hollow sheet named: "+n)},this.finish=function(){s&&e[s].deactivate()},this.import=function(n){t=new ARCS.Context(n.context),e=n.sheets,void 0===(o=n.controller)&&console.error("[ARCS] Undefined controller. Cannot start application.")},this.setFactory=function(n,t){factories[n]=t},this.setDependency=function(n){i[n]={}},this.start=function(){console.log("[ARCS] Starting application..."),t.instanciate().then(n)}},ARCS.Application.setDependency=function(n,t){n.setDependency(t)},ARCS.Component.create(ARCS.Application),ARCS.Application.slot("setSheet"),ARCS.Application.slot("finish");export{ARCS as default}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | /* ugly hack in order to display data in web page instead of console */ | 1 | /* ugly hack in order to display data in web page instead of console */ |
2 | +import ARCS from '../build/arcs.js'; | ||
2 | 3 | ||
4 | +var Console; | ||
5 | +/** | ||
6 | + * @class Console | ||
7 | + * @classdesc Redirects console messages to a given HTML element in the page. | ||
8 | + * @param id {string} id of the HTML element in which console messages will be added. | ||
9 | + */ | ||
10 | +Console = ARCS.Component.create( | ||
11 | + function (id) { | ||
12 | + if (id === undefined) { | ||
13 | + return ; | ||
14 | + } | ||
15 | + | ||
16 | + var output = document.getElementById(id); | ||
17 | + | ||
18 | + if (output) { | ||
19 | + window.console = { | ||
20 | + timeRef: new Date().getTime(), | ||
21 | + output : output, | ||
22 | + display: function(color,args) { | ||
23 | + var s = document.createElement("span"); | ||
24 | + s.style.color=color; | ||
25 | + var elapsed = (new Date().getTime() - this.timeRef); | ||
3 | 26 | ||
4 | -arcs_module( | 27 | + s.innerHTML = '<span class="marker">' + (elapsed/1000).toFixed(3) + '</span>' + Array.prototype.join.call(args, ' '); |
5 | - function(ARCS) { | 28 | + output.appendChild(s); |
6 | - var Console; | 29 | + output.appendChild(document.createElement("br")); |
7 | - /** | 30 | + }, |
8 | - * @class Console | 31 | + log: function () { |
9 | - * @classdesc Redirects console messages to a given HTML element in the page. | 32 | + this.display('green',arguments); |
10 | - * @param id {string} id of the HTML element in which console messages will be added. | 33 | + }, |
11 | - */ | 34 | + error: function () { |
12 | - Console = ARCS.Component.create( | 35 | + this.display('red',arguments); |
13 | - function (id) { | 36 | + }, |
14 | - if (id === undefined) { | 37 | + warn: function () { |
15 | - return ; | 38 | + this.display('orange',arguments); |
16 | } | 39 | } |
17 | - | 40 | + }; |
18 | - var output = document.getElementById(id); | 41 | + } |
19 | - | ||
20 | - if (output) { | ||
21 | - window.console = { | ||
22 | - timeRef: new Date().getTime(), | ||
23 | - output : output, | ||
24 | - display: function(color,args) { | ||
25 | - var s = document.createElement("span"); | ||
26 | - s.style.color=color; | ||
27 | - var elapsed = (new Date().getTime() - this.timeRef); | ||
28 | - | ||
29 | - s.innerHTML = '<span class="marker">' + (elapsed/1000).toFixed(3) + '</span>' + Array.prototype.join.call(args, ' '); | ||
30 | - output.appendChild(s); | ||
31 | - output.appendChild(document.createElement("br")); | ||
32 | - }, | ||
33 | - log: function () { | ||
34 | - this.display('green',arguments); | ||
35 | - }, | ||
36 | - error: function () { | ||
37 | - this.display('red',arguments); | ||
38 | - }, | ||
39 | - warn: function () { | ||
40 | - this.display('orange',arguments); | ||
41 | - } | ||
42 | - }; | ||
43 | - } | ||
44 | - } | ||
45 | - ); | ||
46 | - return { Console: Console}; | ||
47 | } | 42 | } |
43 | +); | ||
44 | + | ||
48 | 45 | ||
49 | -); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
46 | +export default { Console: Console}; | ... | ... |
... | @@ -5,111 +5,99 @@ | ... | @@ -5,111 +5,99 @@ |
5 | * @file | 5 | * @file |
6 | */ | 6 | */ |
7 | 7 | ||
8 | -// TODO first strategy: import ARCS and export components | 8 | +import ARCS from '../build/arcs.js'; |
9 | -// TODO second strategy: make an anonymous function to export | ||
10 | -// in any case, arcs_module disappears | ||
11 | 9 | ||
12 | - | 10 | +/** |
13 | - | 11 | + * @class Loop |
14 | -//! TODO to comment or uncomment (maybe) | 12 | + * @classdesc loop component creation using a compact style. |
15 | -// imports ARCS from '../build/arcs.js'; | 13 | + * This component iterates for a given number of times |
16 | -function (ARCS) { | 14 | + */ |
17 | - var Loop, DisplayInt, Sum; | 15 | +var Loop = ARCS.Component.create( |
18 | - /** @exports loop */ | 16 | + function () { |
19 | - //console.log("loop: ", ARCS); | ||
20 | /** | 17 | /** |
21 | - * @class Loop | 18 | + * Sets the number of times the component should iterate. |
22 | - * @classdesc loop component creation using a compact style. | 19 | + * It starts the iterations. At each iteration, a signal newIteration is |
23 | - * This component iterates for a given number of times | 20 | + * emitted, then, at the end of the iterations, a signal sendToken is |
24 | - */ | 21 | + * eventually triggered. |
25 | - Loop = ARCS.Component.create( | 22 | + * @param n {numeric} number of iterations |
26 | - function () { | 23 | + * @function Loop#setIterations |
27 | - /** | 24 | + * @slot |
28 | - * Sets the number of times the component should iterate. | 25 | + * @emits newIteration |
29 | - * It starts the iterations. At each iteration, a signal newIteration is | 26 | + * @emits sendToken |
30 | - * emitted, then, at the end of the iterations, a signal sendToken is | 27 | + */ |
31 | - * eventually triggered. | 28 | + this.setIterations = function (n) { |
32 | - * @param n {numeric} number of iterations | 29 | + var i; |
33 | - * @function Loop#setIterations | 30 | + for (i = 0; i < n; i++) { |
34 | - * @slot | 31 | + console.log("Loop : emitting ", i); |
35 | - * @emits newIteration | 32 | + this.emit("newIteration", i); |
36 | - * @emits sendToken | 33 | + } |
37 | - */ | 34 | + this.emit("endLoop"); |
38 | - this.setIterations = function (n) { | 35 | + }; |
39 | - var i; | 36 | + |
40 | - for (i = 0; i < n; i++) { | 37 | + /** @function Loop#newIteration |
41 | - console.log("Loop : emitting ", i); | 38 | + * @signal |
42 | - this.emit("newIteration", i); | 39 | + * @param n {number} current iteration number. |
43 | - } | 40 | + */ |
44 | - this.emit("endLoop"); | 41 | + |
45 | - }; | 42 | + /** @function Loop#sendToken |
46 | - | 43 | + * @signal |
47 | - /** @function Loop#newIteration | 44 | + * @param s {string} token to emit. |
48 | - * @signal | 45 | + */ |
49 | - * @param n {number} current iteration number. | 46 | + |
50 | - */ | 47 | + }, |
51 | - | 48 | + "setIterations", //slotList |
52 | - /** @function Loop#sendToken | 49 | + ["endLoop", "newIteration"] // signalList |
53 | - * @signal | 50 | +); |
54 | - * @param s {string} token to emit. | ||
55 | - */ | ||
56 | - | ||
57 | - }, | ||
58 | - "setIterations", //slotList | ||
59 | - ["endLoop", "newIteration"] // signalList | ||
60 | - ); | ||
61 | 51 | ||
62 | 52 | ||
63 | - /** | 53 | +/** |
64 | - * @class DisplayInt | 54 | + * @class DisplayInt |
65 | - * @classdesc displayInt component creation using a variation with defined slots | 55 | + * @classdesc displayInt component creation using a variation with defined slots |
66 | - * in the constructor (a slot is a function). DisplayInt will display an integer | 56 | + * in the constructor (a slot is a function). DisplayInt will display an integer |
67 | - * received on its display slot. | 57 | + * received on its display slot. |
68 | - */ | 58 | + */ |
69 | - DisplayInt = function () { | 59 | +var DisplayInt = function () { |
70 | - /** | 60 | +/** |
71 | - * @param n {numeric} number to display | 61 | + * @param n {numeric} number to display |
72 | - * @function DisplayInt#display | 62 | + * @function DisplayInt#display |
73 | - * @slot | 63 | + * @slot |
74 | - */ | 64 | + */ |
75 | - this.display = function (n) { | 65 | + this.display = function (n) { |
76 | - console.log(" DisplayInt : " + n); | 66 | + console.log(" DisplayInt : " + n); |
77 | - }; | ||
78 | }; | 67 | }; |
68 | +}; | ||
79 | 69 | ||
80 | - ARCS.Component.create(DisplayInt); | 70 | +ARCS.Component.create(DisplayInt); |
81 | - DisplayInt.slot("display"); | 71 | +DisplayInt.slot("display"); |
82 | 72 | ||
83 | 73 | ||
84 | - /** | 74 | +/** |
85 | - * @class Sum | 75 | + * @class Sum |
86 | - * @classdec Sum is a component summing integers passed to its slot "add" | 76 | + * @classdec Sum is a component summing integers passed to its slot "add" |
87 | - * and the result is sent back by signal "sum". | 77 | + * and the result is sent back by signal "sum". |
88 | - * This component is declared in two different phases: declaration of the | 78 | + * This component is declared in two different phases: declaration of the |
89 | - * constructor and declaration of the slot "add". | 79 | + * constructor and declaration of the slot "add". |
90 | - */ | 80 | + */ |
91 | - Sum = function () { | 81 | +var Sum = function () { |
92 | - this.total = 0; | 82 | + this.total = 0; |
93 | - }; | 83 | +}; |
94 | 84 | ||
95 | - ARCS.Component.create(Sum); | 85 | +ARCS.Component.create(Sum); |
96 | - /** | 86 | +/** |
97 | - * This slot adds its parameter to its internal sum and send it back by using | 87 | + * This slot adds its parameter to its internal sum and send it back by using |
98 | - * the signal "sum". | 88 | + * the signal "sum". |
99 | - * @param n {integer} add n to the internal sum of the component. | 89 | + * @param n {integer} add n to the internal sum of the component. |
100 | - * @function Sum#add | 90 | + * @function Sum#add |
101 | - * @slot | 91 | + * @slot |
102 | - */ | 92 | + */ |
103 | - Sum.slot("add", function (n) { | 93 | +Sum.slot("add", function (n) { |
104 | - this.total = this.total + n; | 94 | + this.total = this.total + n; |
105 | - this.emit("sum", this.total); //console.log(" Total : " + this.total); | 95 | + this.emit("sum", this.total); //console.log(" Total : " + this.total); |
106 | - }); | 96 | +}); |
107 | - Sum.signal("sum"); | 97 | +Sum.signal("sum"); |
108 | 98 | ||
109 | - // the anonymous function must return the components in one object: | 99 | +// the anonymous function must return the components in one object: |
110 | - // keys are factory names, value are actual constructors modified by | 100 | +// keys are factory names, value are actual constructors modified by |
111 | - // ARCS.Component.create | 101 | +// ARCS.Component.create |
112 | 102 | ||
113 | - return {Loop: Loop, DisplayInt: DisplayInt, Sum: Sum}; | 103 | +export default {Loop: Loop, DisplayInt: DisplayInt, Sum: Sum}; |
114 | -//! TODO comment or uncomment (maybe) | ||
115 | -} | ... | ... |
... | @@ -16,11 +16,10 @@ | ... | @@ -16,11 +16,10 @@ |
16 | "bower": ">=1.3.9", | 16 | "bower": ">=1.3.9", |
17 | "grunt": ">=0.4.5", | 17 | "grunt": ">=0.4.5", |
18 | "grunt-jslint": ">=1.1.12", | 18 | "grunt-jslint": ">=1.1.12", |
19 | - "grunt-contrib-obfuscator": "*", | ||
20 | "grunt-terser": "*", | 19 | "grunt-terser": "*", |
21 | - "grunt-file-minify": ">=1.0.0", | ||
22 | "grunt-jsdoc": ">=0.5.6", | 20 | "grunt-jsdoc": ">=0.5.6", |
23 | "grunt-bower-task": ">=0.4.0", | 21 | "grunt-bower-task": ">=0.4.0", |
24 | - "grunt-contrib-concat": ">=0.5.0" | 22 | + "grunt-contrib-concat": ">=0.5.0", |
23 | + "grunt-contrib-copy": ">=1.0.0" | ||
25 | } | 24 | } |
26 | } | 25 | } | ... | ... |
... | @@ -199,7 +199,7 @@ ARCS.Application = function () { | ... | @@ -199,7 +199,7 @@ ARCS.Application = function () { |
199 | * Starts the application | 199 | * Starts the application |
200 | */ | 200 | */ |
201 | this.start = function () { | 201 | this.start = function () { |
202 | - console.log("[ARCS] Starting application"); | 202 | + console.log("[ARCS] Starting application..."); |
203 | context.instanciate().then(preProcess); | 203 | context.instanciate().then(preProcess); |
204 | }; | 204 | }; |
205 | }; | 205 | }; | ... | ... |
... | @@ -3,31 +3,31 @@ | ... | @@ -3,31 +3,31 @@ |
3 | * It relies on require.js to get the job done. | 3 | * It relies on require.js to get the job done. |
4 | * @file | 4 | * @file |
5 | */ | 5 | */ |
6 | +"use strict"; | ||
6 | 7 | ||
7 | // basically, here we start by importing the module ARCS | 8 | // basically, here we start by importing the module ARCS |
8 | import ARCS from './arcs.js'; | 9 | import ARCS from './arcs.js'; |
9 | 10 | ||
10 | 11 | ||
11 | -console.log("Bootstrapping ARCS..."); | 12 | +console.log("[ARCS] Bootstrapping..."); |
12 | 13 | ||
13 | var baseUrl, appDescription, requireMarkup, xhr; | 14 | var baseUrl, appDescription, requireMarkup, xhr; |
14 | 15 | ||
15 | -requireMarkup = document.querySelector('[data-main]'); | 16 | +requireMarkup = document.querySelector('[data-arcsapp]'); |
16 | if (requireMarkup !== undefined) { | 17 | if (requireMarkup !== undefined) { |
17 | baseUrl = requireMarkup.dataset.baseUrl ; | 18 | baseUrl = requireMarkup.dataset.baseUrl ; |
18 | appDescription = requireMarkup.dataset.arcsapp || "arcsapp.json"; | 19 | appDescription = requireMarkup.dataset.arcsapp || "arcsapp.json"; |
19 | } | 20 | } |
20 | 21 | ||
22 | + | ||
23 | +(async function toto() { | ||
21 | var description = await(fetch(appDescription)); | 24 | var description = await(fetch(appDescription)); |
22 | var applicationObject = await(description.json()); | 25 | var applicationObject = await(description.json()); |
23 | 26 | ||
24 | 27 | ||
25 | -console.log("ARCS application description loaded"); | 28 | +console.log("[ARCS] Application description loaded"); |
26 | 29 | ||
27 | -if (baseUrl) { | ||
28 | - require.config( { baseUrl: baseUrl }); | ||
29 | -} | ||
30 | var aap = new ARCS.Application(); | 30 | var aap = new ARCS.Application(); |
31 | aap.import(applicationObject); | 31 | aap.import(applicationObject); |
32 | -console.log("Starting application..."); | ||
33 | aap.start(); | 32 | aap.start(); |
33 | +})(); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
src/arcs_module.js
deleted
100644 → 0
1 | -/** | ||
2 | - * definition of the main module function: | ||
3 | - * it takes an anonymous function as a parameter | ||
4 | - * the anonymous function has one parameter: the object encompassing | ||
5 | - * ARCS definitions (in order to able to use ARCS.Component.create, ...) | ||
6 | - * @param moduleDefinition {function} main function of the module. | ||
7 | - * It should return a list of components | ||
8 | - * @param deps {mixed[]} dependencies | ||
9 | - */ | ||
10 | - | ||
11 | -// TODO arcs_module seems to be not needed anymore!!!! | ||
12 | -// more cunning, this time, we export an arcs_module function | ||
13 | -// that we call later! | ||
14 | -// still we need to do something about it in order to register | ||
15 | -// components. | ||
16 | -// in fact factories should be registered in load library. | ||
17 | - | ||
18 | -// reimplementation using native promises | ||
19 | -arcs_module = function(moduleDefinition, deps) { | ||
20 | - var storeComponents, i; | ||
21 | - | ||
22 | - if (typeof module !== 'undefined') { | ||
23 | - if (module.parent.exports) { | ||
24 | - ARCS = module.exports; | ||
25 | - } | ||
26 | - } | ||
27 | - | ||
28 | - if (deps === undefined) { deps = []; } | ||
29 | - | ||
30 | - storeComponents = function (deps) { | ||
31 | - var mdef, p; | ||
32 | - // we should insert ARCS at the beginning of deps ! | ||
33 | - deps.unshift(ARCS); | ||
34 | - | ||
35 | - mdef = (typeof moduleDefinition === 'function') ? | ||
36 | - moduleDefinition.apply(this, deps) : moduleDefinition; | ||
37 | - | ||
38 | - if (mdef === undefined) { | ||
39 | - throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n" +moduleDefinition); | ||
40 | - } | ||
41 | - | ||
42 | - for (p in mdef) { | ||
43 | - if (mdef.hasOwnProperty(p) && ARCS.Context.currentContext != null) { | ||
44 | - ARCS.Context.currentContext.setFactory(p,mdef[p]); //.setFactory(ARCS.Application.currentApplication, p, mdef[p]); | ||
45 | - } | ||
46 | - } | ||
47 | - | ||
48 | - return Promise.resolve(); | ||
49 | - }; | ||
50 | - // until now, it is the very same code. | ||
51 | - | ||
52 | - // here we create a promise to solve dependency | ||
53 | - // reject has the dependency name, while resolve has the object | ||
54 | - var depResolve = function(dep) { | ||
55 | - return new Promise(function(resolve, reject) { | ||
56 | - var d,shimConfig; | ||
57 | - if (ARCS.isInNode()) { | ||
58 | - d = require(dep); | ||
59 | - if (d === undefined) { | ||
60 | - reject(dep); | ||
61 | - } else { | ||
62 | - resolve(d); | ||
63 | - } | ||
64 | - } else { | ||
65 | - // this one a little bit trickier since we have to shim. | ||
66 | - if (dep.name !== undefined) { | ||
67 | - shimConfig = { shim: {} }; | ||
68 | - shimConfig.shim[dep.name] = { exports: dep.exports }; | ||
69 | - if (dep.deps !== undefined) { | ||
70 | - shimConfig.shim[dep.name].deps = dep.deps; | ||
71 | - } | ||
72 | - require.config(shimConfig); | ||
73 | - dep = dep.name; | ||
74 | - } | ||
75 | - // shim performed | ||
76 | - require([dep], | ||
77 | - function(d) { resolve(d); }, | ||
78 | - function(err) { console.log("[ARCS] Trouble with module ", dep); reject(dep, err); } | ||
79 | - ); | ||
80 | - } | ||
81 | - }); | ||
82 | - }; | ||
83 | - | ||
84 | - var depResolves = []; | ||
85 | - for (i=0; i<deps.length; i++) { | ||
86 | - depResolves[i] = depResolve(deps[i]); | ||
87 | - } | ||
88 | - | ||
89 | - | ||
90 | - | ||
91 | - ARCS.Context.currentContext.addLibraryPromise( | ||
92 | - Promise.all(depResolves).then(storeComponents, | ||
93 | - function(reason) { console.error("[ARCS] Failed to load dependency ", reason ); }) | ||
94 | - | ||
95 | - ); | ||
96 | - | ||
97 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -23,6 +23,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -23,6 +23,7 @@ ARCS.Context = function( ctx ) { |
23 | if (ctx !== undefined) { | 23 | if (ctx !== undefined) { |
24 | libraries = ctx.libraries; | 24 | libraries = ctx.libraries; |
25 | 25 | ||
26 | + var p; | ||
26 | for (p in ctx.components) { | 27 | for (p in ctx.components) { |
27 | if (ctx.components.hasOwnProperty(p)) { | 28 | if (ctx.components.hasOwnProperty(p)) { |
28 | components[p] = ctx.components[p]; | 29 | components[p] = ctx.components[p]; |
... | @@ -39,8 +40,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -39,8 +40,7 @@ ARCS.Context = function( ctx ) { |
39 | 40 | ||
40 | } | 41 | } |
41 | 42 | ||
42 | - //! TODO use fetch API? | 43 | + var loadDataFile =async function(fileName) { |
43 | - loadDataFile =async function(fileName) { | ||
44 | var dataPromise ; | 44 | var dataPromise ; |
45 | 45 | ||
46 | if (ARCS.isInNode()) { | 46 | if (ARCS.isInNode()) { |
... | @@ -57,19 +57,8 @@ ARCS.Context = function( ctx ) { | ... | @@ -57,19 +57,8 @@ ARCS.Context = function( ctx ) { |
57 | return client.json(); | 57 | return client.json(); |
58 | } | 58 | } |
59 | }; | 59 | }; |
60 | - | 60 | + |
61 | - //! TODO not needed anymore? | 61 | + var loadLibraries = function () { |
62 | - /*this.addLibraryPromise = function(p) { | ||
63 | - depLibPromises.push(p); | ||
64 | - };*/ | ||
65 | - | ||
66 | - /*promiseLibrary = function(libName) { | ||
67 | - return import(libName); | ||
68 | - };*/ | ||
69 | - | ||
70 | - //! TODO modify loadLibraries and loadLibrary to directly register | ||
71 | - // factories so that arcs_module is not needed anymore ? | ||
72 | - loadLibraries = function () { | ||
73 | var i; | 62 | var i; |
74 | // we will use different instances of require either the one of node | 63 | // we will use different instances of require either the one of node |
75 | // or the one from require.js | 64 | // or the one from require.js |
... | @@ -77,16 +66,13 @@ ARCS.Context = function( ctx ) { | ... | @@ -77,16 +66,13 @@ ARCS.Context = function( ctx ) { |
77 | 66 | ||
78 | var res=[]; | 67 | var res=[]; |
79 | for(i=0; i < libraries.length; i++) { | 68 | for(i=0; i < libraries.length; i++) { |
80 | - //! TODO | 69 | + res.push(self.loadLibrary(libraries[i])); |
81 | - res.push(loadLibrary(libraries[i])); | ||
82 | - //import(libraries[i])); | ||
83 | } | 70 | } |
84 | return Promise.all(res); | 71 | return Promise.all(res); |
85 | }; | 72 | }; |
86 | 73 | ||
87 | - instanciateComponents = function() { | 74 | + var instanciateComponents = function() { |
88 | var p, promises=[]; | 75 | var p, promises=[]; |
89 | - console.log(components); | ||
90 | 76 | ||
91 | for (p in components) { | 77 | for (p in components) { |
92 | if (components.hasOwnProperty(p)) { | 78 | if (components.hasOwnProperty(p)) { |
... | @@ -95,7 +81,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -95,7 +81,7 @@ ARCS.Context = function( ctx ) { |
95 | console.error("[ARCS] Context dump follows: ", libraries, components, constants); | 81 | console.error("[ARCS] Context dump follows: ", libraries, components, constants); |
96 | return ; | 82 | return ; |
97 | } | 83 | } |
98 | - factory = factories[components[p].type]; | 84 | + var factory = factories[components[p].type]; |
99 | //console.log("instanciating ", p); | 85 | //console.log("instanciating ", p); |
100 | try { | 86 | try { |
101 | if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) { | 87 | if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) { |
... | @@ -144,21 +130,23 @@ ARCS.Context = function( ctx ) { | ... | @@ -144,21 +130,23 @@ ARCS.Context = function( ctx ) { |
144 | libActualName = libName.name; | 130 | libActualName = libName.name; |
145 | libUrl = libName.url; | 131 | libUrl = libName.url; |
146 | } | 132 | } |
147 | - | 133 | + |
148 | - libraries.push(libActualName); | 134 | + if (libraries.indexOf(libActualName) < 0) { |
135 | + libraries.push(libActualName); | ||
136 | + } | ||
149 | // TODO promisify call to cbFunction | 137 | // TODO promisify call to cbFunction |
150 | return import(libUrl).then( function(module) { | 138 | return import(libUrl).then( function(module) { |
151 | // TODO insert here component factories | 139 | // TODO insert here component factories |
152 | - for (p in module) { | 140 | + for (p in module.default) { |
153 | - if (module.hasOwnProperty(p)) { | 141 | + if (module.default.hasOwnProperty(p)) { |
154 | - ARCS.Context.currentContext.setFactory(p,module[p]); | 142 | + ARCS.Context.currentContext.setFactory(p,module.default[p]); |
155 | } | 143 | } |
156 | } | 144 | } |
157 | 145 | ||
158 | if (cbFunction !== undefined) { | 146 | if (cbFunction !== undefined) { |
159 | cbFunction(); | 147 | cbFunction(); |
160 | } | 148 | } |
161 | - }); | 149 | + }).catch( function(msg) { console.error("[ARCS] Trouble loading '",libUrl,"' with reason -", msg) }); |
162 | }; | 150 | }; |
163 | 151 | ||
164 | /** | 152 | /** |
... | @@ -277,7 +265,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -277,7 +265,7 @@ ARCS.Context = function( ctx ) { |
277 | this.instanciate = function () { | 265 | this.instanciate = function () { |
278 | //! TODO | 266 | //! TODO |
279 | return loadLibraries().then(instanciateComponents) | 267 | return loadLibraries().then(instanciateComponents) |
280 | - .catch(function(msg) { console.log("[ARCS] Trouble instanciating context", msg); }); | 268 | + .catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); }); |
281 | 269 | ||
282 | }; | 270 | }; |
283 | 271 | ... | ... |
1 | { | 1 | { |
2 | "context" : { | 2 | "context" : { |
3 | - "libraries" : [ "components/loop","components/console"], | 3 | + "libraries" : [ "../components/loop.js","../components/console.js"], |
4 | "components" : { | 4 | "components" : { |
5 | "loop": { "type": "Loop" }, | 5 | "loop": { "type": "Loop" }, |
6 | "dint": { "type": "DisplayInt" }, | 6 | "dint": { "type": "DisplayInt" }, | ... | ... |
... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
4 | <script data-base-url="../.." | 4 | <script data-base-url="../.." |
5 | data-arcsapp="arcsapp.json" | 5 | data-arcsapp="arcsapp.json" |
6 | type="module" | 6 | type="module" |
7 | - src="../../build/arcs_browser"> | 7 | + src="../../build/arcs_browser.js"> |
8 | </script> | 8 | </script> |
9 | </head> | 9 | </head> |
10 | <body> | 10 | <body> | ... | ... |
-
Please register or login to post a comment