Jean-Yves Didier

use of terser as an API

......@@ -59,11 +59,8 @@ module.exports = function (grunt) {
}
}
},
obfuscator: {
terser: {
build: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
files: {
'build/arcs.min.js': [
'build/arcs.js'
......@@ -90,7 +87,7 @@ module.exports = function (grunt) {
}
},
concat: {
concat: {
dist: {
src: [
'src/arcs.js',
......@@ -122,22 +119,21 @@ module.exports = function (grunt) {
dest: 'build/arcseditor.js'
}
}
}
});
// Load the plugin that provides the "uglify" task.
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-obfuscator');
grunt.loadNpmTasks('grunt-file-minify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-jslint');
grunt.loadNpmTasks('grunt-terser');
grunt.loadNpmTasks('grunt-bower-task');
// Default task(s).
grunt.registerTask('default', ['concat',/*'file_minify','obfuscator'*/]);
// Default task(s).
grunt.registerTask('default', ['concat','terser'/*'file_minify','obfuscator'*/]);
grunt.registerTask('lint', ['jslint']);
grunt.registerTask('doc', ['jsdoc']);
};
......
......@@ -233,7 +233,7 @@ ARCS.Context = function( ctx ) {
var constants = {};
var factories = {};
var libraries = [];
var depLibPromises=[];
//var depLibPromises=[];
var self = this;
var loadLibraries;
var loadDataFile;
......@@ -283,13 +283,13 @@ ARCS.Context = function( ctx ) {
};
//! TODO not needed anymore?
this.addLibraryPromise = function(p) {
/*this.addLibraryPromise = function(p) {
depLibPromises.push(p);
};
};*/
promiseLibrary = function(libName) {
/*promiseLibrary = function(libName) {
return import(libName);
};
};*/
//! TODO modify loadLibraries and loadLibrary to directly register
// factories so that arcs_module is not needed anymore ?
......@@ -302,7 +302,8 @@ ARCS.Context = function( ctx ) {
var res=[];
for(i=0; i < libraries.length; i++) {
//! TODO
res.push(import(libraries[i]));
res.push(loadLibrary(libraries[i]));
//import(libraries[i]));
}
return Promise.all(res);
};
......@@ -369,7 +370,15 @@ ARCS.Context = function( ctx ) {
}
libraries.push(libActualName);
promiseLibrary(libUrl).then( function() {
// TODO promisify call to cbFunction
return import(libUrl).then( function(module) {
// TODO insert here component factories
for (p in module) {
if (module.hasOwnProperty(p)) {
ARCS.Context.currentContext.setFactory(p,module[p]);
}
}
if (cbFunction !== undefined) {
cbFunction();
}
......@@ -491,9 +500,8 @@ ARCS.Context = function( ctx ) {
// this should return a promise !
this.instanciate = function () {
//! TODO
return loadLibraries().then(function() { return Promise.all(depLibPromises); })
.then(instanciateComponents)
.catch(function(msg) { console.log("[ARCS] Trouble instanciating context", msg); });
return loadLibraries().then(instanciateComponents)
.catch(function(msg) { console.log("[ARCS] Trouble instanciating context", msg); });
};
......
/*! ARCS 2019-12-10 */
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=[],u=[],f=this;if(c.StateMachine=ARCS.Statemachine,void 0!==n){for(p in a=n.libraries,n.components)n.components.hasOwnProperty(p)&&(r[p]=n.components[p]);if(void 0!==n.constants)for(p in n.constants)n.constants.hasOwnProperty(p)&&(s[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()},this.addLibraryPromise=function(n){u.push(n)},o=function(n){return import(n)},t=function(){var n;ARCS.Context.currentContext=f;var t=[];for(n=0;n<a.length;n++)t.push(import(a[n]));return Promise.all(t)},i=function(){var n,t=[];for(n in console.log(r),r)if(r.hasOwnProperty(n)){if(void 0===c[r[n].type])return console.error("[ARCS] Factory "+r[n].type+" not found."),void console.error("[ARCS] Context dump follows: ",a,r,s);factory=c[r[n].type];try{if(void 0!==r[n].value||void 0!==r[n].url||void 0!==r[n].ref){if(void 0!==r[n].value&&(r[n].instance=new factory(r[n].value)),void 0!==r[n].url){console.log("loading data file",r[n].url),t.push(e(r[n].url).then(function(n,t){return function(e){return console.log("instanciating from data file"),r[n].instance=new t(e),Promise.resolve()}}(n,factory)))}void 0!==r[n].ref&&void 0!==s[r[n].ref]&&(r[n].instance=new factory(s[r[n].ref]))}else r[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,i=n;ARCS.Context.currentContext=f,"string"!=typeof n&&(i=n.name,e=n.url),a.push(i),o(e).then(function(){void 0!==t&&t()})},this.getComponentList=function(){var n,t=Object.keys(r);for(n=0;n<t.length;n++)r.hasOwnProperty(t[n])||t.splice(n--,1);return t},this.getConstant=function(n){return s[n]},this.getComponentType=function(n){if(void 0!==r[n])return r[n].type},this.getComponentValue=function(n){if(void 0!==r[n])return r[n].value},this.getComponent=function(n){if(void 0!==r[n])return r[n].instance},this.getComponentName=function(n){var t,e;for(e=r.getComponentList(),t=0;t<e.length;t++)if(r[e[t]].instance===n)return e[t]},this.setFactory=function(n,t){c[n]=t},this.toJSON=function(){var n,t={};for(n in r)r.hasOwnProperty(n)&&(t[n]={type:r[n].type,value:r[n].value});return t},this.setComponentValue=function(n,t){r[n].value=t},this.addComponent=function(n,t,e){var o;r[n]={},r[n].type=t,r[n].value=e;var i=c[t];void 0!==i&&(o=new i(e)),r[n].instance=o},this.removeComponent=function(n){delete r[n]},this.getFactory=function(n){return c[n]},this.getFactoryList=function(){return Object.keys(c)},this.instanciate=function(){return t().then(function(){return Promise.all(u)}).then(i).catch(function(n){console.log("[ARCS] Trouble instanciating context",n)})};var l=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[l(n,r),l(t,s),l(e,c)]},this.setParent=function(n){if(void 0!==n){var t=n.chain(r,s,c);r=t[0],s=t[1],c=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 m=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(m(c[n]));for(n=0;n<a.length;n++)o.push(m(a[n]));for(n=0;n<u.length;n++)r.push(m(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"},m=function(n){return n.trim()},S=/^[_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=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;return 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),n}()!==i&&(e=Z())!==i?n=u(e):(b=n,n=c),n===i&&(n=b,function(){var n,e,o,r;return 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),n}()!==i&&(e=Z())!==i?n=f(e):(b=n,n=c)),n}function Z(){var n,e,o,r;return n=b,(e=function(){var n,e,o;return L++,n=b,e=b,(o=function(){var n,e,o,r,s;if(n=b,(e=V())!==i)if(S.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&&(e=m(e)),L--,(n=e)===i&&(e=i,0===L&&_(g)),n}())!==i&&(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=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
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
......
......@@ -17,6 +17,7 @@
"grunt": ">=0.4.5",
"grunt-jslint": ">=1.1.12",
"grunt-contrib-obfuscator": "*",
"grunt-terser": "*",
"grunt-file-minify": ">=1.0.0",
"grunt-jsdoc": ">=0.5.6",
"grunt-bower-task": ">=0.4.0",
......
#!/usr/bin/env node
#!/usr/bin/env node --experimental-modules --experimental-json modules
var ARCS = require('./arcs.js');
var application = require('./appli.json');
import ARCS from './arcs.js';
import application from './appli.json';
var aap = new ARCS.Application();
aap.import(application);
aap.start();
......
......@@ -9,7 +9,7 @@ ARCS.Context = function( ctx ) {
var constants = {};
var factories = {};
var libraries = [];
var depLibPromises=[];
//var depLibPromises=[];
var self = this;
var loadLibraries;
var loadDataFile;
......@@ -59,13 +59,13 @@ ARCS.Context = function( ctx ) {
};
//! TODO not needed anymore?
this.addLibraryPromise = function(p) {
/*this.addLibraryPromise = function(p) {
depLibPromises.push(p);
};
};*/
promiseLibrary = function(libName) {
/*promiseLibrary = function(libName) {
return import(libName);
};
};*/
//! TODO modify loadLibraries and loadLibrary to directly register
// factories so that arcs_module is not needed anymore ?
......@@ -78,7 +78,8 @@ ARCS.Context = function( ctx ) {
var res=[];
for(i=0; i < libraries.length; i++) {
//! TODO
res.push(import(libraries[i]));
res.push(loadLibrary(libraries[i]));
//import(libraries[i]));
}
return Promise.all(res);
};
......@@ -145,7 +146,15 @@ ARCS.Context = function( ctx ) {
}
libraries.push(libActualName);
promiseLibrary(libUrl).then( function() {
// TODO promisify call to cbFunction
return import(libUrl).then( function(module) {
// TODO insert here component factories
for (p in module) {
if (module.hasOwnProperty(p)) {
ARCS.Context.currentContext.setFactory(p,module[p]);
}
}
if (cbFunction !== undefined) {
cbFunction();
}
......@@ -267,9 +276,8 @@ ARCS.Context = function( ctx ) {
// this should return a promise !
this.instanciate = function () {
//! TODO
return loadLibraries().then(function() { return Promise.all(depLibPromises); })
.then(instanciateComponents)
.catch(function(msg) { console.log("[ARCS] Trouble instanciating context", msg); });
return loadLibraries().then(instanciateComponents)
.catch(function(msg) { console.log("[ARCS] Trouble instanciating context", msg); });
};
......