Jean-Yves Didier

can now bundle things with webpack

...@@ -116,18 +116,18 @@ module.exports = function (grunt) { ...@@ -116,18 +116,18 @@ module.exports = function (grunt) {
116 concat: { 116 concat: {
117 dist: { 117 dist: {
118 src: [ 118 src: [
119 - 'src/arcs.js', 119 + 'src/arcs.js', *
120 - 'src/component.js', 120 + 'src/component.js', *
121 - 'src/context.js', 121 + 'src/context.js', *
122 - 'src/invocation.js', 122 + 'src/invocation.js', *
123 - 'src/connection.js', 123 + 'src/connection.js', *
124 'src/sheet.js', 124 'src/sheet.js',
125 - 'src/eventlogicparser.js', 125 + 'src/eventlogicparser.js', *
126 - 'src/tokenevent.js', 126 + 'src/tokenevent.js', *
127 - 'src/transitionnetwork.js', 127 + 'src/transitionnetwork.js', *
128 - 'src/statemachine.js', 128 + 'src/statemachine.js', *
129 'src/application.js', 129 'src/application.js',
130 - 'src/exports.js' 130 + 'src/exports.js' *
131 ], 131 ],
132 dest: 'build/arcs.js' 132 dest: 'build/arcs.js'
133 }, 133 },
......
1 -// ARCS.js : 27/6/2014 16:00 1 +/******/ (() => { // webpackBootstrap
2 -// handling dependencies 2 +/******/ "use strict";
3 - 3 +/******/ var __webpack_modules__ = ([
4 - 4 +/* 0 */,
5 -//"use strict"; 5 +/* 1 */
6 - 6 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
7 - 7 +
8 -/** 8 +__webpack_require__.r(__webpack_exports__);
9 - * Main source: describes all the methods needed by the ARCS engine 9 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
10 - * @file 10 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
11 - */ 11 +/* harmony export */ });
12 -
13 -/**
14 - * Defines all elements needed for Augmented Reality Component System
15 - * @namespace
16 - */
17 -var ARCS = ARCS || {};
18 -
19 -
20 -
21 -/******************************************************************************
22 - * Helper functions to determine environment
23 - * ***************************************************************************/
24 -
25 -/**
26 - * @return {boolean} true if ARCS is run in a node.js environment
27 - */
28 -ARCS.isInNode = function () {
29 - return (typeof require === 'function' && require.resolve);
30 -};
31 -
32 -
33 -
34 /****************************************************************************** 12 /******************************************************************************
35 * Component implementation 13 * Component implementation
36 * ***************************************************************************/ 14 * ***************************************************************************/
...@@ -41,7 +19,7 @@ ARCS.isInNode = function () { ...@@ -41,7 +19,7 @@ ARCS.isInNode = function () {
41 * 19 *
42 * @namespace 20 * @namespace
43 */ 21 */
44 -ARCS.Component = { 22 +var Component = {
45 /** Error message */ 23 /** Error message */
46 SourceIsNotComponent : {message : "Source is not a component"}, 24 SourceIsNotComponent : {message : "Source is not a component"},
47 /** Error message */ 25 /** Error message */
...@@ -157,13 +135,13 @@ ARCS.Component = { ...@@ -157,13 +135,13 @@ ARCS.Component = {
157 var orig, p; 135 var orig, p;
158 // here we can perform various checks. 136 // here we can perform various checks.
159 if (source.signals === undefined) { 137 if (source.signals === undefined) {
160 - throw ARCS.Component.SourceIsNotComponent; 138 + throw Component.SourceIsNotComponent;
161 } 139 }
162 if (source.signals[signal] === undefined) { 140 if (source.signals[signal] === undefined) {
163 - throw ARCS.Component.UndefinedSignal; 141 + throw Component.UndefinedSignal;
164 } 142 }
165 if (destination[slt] === undefined) { 143 if (destination[slt] === undefined) {
166 - throw ARCS.Component.UndefinedSlot; 144 + throw Component.UndefinedSlot;
167 } 145 }
168 // we must also check if the signals dispose of their own implementation 146 // we must also check if the signals dispose of their own implementation
169 if (!source.hasOwnProperty('signals')) { 147 if (!source.hasOwnProperty('signals')) {
...@@ -203,7 +181,7 @@ ARCS.Component = { ...@@ -203,7 +181,7 @@ ARCS.Component = {
203 */ 181 */
204 invoke : function (destination, slt, value) { 182 invoke : function (destination, slt, value) {
205 if (destination[slt] === undefined) { 183 if (destination[slt] === undefined) {
206 - throw ARCS.Component.UndefinedSlot; 184 + throw Component.UndefinedSlot;
207 } 185 }
208 186
209 187
...@@ -222,714 +200,304 @@ ARCS.Component = { ...@@ -222,714 +200,304 @@ ARCS.Component = {
222 } 200 }
223 }; 201 };
224 202
203 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ Component: Component});
204 +
205 +
206 +/***/ }),
207 +/* 2 */
208 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
209 +
210 +__webpack_require__.r(__webpack_exports__);
211 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
212 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
213 +/* harmony export */ });
214 +/* harmony import */ var _component_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
215 +/* harmony import */ var _transitionnetwork_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
216 +/* harmony import */ var _eventlogicparser_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5);
217 +/******************************************************************************
218 + * Statemachine implementation
219 + * ***************************************************************************/
220 +
221 +
222 +
223 +
224 +
225 /** 225 /**
226 - * @class ARCS.Context 226 + * Describes a statemachine
227 - * @classdesc Class representing a context containing libraries and components 227 + * @param obj {object} an object describing a state machine. If obj is empty then the statemachine is empty
228 - * used by different parts of the framework. 228 + * @class
229 - * @param ctx {object} an object representing data for the context.
230 */ 229 */
231 -ARCS.Context = function( ctx ) { 230 +let Statemachine = new _component_js__WEBPACK_IMPORTED_MODULE_0__.default.create(function (obj) {
232 - var components = {}; 231 + // dynamic construction: properties are initial state that have properties
233 - var constants = {}; 232 + // that are tokens and value that are the final state
234 - var factories = {}; 233 + var initial = "", final = "", transitions = {}, currentState = "", self= this;
235 - var libraries = []; 234 + var astTokens = {}; // it keeps AST from event logic expressions
236 - //var depLibPromises=[]; 235 + var tokenEvents = {}; // it keeps promises for tokens.
237 - var self = this; 236 + var network = {};
238 - var loadLibraries;
239 - var loadDataFile;
240 - var promiseLibrary;
241 - var instanciateComponents;
242 -
243 237
244 - factories.StateMachine = ARCS.Statemachine;
245 238
246 - 239 + var addToken = function(t) {
247 - if (ctx !== undefined) { 240 + if ( self.slots.indexOf(t) < 0 ) {
248 - libraries = ctx.libraries; 241 + self.slots.push(t);
249 - 242 + self[t] = function( s ) {
250 - var p; 243 + return function() {
251 - for (p in ctx.components) { 244 + self.setToken(s);
252 - if (ctx.components.hasOwnProperty(p)) { 245 + };
253 - components[p] = ctx.components[p]; 246 + } (t);
254 - }
255 - }
256 -
257 - if (ctx.constants !== undefined) {
258 - for (p in ctx.constants) {
259 - if (ctx.constants.hasOwnProperty(p)) {
260 - constants[p] = ctx.constants[p];
261 - }
262 - }
263 } 247 }
264 - 248 + };
265 - } 249 +
266 - 250 + /* this function aims at preparing transition networks for a given state*/
267 - var loadDataFile =async function(fileName) { 251 + var setSheet = function(s) {
268 - var dataPromise ; 252 + // we build promise trees using ast
253 + var t;
269 254
270 - if (ARCS.isInNode()) { 255 + if (transitions.hasOwnProperty(s)) {
271 - return new Promise(function (resolve, reject) { 256 + tokenEvents = {};
272 - var dep = require(fileName); 257 + for (t in transitions[s]) {
273 - if (dep !== undefined) { 258 + if (transitions[s].hasOwnProperty(t)) {
274 - resolve(dep); 259 + network = _transitionnetwork_js__WEBPACK_IMPORTED_MODULE_1__.default.build(astTokens[t],tokenEvents).promise;
275 - } else { 260 + network.then(
276 - reject("[ARCS] File not found"); 261 + function() {
262 + var token;
263 + // clean up remaining promises
264 + for (token in tokenEvents) {
265 + if (tokenEvents.hasOwnProperty(token)) tokenEvents[token].abort();
266 + }
267 + // then activate next sheet
268 + setSheet(transitions[s][t]);
269 + }
270 + );
277 } 271 }
278 - }); 272 + }
279 - } else {
280 - var client = await fetch(fileName);
281 - return client.json();
282 } 273 }
283 - };
284 -
285 - var loadLibraries = function () {
286 - var i;
287 - // we will use different instances of require either the one of node
288 - // or the one from require.js
289 - ARCS.Context.currentContext = self;
290 274
291 - var res=[]; 275 + currentState = s;
292 - for(i=0; i < libraries.length; i++) { 276 + self.emit('requestSheet', currentState);
293 - res.push(self.loadLibrary(libraries[i])); 277 + if (currentState === final) {
278 + self.emit('requestTermination');
294 } 279 }
295 - return Promise.all(res);
296 - };
297 -
298 - var instanciateComponents = function() {
299 - var p, promises=[];
300 280
301 - for (p in components) {
302 - if (components.hasOwnProperty(p)) {
303 - if (factories[components[p].type] === undefined) {
304 - console.error("[ARCS] Factory " + components[p].type + " not found.");
305 - console.error("[ARCS] Context dump follows: ", libraries, components, constants);
306 - return ;
307 - }
308 - var factory = factories[components[p].type];
309 - //console.log("instanciating ", p);
310 - try {
311 - if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) {
312 - if (components[p].value !== undefined) {
313 - components[p].instance = new factory(components[p].value);
314 - }
315 - if (components[p].url !== undefined) {
316 - // we need currying here !
317 - var delayInstanciation = function(p,factory) {
318 - return function(obj) {
319 - console.log("instanciating from data file");
320 - components[p].instance = new factory(obj);
321 - return Promise.resolve();
322 - }
323 - };
324 - console.log("loading data file", components[p].url);
325 - promises.push(
326 - loadDataFile(components[p].url).then(delayInstanciation(p,factory))
327 - );
328 - }
329 - if (components[p].ref !== undefined) {
330 - if (constants[components[p].ref] !== undefined) {
331 - components[p].instance = new factory(constants[components[p].ref]);
332 - }
333 - }
334 - } else {
335 - components[p].instance = new factory();
336 - }
337 - } catch(e) { console.error("[ARCS] Component of type ", p, " not instanciated.", e);}
338 - }
339 - }
340 - return Promise.all(promises);
341 }; 281 };
342 282
343 /** 283 /**
344 - * loads a given library and, if necessary, launches a call back function 284 + * Sets the initial state of the statemachine
345 - * when the library is loaded. 285 + * @param string {string} name of the initial state
346 - * @param libName {string} name of the library to load
347 - * @param cbFunction {function} callback function to call when library is loaded
348 */ 286 */
349 - this.loadLibrary = function (libName, cbFunction) { 287 + this.setInitialState = function (string) {
350 - var libUrl = libName, libActualName = libName; 288 + initial = string;
351 - 289 + currentState = initial;
352 - ARCS.Context.currentContext = self;
353 - if (typeof libName !== "string") {
354 - libActualName = libName.name;
355 - libUrl = libName.url;
356 - }
357 -
358 - if (libraries.indexOf(libActualName) < 0) {
359 - libraries.push(libActualName);
360 - }
361 - // TODO promisify call to cbFunction
362 - return import(libUrl).then( function(module) {
363 - // TODO insert here component factories
364 - for (p in module.default) {
365 - if (module.default.hasOwnProperty(p)) {
366 - ARCS.Context.currentContext.setFactory(p,module.default[p]);
367 - }
368 - }
369 -
370 - if (cbFunction !== undefined) {
371 - cbFunction();
372 - }
373 - }).catch( function(msg) { console.error("[ARCS] Trouble loading '",libUrl,"' with reason -", msg) });
374 }; 290 };
375 -
376 /** 291 /**
377 - * @return the component list stored inside context 292 + * Sets the final state of the statemachine
378 - */ 293 + * @param string {string} name of the final state
379 - this.getComponentList = function () { 294 + */
380 - var list = Object.keys(components); 295 + this.setFinalState = function (string) { final = string; };
381 - var i; 296 + /**
297 + * Adds a transition to the state machine
298 + * @param start {string} name of the state at the beginning of the transition
299 + * @param token {string} name of the token triggering the transition
300 + * @param end {string} name of the state reached at the end of the transition
301 + */
302 + this.addTransition = function (start, token, end) {
303 + var re = /([A-Za-z_]\w*)/g;
304 + var t, tsd, ts, tsc;
305 + try {
382 306
383 - for (i = 0; i < list.length; i++) { 307 + var tsd = ARCS.EventLogicParser.parse(token);
384 - if ( ! components.hasOwnProperty(list[i])) { 308 + if (typeof tsd === "string") {
385 - list.splice(i--,1); 309 + addToken(tsd);
310 + } else {
311 + while( (t = re.exec(token)) !== null) {
312 + addToken(t[0]);
313 + }
386 } 314 }
387 - }
388 - return list;
389 - };
390 315
391 - this.getConstant = function(cName) { 316 + astTokens[token] = tsd;
392 - /*if (!constants.hasOwnProperty(cName)) { 317 +
393 - return undefined; 318 + if (transitions[start] === undefined) {
394 - }*/ 319 + transitions[start] = {};
395 - return constants[cName];
396 - };
397 -
398 -
399 - // to determine if really needed
400 - this.getComponentType = function(cName) {
401 - /*if (!components.hasOwnProperty(cName))
402 - return undefined;*/
403 - if (components[cName] === undefined) return undefined;
404 - return components[cName].type;
405 - };
406 -
407 - // to determine if really needed
408 - this.getComponentValue = function(cName) {
409 - /*if (!components.hasOwnProperty(cName))
410 - return undefined;*/
411 - if (components[cName] === undefined) return undefined;
412 - return components[cName].value;
413 - };
414 -
415 - // to determine if really needed
416 - this.getComponent = function (cName) {
417 - /*if (!components.hasOwnProperty(cName))
418 - return undefined;*/
419 - if (components[cName] === undefined) return undefined;
420 - return components[cName].instance;
421 - };
422 -
423 -
424 - // to determine if really needed
425 - this.getComponentName = function (cmp) {
426 - var i, keys;
427 - keys = components.getComponentList();
428 -
429 - for(i = 0; i < keys.length; i++) {
430 - if (components[keys[i]].instance === cmp) {
431 - return keys[i];
432 } 320 }
433 - } 321 + transitions[start][token] = end;
434 - 322 + } catch (e) { }
435 - return undefined;
436 - };
437 -
438 -
439 - this.setFactory = function(key, factory ) {
440 - factories[key] = factory;
441 }; 323 };
442 - 324 + /**
443 - this.toJSON = function () { 325 + * Gives a token to the statemachine. According to its list of transitions
444 - var res = {}, p; 326 + * and the current state, it may trigger a transition
445 - 327 + * @param token {string} name of the token
446 - for (p in components) { 328 + */
447 - if (components.hasOwnProperty(p)) { 329 + this.setToken = function (token) {
448 - res[p] = { type: components[p].type, value: components[p].value }; 330 + if (tokenEvents.hasOwnProperty(token)) {
449 - } 331 + tokenEvents[token].accept();
450 } 332 }
451 - return res;
452 - };
453 -
454 -
455 - // functions used with editor
456 - this.setComponentValue = function (cName, cValue) {
457 - components[cName].value = cValue; // to modifiy
458 }; 333 };
334 + /**
335 + * Sets transitions from a list of transitions
336 + * @param obj {object[]} list of transitions
337 + */
338 + this.setTransitions = function (obj) {
339 + // this function is no longuer a simple affectation
340 + // transitions = obj;
341 + var p, t, i;
342 + for (p in obj) {
343 + if (obj.hasOwnProperty(p)) {
344 + for (t in obj[p]) {
345 + if (obj[p].hasOwnProperty(t)) {
346 + this.addTransition(p, t, obj[p][t]);
347 + }
348 + }
349 + }
350 + }
459 351
460 - this.addComponent = function (cName, cType, cValue) {
461 - var component;
462 - components[cName] = {};
463 - components[cName].type = cType;
464 - components[cName].value = cValue;
465 352
466 - var factory = factories[cType]; 353 + // we will temporay dump properties in order to understand how the statemachine is built
467 - if (factory !== undefined) { 354 + /*
468 - component = new factory(cValue); 355 + for (p in transitions) {
469 - } 356 + if (transitions.hasOwnProperty(p)) {
470 - components[cName].instance = component; 357 + for (t in transitions[p]) {
358 + if (transitions[p].hasOwnProperty(t)) {
359 + console.log("\t" + p + "\t----\t" + t + "\t--->\t" + transitions[p][t]);
360 + }
361 + }
362 + }
363 + }*/
471 }; 364 };
472 - 365 + /**
473 - this.removeComponent = function (cName) { 366 + * Initialize and starts the statemachine, setting its current state to
474 - delete components[cName]; 367 + * the initial state (by default, it is the departure of the first transition
368 + */
369 + this.start = function () {
370 + console.log("statemachine", this, initial,obj);
371 + setSheet(initial);
475 }; 372 };
476 373
477 -
478 - // see if it is needed
479 - this.getFactory = function (fName) {
480 - return factories[fName];
481 - };
482 374
483 - // see if it is needed 375 + // INIT CODE
484 - this.getFactoryList = function() { 376 + if (obj !== undefined) {
485 - return Object.keys(factories); 377 + initial = obj.initial;
486 - }; 378 + final = obj.final;
379 + this.setTransitions(obj.transitions);
380 + currentState = "";
381 + }
487 382
488 - // this should return a promise ! 383 +},
489 - this.instanciate = function () { 384 +['setToken'],
490 - //! TODO 385 +['requestSheet', 'requestTermination']
491 - return loadLibraries().then(instanciateComponents) 386 +);
492 - .catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); }); 387 +
388 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ StateMachine: StateMachine});
389 +
390 +
391 +/***/ }),
392 +/* 3 */
393 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
394 +
395 +__webpack_require__.r(__webpack_exports__);
396 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
397 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
398 +/* harmony export */ });
399 +/* harmony import */ var _tokenevent_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
400 +/* the aim of the transition network is to build a network of promises */
401 +
402 +
403 +
404 +let TransitionNetwork = function() {
405 + // object storing token events (that is to say references to promises)
406 + this.promise = {};
493 407
408 + this.and = function(tn) {
409 + this.promise = Promise.all([this.promise, tn.promise]);
410 + return this;
494 }; 411 };
495 412
413 + this.or = function(tn) {
414 + this.promise = Promise.race([this.promise, tn.promise]);
415 + return this;
416 + };
417 +
418 +};
419 +
420 +TransitionNetwork.build = function(tree, tokenEvents) {
421 + var res;
422 + var tmpTN;
423 + var rightTN;
424 +
425 + if (typeof tree === "string") {
426 + // here we have a terminal string i.e. a token event
427 + var tokenEvent;
428 + if (tokenEvents.hasOwnProperty(tree)) {
429 + tokenEvent = tokenEvents[tree];
430 + } else {
431 + tokenEvents[tree] = tokenEvent = new _tokenevent_js__WEBPACK_IMPORTED_MODULE_0__.default();
432 + }
433 + var tn = new TransitionNetwork();
434 + tn.promise = tokenEvent.promise;
435 + return tn;
436 + }
496 437
497 - var chainPrototype = function (obj, proto) { 438 + res = TransitionNetwork.build(tree[0],tokenEvents);
498 - // this stunt seems better than using 439 + var i;
499 - // Object.setPrototypeOf or using [object].__proto__ 440 + for (i=1; i < tree.length; i++) {
500 - // due to javascript engine optimizations 441 + if (tree[i].hasOwnProperty('and')) {
501 - var newObj = Object.create(proto); 442 + rightTN = TransitionNetwork.build(tree[i]['and'], tokenEvents);
502 - var p ; 443 + tmpTN = res.and(rightTN);
503 - 444 + } else {
504 - for (p in obj) { 445 + if (tree[i].hasOwnProperty('or')) {
505 - if (obj.hasOwnProperty(p)) { 446 + rightTN = TransitionNetwork.build(tree[i]['or'], tokenEvents);
506 - newObj[p] = obj[p]; 447 + tmpTN = res.or(rightTN);
448 + } else {
449 + console.warn('[ARCS] Illegal tree');
507 } 450 }
508 } 451 }
509 - return newObj; 452 + res = tmpTN;
510 - }; 453 + }
511 -
512 - this.chain = function (cmp,cst,fct) {
513 - // cmp and cst are the children context elements
514 - // we need to chain contexts properly.
515 - return [ chainPrototype(cmp, components),
516 - chainPrototype(cst, constants),
517 - chainPrototype(fct, factories)
518 - ];
519 - };
520 -
521 -
522 - this.setParent = function (ctx) {
523 - // chaining factories is also important if contexts are repeating
524 - // the same things
525 - if (ctx === undefined) return;
526 - var v = ctx.chain(components, constants, factories);
527 - components = v[0];
528 - constants = v[1];
529 - factories = v[2];
530 - };
531 454
455 + return res;
532 }; 456 };
533 457
534 - 458 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({TransitionNetwork: TransitionNetwork});
535 -/** pseudo-singleton to current context being used */
536 -ARCS.Context.currentContext = null;
537 459
538 460
461 +/***/ }),
462 +/* 4 */
463 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
539 464
465 +__webpack_require__.r(__webpack_exports__);
466 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
467 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
468 +/* harmony export */ });
469 +// this class creates a promise that can be deferred as long as necessary.
470 +// calls to accept or reject will solve the promise.
540 471
541 -/****************************************************************************** 472 +let TokenEvent = function() {
542 - * Invocation implementation 473 + var refResolve;
543 - * ***************************************************************************/ 474 + var refReject;
544 -/**
545 - * Defines an invocation
546 - * @param destination {object} component on which to perform invocation
547 - * @param slot {string} name of the slot
548 - * @param value {mixed} value passed to the invoked slot
549 - * @constructor
550 - */
551 -ARCS.Invocation = function (destination, slot, value) {
552 - this.getDestination = function () {
553 - return destination;
554 - };
555 475
556 - this.getSlot = function () { 476 + this.promise = new Promise(function(resolve, reject) {
557 - return slot; 477 + refResolve = resolve;
558 - }; 478 + refReject = reject;
479 + });
559 480
560 - this.getValue = function () { 481 + this.accept = function() {
561 - return value; 482 + refResolve();
562 }; 483 };
563 484
564 - this.invoke = function () { 485 + this.abort = function() {
565 - var func = destination[slot]; 486 + refReject();
566 - if (func === undefined) { 487 + };
567 - console.error("Undefined slot %s of component %s", slot, destination);
568 - return;
569 - }
570 - func.apply(destination, value);
571 - };
572 -};
573 -/**
574 - * Helper function that casts an invocation from a description
575 - * @param obj {object} a raw description of the invocation
576 - * @param context {object} the context in which this invocation takes place.
577 - * @return an invocation
578 - */
579 -ARCS.Invocation.cast = function (obj, context) {
580 - if (obj.value !== undefined) {
581 - var component = context.getComponent(obj.destination);
582 - if (component === undefined) {
583 - console.error("[ARCS] Destination ",obj.destination, " is undefined");
584 - }
585 -
586 - return new ARCS.Invocation(component, obj.slot, obj.value);
587 - }
588 -
589 - // this one looks odd, seems there is a failure in the logic.
590 - if (obj.ref !== undefined) {
591 - return new ARCS.Invocation(context.getComponent(obj.destination), obj.slot, context.getConstant(obj.ref));
592 - }
593 -};
594 -
595 -/*ARCS.Invocation.revert = function(obj, context) {
596 - return {
597 - destination: context
598 -
599 - };
600 -
601 -};*/
602 -
603 -
604 -ARCS.Invocation.PRE_CONNECTION = 0;
605 -ARCS.Invocation.POST_CONNECTION = 1;
606 -ARCS.Invocation.CLEAN_UP = 2;
607 -/******************************************************************************
608 - * Connection implementation
609 - * ***************************************************************************/
610 -/**
611 - * Defines a connection between two components
612 - * @param source {object} component at the source
613 - * @param signal {string} name of the signal emitting data
614 - * @param destination {object} component at the destination
615 - * @param slot {string} name of the signal receiving data
616 - * @class
617 - */
618 -ARCS.Connection = function (source, signal, destination, slot) {
619 - /**
620 - * Connects two components as described in this object
621 - * @function ARCS.Connection#connect
622 - */
623 - this.connect = function () {
624 - try {
625 - ARCS.Component.connect(source, signal, destination, slot);
626 - } catch(e) { console.log(e, source, signal, destination, slot); }
627 - };
628 - /**
629 - * Disconnects a signal/slot connection between the two components
630 - * described in this object.
631 - */
632 - this.disconnect = function () {
633 - ARCS.Component.disconnect(source, signal, destination, slot);
634 - };
635 -
636 - this.getSource = function() {
637 - return source;
638 - };
639 -
640 - this.getDestination = function () {
641 - return destination;
642 - };
643 -
644 - this.getSlot = function () {
645 - return slot;
646 - };
647 -
648 - this.getSignal = function () {
649 - return signal;
650 - };
651 -};
652 -/**
653 - * Helper function that casts a connection from a description
654 - * @param obj {object} a raw description of the connection
655 - * @param context {object} the context in which this connection takes place.
656 - * @return a connection
657 - */
658 -ARCS.Connection.cast = function (obj, context) {
659 - return new ARCS.Connection(context.getComponent(obj.source)/*[obj.source].instance*/, obj.signal,
660 - context.getComponent(obj.destination)/*[obj.destination].instance*/, obj.slot);
661 }; 488 };
662 489
663 -/****************************************************************************** 490 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({TokenEvent: TokenEvent});
664 - * Sheet implementation
665 - * ***************************************************************************/
666 -/**
667 - * Constructs a sheet
668 - * @param context {object} a context object
669 - * @class
670 - * @classdesc A Sheet is an operationnal configuration in an application. It
671 - * contains many things: multiple sets of {@link ARCS.Invocation}
672 - * performed at different times
673 - * and a set of {@link ARCS.Connection}. Sheets have two high level operations:
674 - * activation and deactivation.
675 - */
676 -ARCS.Sheet = function (ctx /*context*/) {
677 - var context = new ARCS.Context();
678 - var preconnections = [], postconnections = [], cleanups = [], connections = [],
679 - invokePreconnections, invokePostconnections, invokeCleanups,
680 - connect, disconnect, getComponentName,
681 - preCount = 0, postCount = 0, cleanCount = 0, connCount = 0;
682 -
683 - invokePreconnections = function () {
684 - var i;
685 - for (i = 0; i < preconnections.length; i++) {
686 - preconnections[i].invoke();
687 - }
688 - };
689 - invokePostconnections = function () {
690 - var i;
691 - for (i = 0; i < postconnections.length; i++) {
692 - postconnections[i].invoke();
693 - }
694 - };
695 - invokeCleanups = function () {
696 - var i;
697 - for (i = 0; i < cleanups.length; i++) {
698 - cleanups[i].invoke();
699 - }
700 - };
701 - connect = function () {
702 - var i;
703 - for (i = 0; i < connections.length; i++) {
704 - connections[i].connect();
705 - }
706 - };
707 - disconnect = function () {
708 - var i;
709 - for (i = 0; i < connections.length; i++) {
710 - connections[i].disconnect();
711 - }
712 - };
713 -
714 - this.setContext = function (ctx) {
715 - context = ctx;
716 - };
717 - /**
718 - * Activates this sheet. Pre-connection invocations are peformed, then
719 - * connections are established and post-connection invocations are finally
720 - * performed.
721 - */
722 - this.activate = function () {
723 - context.instanciate().then(function() {
724 - invokePreconnections();
725 - connect();
726 - invokePostconnections();
727 - });
728 - };
729 - /**
730 - * Deactivates this sheet. Connections are removed and then cleanup invocations
731 - * are performed.
732 - */
733 - this.deactivate = function () {
734 - disconnect();
735 - invokeCleanups();
736 - };
737 -
738 - this.addPreConnection = function (obj) {
739 - var pre = ARCS.Invocation.cast(obj, context);
740 - pre.id = preCount++;
741 - preconnections.push(pre);
742 - return pre.id;
743 - };
744 -
745 - this.addPostConnection = function (obj) {
746 - var post = ARCS.Invocation.cast(obj, context);
747 - post.id = postCount++;
748 - postconnections.push(post);
749 - return post.id;
750 - };
751 -
752 491
753 - this.addCleanup = function (obj) {
754 - var cleanup = ARCS.Invocation.cast(obj, context);
755 - cleanup.id = cleanCount++;
756 - cleanups.push(cleanup);
757 - return cleanup.id;
758 - };
759 -
760 - this.addConnection = function (obj) {
761 - var connection = ARCS.Connection.cast(obj, context);
762 - connection.id = connCount++;
763 - connections.push(connection);
764 - return connection.id;
765 - };
766 492
767 - 493 +/***/ }),
768 - var removeItem = function(id, tab) { 494 +/* 5 */
769 - var i = tab.length; 495 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
770 -
771 - while ( i-- && tab[i].id !== id );
772 -
773 - if (i >= 0) {
774 - tab.splice(i,1);
775 - } else {
776 - console.warn("Could not remove data with id", id);
777 - }
778 - };
779 -
780 - this.removePreConnection = function (id) {
781 - removeItem(id, preconnections);
782 - };
783 -
784 - this.removePostConnection = function (id) {
785 - removeItem(id, postconnections);
786 - };
787 -
788 - this.removeCleanup = function (id) {
789 - removeItem(id, cleanups);
790 - };
791 -
792 - var changeItem = function(id, value, tab) {
793 - var i = tab.length;
794 - while ( i-- && tab[i].id !== id );
795 - if (i >= 0) {
796 - tab[i].value = value;
797 - }
798 - };
799 -
800 - this.changePreConnection = function (id, value) {
801 - changeItem(id, value, preconnections);
802 - };
803 -
804 - this.changePostConnection = function (id, value) {
805 - changeItem(id, value, postconnections);
806 - };
807 -
808 - this.changeCleanup = function (id, value) {
809 - changeItem(id, value, cleanups);
810 - };
811 -
812 - this.removeConnection = function (id) {
813 - removeItem(id, connections);
814 - };
815 -
816 -
817 - var swapItems = function (id1, id2, tab) {
818 - var item;
819 -
820 - var i = tab.length, j = tab.length;
821 -
822 - while( i-- && tab[i].id !== id1 ) ;
823 - while( j-- && tab[j].id !== id2 ) ;
824 -
825 - if (i >= 0 && j >= 0) {
826 - item = tab[i];
827 - tab[i] = tab[j];
828 - tab[j] = item;
829 - tab[i].id = id1;
830 - tab[j].id = id2;
831 - }
832 - };
833 -
834 - this.swapConnections = function (id1, id2) {
835 - swapItems(id1, id2, connections);
836 - };
837 -
838 - this.swapCleanups = function (id1, id2) {
839 - swapItems(id1, id2, cleanups);
840 - };
841 -
842 - this.swapPreConnections = function (id1, id2) {
843 - swapItems(id1, id2, preconnections);
844 - };
845 -
846 - this.swapPostConnections = function (id1, id2) {
847 - swapItems(id1, id2, postconnections);
848 - };
849 -
850 -
851 - var cacheConnectionsInvocations = function(object) {
852 - var i = 0, castInvocation = ARCS.Invocation.cast, castConnection = ARCS.Connection.cast;
853 - for (i = 0; i < object.preconnections.length; i++) {
854 - preconnections.push(castInvocation(object.preconnections[i], context));
855 - }
856 - for (i = 0; i < object.postconnections.length; i++) {
857 - postconnections.push(castInvocation(object.postconnections[i], context));
858 - }
859 - for (i = 0; i < object.cleanups.length; i++) {
860 - cleanups.push(castInvocation(object.cleanups[i], context));
861 - }
862 - for (i = 0; i < object.connections.length; i++) {
863 - connections.push(castConnection(object.connections[i], context));
864 - }
865 - };
866 -
867 - /**
868 - * Imports a structure object describing the content of a sheet.
869 - * @param object {object} structured object describing sheet's content.
870 - */
871 - this.import = function (object) {
872 - if (object.hasOwnProperty("context")) {
873 - context = new ARCS.Context(object.context);
874 - context.setParent(ctx);
875 - }
876 -
877 - // the caching system below should wait for the context to be proper initialized
878 - // todo: there may be a flow here if the instanciation is too long.
879 - context.instanciate().then( function() {
880 - cacheConnectionsInvocations(object);
881 - });
882 - };
883 -
884 - var revertInvocation = function (obj) {
885 - return {
886 - destination: context.getComponentName(obj.getDestination()),
887 - slot: obj.getSlot(),
888 - value: obj.getValue()
889 - };
890 - };
891 -
892 - var revertConnection = function (obj) {
893 - return {
894 - source: context.getComponentName(obj.getSource()),
895 - signal: obj.getSignal(),
896 - destination: context.getComponentName(obj.getDestination()),
897 - slot: obj.getSlot()
898 - };
899 - };
900 -
901 - this.toJSON = function () {
902 - var preconns = [];
903 - var postconns = [];
904 - var conns = [];
905 - var cleans = [];
906 -
907 - var i;
908 - for (i = 0; i < connections.length; i++) {
909 - conns.push(revertConnection(connections[i]))
910 - }
911 - for (i = 0; i < preconnections.length; i++) {
912 - preconns.push(revertInvocation(preconnections[i]))
913 - }
914 - for (i = 0; i < postconnections.length; i++) {
915 - postconns.push(revertInvocation(postconnections[i]))
916 - }
917 - for (i = 0; i < cleanups.length; i++) {
918 - cleans.push(revertInvocation(cleanups[i]))
919 - }
920 -
921 - return {
922 - preconnections : preconns,
923 - postconnections : postconns,
924 - connections: conns,
925 - cleanups: cleans
926 - };
927 - };
928 -
929 - //console.log("setting parent");
930 - context.setParent(ctx);
931 -};
932 496
497 +__webpack_require__.r(__webpack_exports__);
498 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
499 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
500 +/* harmony export */ });
933 /**************************************************************************** 501 /****************************************************************************
934 * PEG.js grammar used to generate Parser 502 * PEG.js grammar used to generate Parser
935 **************************************************************************** 503 ****************************************************************************
...@@ -968,7 +536,7 @@ WS = [ \r\n\t]* ...@@ -968,7 +536,7 @@ WS = [ \r\n\t]*
968 ******************************************************************************/ 536 ******************************************************************************/
969 537
970 538
971 -ARCS.EventLogicParser = (function() { 539 +let EventLogicParser = (function() {
972 /* 540 /*
973 * Generated by PEG.js 0.8.0. 541 * Generated by PEG.js 0.8.0.
974 * 542 *
...@@ -1593,253 +1161,836 @@ ARCS.EventLogicParser = (function() { ...@@ -1593,253 +1161,836 @@ ARCS.EventLogicParser = (function() {
1593 parse: parse 1161 parse: parse
1594 }; 1162 };
1595 })(); 1163 })();
1164 +
1165 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ EventLogicParser: EventLogicParser});
1596 1166
1597 -// this class creates a promise that can be deferred as long as necessary.
1598 -// calls to accept or reject will solve the promise.
1599 1167
1600 -ARCS.TokenEvent = function() { 1168 +/***/ }),
1601 - var refResolve; 1169 +/* 6 */
1602 - var refReject; 1170 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1171 +
1172 +__webpack_require__.r(__webpack_exports__);
1173 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
1174 +/* harmony export */ "default": () => (/* binding */ isInNode)
1175 +/* harmony export */ });
1176 +// ARCS.js : 27/6/2014 16:00
1177 +// handling dependencies
1178 +
1179 +
1180 +//"use strict";
1181 +
1182 +
1183 +
1184 +
1185 +/**
1186 + * Main source: describes all the methods needed by the ARCS engine
1187 + * @file
1188 + */
1189 +
1190 +
1191 +/******************************************************************************
1192 + * Helper functions to determine environment
1193 + * ***************************************************************************/
1194 +
1195 +/**
1196 + * @return {boolean} true if ARCS is run in a node.js environment
1197 + */
1198 +
1199 +function isInNode() {
1200 + return (typeof process !== 'undefined') &&
1201 + (process.release.name.search(/node|io.js/) !== -1);
1603 1202
1604 - this.promise = new Promise(function(resolve, reject) { 1203 + // return (typeof require === 'function' && require.resolve);
1605 - refResolve = resolve; 1204 +};
1606 - refReject = reject; 1205 +
1607 - }); 1206 +
1207 +
1208 +/***/ }),
1209 +/* 7 */
1210 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1211 +
1212 +__webpack_require__.r(__webpack_exports__);
1213 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
1214 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
1215 +/* harmony export */ });
1216 +/* harmony import */ var _statemachine_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
1217 +/* harmony import */ var _arcs_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6);
1218 +
1219 +
1220 +
1221 +/**
1222 + * @class ARCS.Context
1223 + * @classdesc Class representing a context containing libraries and components
1224 + * used by different parts of the framework.
1225 + * @param ctx {object} an object representing data for the context.
1226 + */
1227 +let Context = function( ctx ) {
1228 + var components = {};
1229 + var constants = {};
1230 + var factories = {};
1231 + var libraries = [];
1232 + //var depLibPromises=[];
1233 + var self = this;
1234 + var loadLibraries;
1235 + var loadDataFile;
1236 + var promiseLibrary;
1237 + var instanciateComponents;
1608 1238
1609 - this.accept = function() { 1239 +
1610 - refResolve(); 1240 + factories.StateMachine = Statemachine;
1241 +
1242 +
1243 + if (ctx !== undefined) {
1244 + libraries = ctx.libraries;
1245 +
1246 + var p;
1247 + for (p in ctx.components) {
1248 + if (ctx.components.hasOwnProperty(p)) {
1249 + components[p] = ctx.components[p];
1250 + }
1251 + }
1252 +
1253 + if (ctx.constants !== undefined) {
1254 + for (p in ctx.constants) {
1255 + if (ctx.constants.hasOwnProperty(p)) {
1256 + constants[p] = ctx.constants[p];
1257 + }
1258 + }
1259 + }
1260 +
1261 + }
1262 +
1263 + var loadDataFile =async function(fileName) {
1264 + var dataPromise ;
1265 +
1266 + if ((0,_arcs_js__WEBPACK_IMPORTED_MODULE_1__.default)()) {
1267 + return new Promise(function (resolve, reject) {
1268 + var dep = require(/* webpackIgnore: true */fileName);
1269 + if (dep !== undefined) {
1270 + resolve(dep);
1271 + } else {
1272 + reject("[ARCS] File not found");
1273 + }
1274 + });
1275 + } else {
1276 + var client = await fetch(fileName);
1277 + return client.json();
1278 + }
1279 + };
1280 +
1281 + var loadLibraries = function () {
1282 + var i;
1283 + // we will use different instances of require either the one of node
1284 + // or the one from require.js
1285 + Context.currentContext = self;
1286 +
1287 + var res=[];
1288 + for(i=0; i < libraries.length; i++) {
1289 + res.push(self.loadLibrary(libraries[i]));
1290 + }
1291 + return Promise.all(res);
1292 + };
1293 +
1294 + var instanciateComponents = function() {
1295 + var p, promises=[];
1296 +
1297 + for (p in components) {
1298 + if (components.hasOwnProperty(p)) {
1299 + if (factories[components[p].type] === undefined) {
1300 + console.error("[ARCS] Factory " + components[p].type + " not found.");
1301 + console.error("[ARCS] Context dump follows: ", libraries, components, constants);
1302 + return ;
1303 + }
1304 + var factory = factories[components[p].type];
1305 + //console.log("instanciating ", p);
1306 + try {
1307 + if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) {
1308 + if (components[p].value !== undefined) {
1309 + components[p].instance = new factory(components[p].value);
1310 + }
1311 + if (components[p].url !== undefined) {
1312 + // we need currying here !
1313 + var delayInstanciation = function(p,factory) {
1314 + return function(obj) {
1315 + console.log("instanciating from data file");
1316 + components[p].instance = new factory(obj);
1317 + return Promise.resolve();
1318 + }
1319 + };
1320 + console.log("loading data file", components[p].url);
1321 + promises.push(
1322 + loadDataFile(components[p].url).then(delayInstanciation(p,factory))
1323 + );
1324 + }
1325 + if (components[p].ref !== undefined) {
1326 + if (constants[components[p].ref] !== undefined) {
1327 + components[p].instance = new factory(constants[components[p].ref]);
1328 + }
1329 + }
1330 + } else {
1331 + components[p].instance = new factory();
1332 + }
1333 + } catch(e) { console.error("[ARCS] Component of type ", p, " not instanciated.", e);}
1334 + }
1335 + }
1336 + return Promise.all(promises);
1337 + };
1338 +
1339 + /**
1340 + * loads a given library and, if necessary, launches a call back function
1341 + * when the library is loaded.
1342 + * @param libName {string} name of the library to load
1343 + * @param cbFunction {function} callback function to call when library is loaded
1344 + */
1345 + this.loadLibrary = function (libName, cbFunction) {
1346 + var libUrl = libName, libActualName = libName;
1347 +
1348 + Context.currentContext = self;
1349 + if (typeof libName !== "string") {
1350 + libActualName = libName.name;
1351 + libUrl = libName.url;
1352 + }
1353 +
1354 + if (libraries.indexOf(libActualName) < 0) {
1355 + libraries.push(libActualName);
1356 + }
1357 + // TODO promisify call to cbFunction
1358 + return import(/* webpackIgnore: true */libUrl).then( function(module) {
1359 + // TODO insert here component factories
1360 + for (p in module.default) {
1361 + if (module.default.hasOwnProperty(p)) {
1362 + Context.currentContext.setFactory(p,module.default[p]);
1363 + }
1364 + }
1365 +
1366 + if (cbFunction !== undefined) {
1367 + cbFunction();
1368 + }
1369 + }).catch( function(msg) { console.error("[ARCS] Trouble loading '",libUrl,"' with reason -", msg) });
1370 + };
1371 +
1372 + /**
1373 + * @return the component list stored inside context
1374 + */
1375 + this.getComponentList = function () {
1376 + var list = Object.keys(components);
1377 + var i;
1378 +
1379 + for (i = 0; i < list.length; i++) {
1380 + if ( ! components.hasOwnProperty(list[i])) {
1381 + list.splice(i--,1);
1382 + }
1383 + }
1384 + return list;
1385 + };
1386 +
1387 + this.getConstant = function(cName) {
1388 + /*if (!constants.hasOwnProperty(cName)) {
1389 + return undefined;
1390 + }*/
1391 + return constants[cName];
1392 + };
1393 +
1394 +
1395 + // to determine if really needed
1396 + this.getComponentType = function(cName) {
1397 + /*if (!components.hasOwnProperty(cName))
1398 + return undefined;*/
1399 + if (components[cName] === undefined) return undefined;
1400 + return components[cName].type;
1401 + };
1402 +
1403 + // to determine if really needed
1404 + this.getComponentValue = function(cName) {
1405 + /*if (!components.hasOwnProperty(cName))
1406 + return undefined;*/
1407 + if (components[cName] === undefined) return undefined;
1408 + return components[cName].value;
1409 + };
1410 +
1411 + // to determine if really needed
1412 + this.getComponent = function (cName) {
1413 + /*if (!components.hasOwnProperty(cName))
1414 + return undefined;*/
1415 + if (components[cName] === undefined) return undefined;
1416 + return components[cName].instance;
1417 + };
1418 +
1419 +
1420 + // to determine if really needed
1421 + this.getComponentName = function (cmp) {
1422 + var i, keys;
1423 + keys = components.getComponentList();
1424 +
1425 + for(i = 0; i < keys.length; i++) {
1426 + if (components[keys[i]].instance === cmp) {
1427 + return keys[i];
1428 + }
1429 + }
1430 +
1431 + return undefined;
1432 + };
1433 +
1434 +
1435 + this.setFactory = function(key, factory ) {
1436 + factories[key] = factory;
1437 + };
1438 +
1439 + this.toJSON = function () {
1440 + var res = {}, p;
1441 +
1442 + for (p in components) {
1443 + if (components.hasOwnProperty(p)) {
1444 + res[p] = { type: components[p].type, value: components[p].value };
1445 + }
1446 + }
1447 + return res;
1448 + };
1449 +
1450 +
1451 + // functions used with editor
1452 + this.setComponentValue = function (cName, cValue) {
1453 + components[cName].value = cValue; // to modifiy
1454 + };
1455 +
1456 + this.addComponent = function (cName, cType, cValue) {
1457 + var component;
1458 + components[cName] = {};
1459 + components[cName].type = cType;
1460 + components[cName].value = cValue;
1461 +
1462 + var factory = factories[cType];
1463 + if (factory !== undefined) {
1464 + component = new factory(cValue);
1465 + }
1466 + components[cName].instance = component;
1467 + };
1468 +
1469 + this.removeComponent = function (cName) {
1470 + delete components[cName];
1471 + };
1472 +
1473 +
1474 + // see if it is needed
1475 + this.getFactory = function (fName) {
1476 + return factories[fName];
1477 + };
1478 +
1479 + // see if it is needed
1480 + this.getFactoryList = function() {
1481 + return Object.keys(factories);
1482 + };
1483 +
1484 + // this should return a promise !
1485 + this.instanciate = function () {
1486 + //! TODO
1487 + return loadLibraries().then(instanciateComponents)
1488 + .catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); });
1489 +
1490 + };
1491 +
1492 +
1493 + var chainPrototype = function (obj, proto) {
1494 + // this stunt seems better than using
1495 + // Object.setPrototypeOf or using [object].__proto__
1496 + // due to javascript engine optimizations
1497 + var newObj = Object.create(proto);
1498 + var p ;
1499 +
1500 + for (p in obj) {
1501 + if (obj.hasOwnProperty(p)) {
1502 + newObj[p] = obj[p];
1503 + }
1504 + }
1505 + return newObj;
1506 + };
1507 +
1508 + this.chain = function (cmp,cst,fct) {
1509 + // cmp and cst are the children context elements
1510 + // we need to chain contexts properly.
1511 + return [ chainPrototype(cmp, components),
1512 + chainPrototype(cst, constants),
1513 + chainPrototype(fct, factories)
1514 + ];
1515 + };
1516 +
1517 +
1518 + this.setParent = function (ctx) {
1519 + // chaining factories is also important if contexts are repeating
1520 + // the same things
1521 + if (ctx === undefined) return;
1522 + var v = ctx.chain(components, constants, factories);
1523 + components = v[0];
1524 + constants = v[1];
1525 + factories = v[2];
1526 + };
1527 +
1528 +};
1529 +
1530 +
1531 +/** pseudo-singleton to current context being used */
1532 +Context.currentContext = null;
1533 +
1534 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({Context: Context});
1535 +
1536 +
1537 +
1538 +/***/ }),
1539 +/* 8 */
1540 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1541 +
1542 +__webpack_require__.r(__webpack_exports__);
1543 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
1544 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
1545 +/* harmony export */ });
1546 +/******************************************************************************
1547 + * Invocation implementation
1548 + * ***************************************************************************/
1549 +/**
1550 + * Defines an invocation
1551 + * @param destination {object} component on which to perform invocation
1552 + * @param slot {string} name of the slot
1553 + * @param value {mixed} value passed to the invoked slot
1554 + * @constructor
1555 + */
1556 +
1557 +let Invocation = function (destination, slot, value) {
1558 + this.getDestination = function () {
1559 + return destination;
1560 + };
1561 +
1562 + this.getSlot = function () {
1563 + return slot;
1564 + };
1565 +
1566 + this.getValue = function () {
1567 + return value;
1568 + };
1569 +
1570 + this.invoke = function () {
1571 + var func = destination[slot];
1572 + if (func === undefined) {
1573 + console.error("Undefined slot %s of component %s", slot, destination);
1574 + return;
1575 + }
1576 + func.apply(destination, value);
1611 }; 1577 };
1578 +};
1579 +/**
1580 + * Helper function that casts an invocation from a description
1581 + * @param obj {object} a raw description of the invocation
1582 + * @param context {object} the context in which this invocation takes place.
1583 + * @return an invocation
1584 + */
1585 +Invocation.cast = function (obj, context) {
1586 + if (obj.value !== undefined) {
1587 + var component = context.getComponent(obj.destination);
1588 + if (component === undefined) {
1589 + console.error("[ARCS] Destination ",obj.destination, " is undefined");
1590 + }
1591 +
1592 + return new Invocation(component, obj.slot, obj.value);
1593 + }
1612 1594
1613 - this.abort = function() { 1595 + // this one looks odd, seems there is a failure in the logic.
1614 - refReject(); 1596 + if (obj.ref !== undefined) {
1615 - }; 1597 + return new Invocation(context.getComponent(obj.destination), obj.slot, context.getConstant(obj.ref));
1598 + }
1616 }; 1599 };
1617 -/* the aim of the transition network is to build a network of promises */
1618 1600
1619 -ARCS.TransitionNetwork = function() { 1601 +/*ARCS.Invocation.revert = function(obj, context) {
1620 - // object storing token events (that is to say references to promises) 1602 + return {
1621 - this.promise = {}; 1603 + destination: context
1622 1604
1623 - this.and = function(tn) {
1624 - this.promise = Promise.all([this.promise, tn.promise]);
1625 - return this;
1626 }; 1605 };
1627 1606
1628 - this.or = function(tn) { 1607 +};*/
1629 - this.promise = Promise.race([this.promise, tn.promise]);
1630 - return this;
1631 - };
1632 1608
1633 -};
1634 1609
1635 -ARCS.TransitionNetwork.build = function(tree, tokenEvents) { 1610 +Invocation.PRE_CONNECTION = 0;
1636 - var res; 1611 +Invocation.POST_CONNECTION = 1;
1637 - var tmpTN; 1612 +Invocation.CLEAN_UP = 2;
1638 - var rightTN;
1639 1613
1640 - if (typeof tree === "string") { 1614 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ Invocation: Invocation});
1641 - // here we have a terminal string i.e. a token event 1615 +
1642 - var tokenEvent; 1616 +
1643 - if (tokenEvents.hasOwnProperty(tree)) { 1617 +/***/ }),
1644 - tokenEvent = tokenEvents[tree]; 1618 +/* 9 */
1645 - } else { 1619 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1646 - tokenEvents[tree] = tokenEvent = new ARCS.TokenEvent(); 1620 +
1647 - } 1621 +__webpack_require__.r(__webpack_exports__);
1648 - var tn = new ARCS.TransitionNetwork(); 1622 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
1649 - tn.promise = tokenEvent.promise; 1623 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
1650 - return tn; 1624 +/* harmony export */ });
1651 - } 1625 +/* harmony import */ var _component_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1626 +/******************************************************************************
1627 + * Connection implementation
1628 + * ***************************************************************************/
1629 +
1630 +
1631 +/**
1632 + * Defines a connection between two components
1633 + * @param source {object} component at the source
1634 + * @param signal {string} name of the signal emitting data
1635 + * @param destination {object} component at the destination
1636 + * @param slot {string} name of the signal receiving data
1637 + * @class
1638 + */
1639 +let Connection = function (source, signal, destination, slot) {
1640 + /**
1641 + * Connects two components as described in this object
1642 + * @function ARCS.Connection#connect
1643 + */
1644 + this.connect = function () {
1645 + try {
1646 + _component_js__WEBPACK_IMPORTED_MODULE_0__.default.connect(source, signal, destination, slot);
1647 + } catch(e) { console.log(e, source, signal, destination, slot); }
1648 + };
1649 + /**
1650 + * Disconnects a signal/slot connection between the two components
1651 + * described in this object.
1652 + */
1653 + this.disconnect = function () {
1654 + _component_js__WEBPACK_IMPORTED_MODULE_0__.default.disconnect(source, signal, destination, slot);
1655 + };
1652 1656
1653 - res = ARCS.TransitionNetwork.build(tree[0],tokenEvents); 1657 + this.getSource = function() {
1654 - var i; 1658 + return source;
1655 - for (i=1; i < tree.length; i++) { 1659 + };
1656 - if (tree[i].hasOwnProperty('and')) {
1657 - rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents);
1658 - tmpTN = res.and(rightTN);
1659 - } else {
1660 - if (tree[i].hasOwnProperty('or')) {
1661 - rightTN = ARCS.TransitionNetwork.build(tree[i]['or'], tokenEvents);
1662 - tmpTN = res.or(rightTN);
1663 - } else {
1664 - console.warn('[ARCS] Illegal tree');
1665 - }
1666 - }
1667 - res = tmpTN;
1668 - }
1669 1660
1670 - return res; 1661 + this.getDestination = function () {
1662 + return destination;
1663 + };
1664 +
1665 + this.getSlot = function () {
1666 + return slot;
1667 + };
1668 +
1669 + this.getSignal = function () {
1670 + return signal;
1671 + };
1672 +};
1673 +/**
1674 + * Helper function that casts a connection from a description
1675 + * @param obj {object} a raw description of the connection
1676 + * @param context {object} the context in which this connection takes place.
1677 + * @return a connection
1678 + */
1679 +Connection.cast = function (obj, context) {
1680 + return new Connection(context.getComponent(obj.source)/*[obj.source].instance*/, obj.signal,
1681 + context.getComponent(obj.destination)/*[obj.destination].instance*/, obj.slot);
1671 }; 1682 };
1683 +
1684 +
1685 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ Connection: Connection});
1686 +
1687 +
1688 +/***/ }),
1689 +/* 10 */
1690 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1691 +
1692 +__webpack_require__.r(__webpack_exports__);
1693 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
1694 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
1695 +/* harmony export */ });
1696 +/* harmony import */ var _context_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
1697 +/* harmony import */ var _invocation_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
1698 +/* harmony import */ var _connection_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
1672 /****************************************************************************** 1699 /******************************************************************************
1673 - * Statemachine implementation 1700 + * Sheet implementation
1674 * ***************************************************************************/ 1701 * ***************************************************************************/
1702 +
1703 +
1704 +
1705 +
1675 /** 1706 /**
1676 - * Describes a statemachine 1707 + * Constructs a sheet
1677 - * @param obj {object} an object describing a state machine. If obj is empty then the statemachine is empty 1708 + * @param context {object} a context object
1678 * @class 1709 * @class
1710 + * @classdesc A Sheet is an operationnal configuration in an application. It
1711 + * contains many things: multiple sets of {@link ARCS.Invocation}
1712 + * performed at different times
1713 + * and a set of {@link ARCS.Connection}. Sheets have two high level operations:
1714 + * activation and deactivation.
1679 */ 1715 */
1680 -ARCS.Statemachine = new ARCS.Component.create(function (obj) { 1716 +let Sheet = function (ctx /*context*/) {
1681 - // dynamic construction: properties are initial state that have properties 1717 + var context = new _context_js__WEBPACK_IMPORTED_MODULE_0__.default();
1682 - // that are tokens and value that are the final state 1718 + var preconnections = [], postconnections = [], cleanups = [], connections = [],
1683 - var initial = "", final = "", transitions = {}, currentState = "", self= this; 1719 + invokePreconnections, invokePostconnections, invokeCleanups,
1684 - var astTokens = {}; // it keeps AST from event logic expressions 1720 + connect, disconnect, getComponentName,
1685 - var tokenEvents = {}; // it keeps promises for tokens. 1721 + preCount = 0, postCount = 0, cleanCount = 0, connCount = 0;
1686 - var network = {}; 1722 +
1723 + invokePreconnections = function () {
1724 + var i;
1725 + for (i = 0; i < preconnections.length; i++) {
1726 + preconnections[i].invoke();
1727 + }
1728 + };
1729 + invokePostconnections = function () {
1730 + var i;
1731 + for (i = 0; i < postconnections.length; i++) {
1732 + postconnections[i].invoke();
1733 + }
1734 + };
1735 + invokeCleanups = function () {
1736 + var i;
1737 + for (i = 0; i < cleanups.length; i++) {
1738 + cleanups[i].invoke();
1739 + }
1740 + };
1741 + connect = function () {
1742 + var i;
1743 + for (i = 0; i < connections.length; i++) {
1744 + connections[i].connect();
1745 + }
1746 + };
1747 + disconnect = function () {
1748 + var i;
1749 + for (i = 0; i < connections.length; i++) {
1750 + connections[i].disconnect();
1751 + }
1752 + };
1753 +
1754 + this.setContext = function (ctx) {
1755 + context = ctx;
1756 + };
1757 + /**
1758 + * Activates this sheet. Pre-connection invocations are peformed, then
1759 + * connections are established and post-connection invocations are finally
1760 + * performed.
1761 + */
1762 + this.activate = function () {
1763 + context.instanciate().then(function() {
1764 + invokePreconnections();
1765 + connect();
1766 + invokePostconnections();
1767 + });
1768 + };
1769 + /**
1770 + * Deactivates this sheet. Connections are removed and then cleanup invocations
1771 + * are performed.
1772 + */
1773 + this.deactivate = function () {
1774 + disconnect();
1775 + invokeCleanups();
1776 + };
1777 +
1778 + this.addPreConnection = function (obj) {
1779 + var pre = _invocation_js__WEBPACK_IMPORTED_MODULE_1__.default.cast(obj, context);
1780 + pre.id = preCount++;
1781 + preconnections.push(pre);
1782 + return pre.id;
1783 + };
1687 1784
1785 + this.addPostConnection = function (obj) {
1786 + var post = _invocation_js__WEBPACK_IMPORTED_MODULE_1__.default.cast(obj, context);
1787 + post.id = postCount++;
1788 + postconnections.push(post);
1789 + return post.id;
1790 + };
1688 1791
1689 - var addToken = function(t) { 1792 +
1690 - if ( self.slots.indexOf(t) < 0 ) { 1793 + this.addCleanup = function (obj) {
1691 - self.slots.push(t); 1794 + var cleanup = _invocation_js__WEBPACK_IMPORTED_MODULE_1__.default.cast(obj, context);
1692 - self[t] = function( s ) { 1795 + cleanup.id = cleanCount++;
1693 - return function() { 1796 + cleanups.push(cleanup);
1694 - self.setToken(s); 1797 + return cleanup.id;
1695 - }; 1798 + };
1696 - } (t); 1799 +
1800 + this.addConnection = function (obj) {
1801 + var connection = _connection_js__WEBPACK_IMPORTED_MODULE_2__.default.cast(obj, context);
1802 + connection.id = connCount++;
1803 + connections.push(connection);
1804 + return connection.id;
1805 + };
1806 +
1807 +
1808 + var removeItem = function(id, tab) {
1809 + var i = tab.length;
1810 +
1811 + while ( i-- && tab[i].id !== id );
1812 +
1813 + if (i >= 0) {
1814 + tab.splice(i,1);
1815 + } else {
1816 + console.warn("Could not remove data with id", id);
1697 } 1817 }
1698 }; 1818 };
1699 1819
1700 - /* this function aims at preparing transition networks for a given state*/ 1820 + this.removePreConnection = function (id) {
1701 - var setSheet = function(s) { 1821 + removeItem(id, preconnections);
1702 - // we build promise trees using ast 1822 + };
1703 - var t; 1823 +
1704 - 1824 + this.removePostConnection = function (id) {
1705 - if (transitions.hasOwnProperty(s)) { 1825 + removeItem(id, postconnections);
1706 - tokenEvents = {}; 1826 + };
1707 - for (t in transitions[s]) { 1827 +
1708 - if (transitions[s].hasOwnProperty(t)) { 1828 + this.removeCleanup = function (id) {
1709 - network = ARCS.TransitionNetwork.build(astTokens[t],tokenEvents).promise; 1829 + removeItem(id, cleanups);
1710 - network.then( 1830 + };
1711 - function() { 1831 +
1712 - var token; 1832 + var changeItem = function(id, value, tab) {
1713 - // clean up remaining promises 1833 + var i = tab.length;
1714 - for (token in tokenEvents) { 1834 + while ( i-- && tab[i].id !== id );
1715 - if (tokenEvents.hasOwnProperty(token)) tokenEvents[token].abort(); 1835 + if (i >= 0) {
1716 - } 1836 + tab[i].value = value;
1717 - // then activate next sheet
1718 - setSheet(transitions[s][t]);
1719 - }
1720 - );
1721 - }
1722 - }
1723 } 1837 }
1838 + };
1839 +
1840 + this.changePreConnection = function (id, value) {
1841 + changeItem(id, value, preconnections);
1842 + };
1843 +
1844 + this.changePostConnection = function (id, value) {
1845 + changeItem(id, value, postconnections);
1846 + };
1847 +
1848 + this.changeCleanup = function (id, value) {
1849 + changeItem(id, value, cleanups);
1850 + };
1851 +
1852 + this.removeConnection = function (id) {
1853 + removeItem(id, connections);
1854 + };
1855 +
1856 +
1857 + var swapItems = function (id1, id2, tab) {
1858 + var item;
1724 1859
1725 - currentState = s; 1860 + var i = tab.length, j = tab.length;
1726 - self.emit('requestSheet', currentState);
1727 - if (currentState === final) {
1728 - self.emit('requestTermination');
1729 - }
1730 1861
1862 + while( i-- && tab[i].id !== id1 ) ;
1863 + while( j-- && tab[j].id !== id2 ) ;
1864 +
1865 + if (i >= 0 && j >= 0) {
1866 + item = tab[i];
1867 + tab[i] = tab[j];
1868 + tab[j] = item;
1869 + tab[i].id = id1;
1870 + tab[j].id = id2;
1871 + }
1731 }; 1872 };
1732 1873
1733 - /** 1874 + this.swapConnections = function (id1, id2) {
1734 - * Sets the initial state of the statemachine 1875 + swapItems(id1, id2, connections);
1735 - * @param string {string} name of the initial state
1736 - */
1737 - this.setInitialState = function (string) {
1738 - initial = string;
1739 - currentState = initial;
1740 }; 1876 };
1741 - /** 1877 +
1742 - * Sets the final state of the statemachine 1878 + this.swapCleanups = function (id1, id2) {
1743 - * @param string {string} name of the final state 1879 + swapItems(id1, id2, cleanups);
1744 - */
1745 - this.setFinalState = function (string) { final = string; };
1746 - /**
1747 - * Adds a transition to the state machine
1748 - * @param start {string} name of the state at the beginning of the transition
1749 - * @param token {string} name of the token triggering the transition
1750 - * @param end {string} name of the state reached at the end of the transition
1751 - */
1752 - this.addTransition = function (start, token, end) {
1753 - var re = /([A-Za-z_]\w*)/g;
1754 - var t, tsd, ts, tsc;
1755 - try {
1756 -
1757 - var tsd = ARCS.EventLogicParser.parse(token);
1758 - if (typeof tsd === "string") {
1759 - addToken(tsd);
1760 - } else {
1761 - while( (t = re.exec(token)) !== null) {
1762 - addToken(t[0]);
1763 - }
1764 - }
1765 -
1766 - astTokens[token] = tsd;
1767 -
1768 - if (transitions[start] === undefined) {
1769 - transitions[start] = {};
1770 - }
1771 - transitions[start][token] = end;
1772 - } catch (e) { }
1773 }; 1880 };
1774 - /** 1881 +
1775 - * Gives a token to the statemachine. According to its list of transitions 1882 + this.swapPreConnections = function (id1, id2) {
1776 - * and the current state, it may trigger a transition 1883 + swapItems(id1, id2, preconnections);
1777 - * @param token {string} name of the token 1884 + };
1778 - */ 1885 +
1779 - this.setToken = function (token) { 1886 + this.swapPostConnections = function (id1, id2) {
1780 - if (tokenEvents.hasOwnProperty(token)) { 1887 + swapItems(id1, id2, postconnections);
1781 - tokenEvents[token].accept(); 1888 + };
1889 +
1890 +
1891 + var cacheConnectionsInvocations = function(object) {
1892 + var i = 0, castInvocation = _invocation_js__WEBPACK_IMPORTED_MODULE_1__.default.cast, castConnection = _connection_js__WEBPACK_IMPORTED_MODULE_2__.default.cast;
1893 + for (i = 0; i < object.preconnections.length; i++) {
1894 + preconnections.push(castInvocation(object.preconnections[i], context));
1895 + }
1896 + for (i = 0; i < object.postconnections.length; i++) {
1897 + postconnections.push(castInvocation(object.postconnections[i], context));
1782 } 1898 }
1899 + for (i = 0; i < object.cleanups.length; i++) {
1900 + cleanups.push(castInvocation(object.cleanups[i], context));
1901 + }
1902 + for (i = 0; i < object.connections.length; i++) {
1903 + connections.push(castConnection(object.connections[i], context));
1904 + }
1783 }; 1905 };
1906 +
1784 /** 1907 /**
1785 - * Sets transitions from a list of transitions 1908 + * Imports a structure object describing the content of a sheet.
1786 - * @param obj {object[]} list of transitions 1909 + * @param object {object} structured object describing sheet's content.
1787 */ 1910 */
1788 - this.setTransitions = function (obj) { 1911 + this.import = function (object) {
1789 - // this function is no longuer a simple affectation 1912 + if (object.hasOwnProperty("context")) {
1790 - // transitions = obj; 1913 + context = new _context_js__WEBPACK_IMPORTED_MODULE_0__.default(object.context);
1791 - var p, t, i; 1914 + context.setParent(ctx);
1792 - for (p in obj) {
1793 - if (obj.hasOwnProperty(p)) {
1794 - for (t in obj[p]) {
1795 - if (obj[p].hasOwnProperty(t)) {
1796 - this.addTransition(p, t, obj[p][t]);
1797 - }
1798 - }
1799 - }
1800 } 1915 }
1801 1916
1802 - 1917 + // the caching system below should wait for the context to be proper initialized
1803 - // we will temporay dump properties in order to understand how the statemachine is built 1918 + // todo: there may be a flow here if the instanciation is too long.
1804 - /* 1919 + context.instanciate().then( function() {
1805 - for (p in transitions) { 1920 + cacheConnectionsInvocations(object);
1806 - if (transitions.hasOwnProperty(p)) { 1921 + });
1807 - for (t in transitions[p]) {
1808 - if (transitions[p].hasOwnProperty(t)) {
1809 - console.log("\t" + p + "\t----\t" + t + "\t--->\t" + transitions[p][t]);
1810 - }
1811 - }
1812 - }
1813 - }*/
1814 }; 1922 };
1815 - /** 1923 +
1816 - * Initialize and starts the statemachine, setting its current state to 1924 + var revertInvocation = function (obj) {
1817 - * the initial state (by default, it is the departure of the first transition 1925 + return {
1818 - */ 1926 + destination: context.getComponentName(obj.getDestination()),
1819 - this.start = function () { 1927 + slot: obj.getSlot(),
1820 - console.log("statemachine", this, initial,obj); 1928 + value: obj.getValue()
1821 - setSheet(initial); 1929 + };
1930 + };
1931 +
1932 + var revertConnection = function (obj) {
1933 + return {
1934 + source: context.getComponentName(obj.getSource()),
1935 + signal: obj.getSignal(),
1936 + destination: context.getComponentName(obj.getDestination()),
1937 + slot: obj.getSlot()
1938 + };
1939 + };
1940 +
1941 + this.toJSON = function () {
1942 + var preconns = [];
1943 + var postconns = [];
1944 + var conns = [];
1945 + var cleans = [];
1946 +
1947 + var i;
1948 + for (i = 0; i < connections.length; i++) {
1949 + conns.push(revertConnection(connections[i]))
1950 + }
1951 + for (i = 0; i < preconnections.length; i++) {
1952 + preconns.push(revertInvocation(preconnections[i]))
1953 + }
1954 + for (i = 0; i < postconnections.length; i++) {
1955 + postconns.push(revertInvocation(postconnections[i]))
1956 + }
1957 + for (i = 0; i < cleanups.length; i++) {
1958 + cleans.push(revertInvocation(cleanups[i]))
1959 + }
1960 +
1961 + return {
1962 + preconnections : preconns,
1963 + postconnections : postconns,
1964 + connections: conns,
1965 + cleanups: cleans
1966 + };
1822 }; 1967 };
1823 1968
1969 + //console.log("setting parent");
1970 + context.setParent(ctx);
1971 +};
1824 1972
1825 - // INIT CODE 1973 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({Sheet: Sheet});
1826 - if (obj !== undefined) {
1827 - initial = obj.initial;
1828 - final = obj.final;
1829 - this.setTransitions(obj.transitions);
1830 - currentState = "";
1831 - }
1832 1974
1833 -},
1834 -['setToken'],
1835 -['requestSheet', 'requestTermination']
1836 -);
1837 -
1838 1975
1976 +/***/ }),
1977 +/* 11 */
1978 +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
1979 +
1980 +__webpack_require__.r(__webpack_exports__);
1981 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
1982 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
1983 +/* harmony export */ });
1984 +/* harmony import */ var _context_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
1985 +/* harmony import */ var _sheet_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10);
1986 +/* harmony import */ var _component_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1);
1839 /****************************************************************************** 1987 /******************************************************************************
1840 * Application implementation 1988 * Application implementation
1841 * ***************************************************************************/ 1989 * ***************************************************************************/
1842 1990
1991 +
1992 +
1993 +
1843 /** 1994 /**
1844 * Creates an application runnable by the ARCS engine. 1995 * Creates an application runnable by the ARCS engine.
1845 * @class ARCS.Application 1996 * @class ARCS.Application
...@@ -1849,8 +2000,8 @@ ARCS.Statemachine = new ARCS.Component.create(function (obj) { ...@@ -1849,8 +2000,8 @@ ARCS.Statemachine = new ARCS.Component.create(function (obj) {
1849 * to load all external scripts describing components, instanciate 2000 * to load all external scripts describing components, instanciate
1850 * all components and then start the application 2001 * all components and then start the application
1851 */ 2002 */
1852 -ARCS.Application = function () { 2003 +let Application = function () {
1853 - var context = new ARCS.Context(), 2004 + var context = new _context_js__WEBPACK_IMPORTED_MODULE_0__.default(),
1854 sheets = {}, 2005 sheets = {},
1855 controller = {}, 2006 controller = {},
1856 dependencies = [], 2007 dependencies = [],
...@@ -1906,13 +2057,13 @@ ARCS.Application = function () { ...@@ -1906,13 +2057,13 @@ ARCS.Application = function () {
1906 // then we should work on sheets 2057 // then we should work on sheets
1907 sheetList = Object.keys(sheets); 2058 sheetList = Object.keys(sheets);
1908 for (i = 0; i < sheetList.length; i++) { 2059 for (i = 0; i < sheetList.length; i++) {
1909 - temp = new ARCS.Sheet(context); 2060 + temp = new _sheet_js__WEBPACK_IMPORTED_MODULE_1__.default(context);
1910 temp.import(sheets[sheetList[i]], context); 2061 temp.import(sheets[sheetList[i]], context);
1911 sheets[sheetList[i]] = temp; 2062 sheets[sheetList[i]] = temp;
1912 } 2063 }
1913 2064
1914 - ARCS.Component.connect(controller, "requestSheet", self, "setSheet"); 2065 + _component_js__WEBPACK_IMPORTED_MODULE_2__.default.connect(controller, "requestSheet", self, "setSheet");
1915 - ARCS.Component.connect(controller, "requestTermination", self, "finish"); 2066 + _component_js__WEBPACK_IMPORTED_MODULE_2__.default.connect(controller, "requestTermination", self, "finish");
1916 controller.start(); 2067 controller.start();
1917 }; 2068 };
1918 2069
...@@ -2011,7 +2162,7 @@ ARCS.Application = function () { ...@@ -2011,7 +2162,7 @@ ARCS.Application = function () {
2011 * 2162 *
2012 */ 2163 */
2013 this.import = function (object) { 2164 this.import = function (object) {
2014 - context = new ARCS.Context(object.context/*.components*/); 2165 + context = new _context_js__WEBPACK_IMPORTED_MODULE_0__.default(object.context/*.components*/);
2015 sheets = object.sheets; 2166 sheets = object.sheets;
2016 controller = object.controller; 2167 controller = object.controller;
2017 if (controller === undefined) { 2168 if (controller === undefined) {
...@@ -2042,17 +2193,114 @@ ARCS.Application = function () { ...@@ -2042,17 +2193,114 @@ ARCS.Application = function () {
2042 }; 2193 };
2043 }; 2194 };
2044 2195
2045 -ARCS.Application.setDependency = function (app, key) { 2196 +Application.setDependency = function (app, key) {
2046 app.setDependency(key); 2197 app.setDependency(key);
2047 }; 2198 };
2048 2199
2049 2200
2050 2201
2051 -ARCS.Component.create(ARCS.Application); 2202 +_component_js__WEBPACK_IMPORTED_MODULE_2__.default.create(Application);
2052 -ARCS.Application.slot("setSheet"); 2203 +Application.slot("setSheet");
2053 -ARCS.Application.slot("finish"); 2204 +Application.slot("finish");
2205 +
2206 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({Application: Application});
2207 +
2208 +
2209 +/***/ })
2210 +/******/ ]);
2211 +/************************************************************************/
2212 +/******/ // The module cache
2213 +/******/ var __webpack_module_cache__ = {};
2214 +/******/
2215 +/******/ // The require function
2216 +/******/ function __webpack_require__(moduleId) {
2217 +/******/ // Check if module is in cache
2218 +/******/ var cachedModule = __webpack_module_cache__[moduleId];
2219 +/******/ if (cachedModule !== undefined) {
2220 +/******/ return cachedModule.exports;
2221 +/******/ }
2222 +/******/ // Create a new module (and put it into the cache)
2223 +/******/ var module = __webpack_module_cache__[moduleId] = {
2224 +/******/ // no module.id needed
2225 +/******/ // no module.loaded needed
2226 +/******/ exports: {}
2227 +/******/ };
2228 +/******/
2229 +/******/ // Execute the module function
2230 +/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
2231 +/******/
2232 +/******/ // Return the exports of the module
2233 +/******/ return module.exports;
2234 +/******/ }
2235 +/******/
2236 +/************************************************************************/
2237 +/******/ /* webpack/runtime/define property getters */
2238 +/******/ (() => {
2239 +/******/ // define getter functions for harmony exports
2240 +/******/ __webpack_require__.d = (exports, definition) => {
2241 +/******/ for(var key in definition) {
2242 +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
2243 +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
2244 +/******/ }
2245 +/******/ }
2246 +/******/ };
2247 +/******/ })();
2248 +/******/
2249 +/******/ /* webpack/runtime/hasOwnProperty shorthand */
2250 +/******/ (() => {
2251 +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
2252 +/******/ })();
2253 +/******/
2254 +/******/ /* webpack/runtime/make namespace object */
2255 +/******/ (() => {
2256 +/******/ // define __esModule on exports
2257 +/******/ __webpack_require__.r = (exports) => {
2258 +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
2259 +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2260 +/******/ }
2261 +/******/ Object.defineProperty(exports, '__esModule', { value: true });
2262 +/******/ };
2263 +/******/ })();
2264 +/******/
2265 +/************************************************************************/
2266 +var __webpack_exports__ = {};
2267 +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
2268 +(() => {
2269 +__webpack_require__.r(__webpack_exports__);
2270 +/* harmony export */ __webpack_require__.d(__webpack_exports__, {
2271 +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
2272 +/* harmony export */ });
2273 +/* harmony import */ var _component_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
2274 +/* harmony import */ var _statemachine_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
2275 +/* harmony import */ var _arcs_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
2276 +/* harmony import */ var _context_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(7);
2277 +/* harmony import */ var _invocation_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(8);
2278 +/* harmony import */ var _connection_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(9);
2279 +/* harmony import */ var _sheet_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(10);
2280 +/* harmony import */ var _application_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(11);
2281 +// no longer needed with the use of imports
2282 +
2054 2283
2055 2284
2056 -// no longer needed with the use of imports
2057 2285
2058 -export { ARCS as default};
...\ No newline at end of file ...\ No newline at end of file
2286 +
2287 +
2288 +
2289 +
2290 +
2291 +
2292 +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
2293 + Component: _component_js__WEBPACK_IMPORTED_MODULE_0__.default,
2294 + isInNode : _arcs_js__WEBPACK_IMPORTED_MODULE_2__.default,
2295 + StateMachine: _statemachine_js__WEBPACK_IMPORTED_MODULE_1__.default,
2296 + Context: _context_js__WEBPACK_IMPORTED_MODULE_3__.default,
2297 + Invocation: _invocation_js__WEBPACK_IMPORTED_MODULE_4__.default,
2298 + Connection: _connection_js__WEBPACK_IMPORTED_MODULE_5__.default,
2299 + Sheet: _sheet_js__WEBPACK_IMPORTED_MODULE_6__.default,
2300 + Application: _application_js__WEBPACK_IMPORTED_MODULE_7__.default
2301 +});
2302 +
2303 +})();
2304 +
2305 +/******/ })()
2306 +;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -12,6 +12,12 @@ ...@@ -12,6 +12,12 @@
12 ], 12 ],
13 "author": "Jean-Yves Didier", 13 "author": "Jean-Yves Didier",
14 "license": "GPL-3.0-or-later", 14 "license": "GPL-3.0-or-later",
15 + "dependencies": {
16 + "tracking": ">=1.1.3",
17 + "three": ">=0.131",
18 + "js-aruco": ">=0.1",
19 + "codemirror": ">=5.62"
20 + },
15 "devDependencies": { 21 "devDependencies": {
16 "bower": ">=1.3.9", 22 "bower": ">=1.3.9",
17 "grunt": ">=0.4.5", 23 "grunt": ">=0.4.5",
......
1 /****************************************************************************** 1 /******************************************************************************
2 * Application implementation 2 * Application implementation
3 * ***************************************************************************/ 3 * ***************************************************************************/
4 +import Context from './context.js';
5 +import Sheet from './sheet.js';
6 +import Component from './component.js';
4 7
5 /** 8 /**
6 * Creates an application runnable by the ARCS engine. 9 * Creates an application runnable by the ARCS engine.
...@@ -11,8 +14,8 @@ ...@@ -11,8 +14,8 @@
11 * to load all external scripts describing components, instanciate 14 * to load all external scripts describing components, instanciate
12 * all components and then start the application 15 * all components and then start the application
13 */ 16 */
14 -ARCS.Application = function () { 17 +let Application = function () {
15 - var context = new ARCS.Context(), 18 + var context = new Context(),
16 sheets = {}, 19 sheets = {},
17 controller = {}, 20 controller = {},
18 dependencies = [], 21 dependencies = [],
...@@ -68,13 +71,13 @@ ARCS.Application = function () { ...@@ -68,13 +71,13 @@ ARCS.Application = function () {
68 // then we should work on sheets 71 // then we should work on sheets
69 sheetList = Object.keys(sheets); 72 sheetList = Object.keys(sheets);
70 for (i = 0; i < sheetList.length; i++) { 73 for (i = 0; i < sheetList.length; i++) {
71 - temp = new ARCS.Sheet(context); 74 + temp = new Sheet(context);
72 temp.import(sheets[sheetList[i]], context); 75 temp.import(sheets[sheetList[i]], context);
73 sheets[sheetList[i]] = temp; 76 sheets[sheetList[i]] = temp;
74 } 77 }
75 78
76 - ARCS.Component.connect(controller, "requestSheet", self, "setSheet"); 79 + Component.connect(controller, "requestSheet", self, "setSheet");
77 - ARCS.Component.connect(controller, "requestTermination", self, "finish"); 80 + Component.connect(controller, "requestTermination", self, "finish");
78 controller.start(); 81 controller.start();
79 }; 82 };
80 83
...@@ -173,7 +176,7 @@ ARCS.Application = function () { ...@@ -173,7 +176,7 @@ ARCS.Application = function () {
173 * 176 *
174 */ 177 */
175 this.import = function (object) { 178 this.import = function (object) {
176 - context = new ARCS.Context(object.context/*.components*/); 179 + context = new Context(object.context/*.components*/);
177 sheets = object.sheets; 180 sheets = object.sheets;
178 controller = object.controller; 181 controller = object.controller;
179 if (controller === undefined) { 182 if (controller === undefined) {
...@@ -204,13 +207,14 @@ ARCS.Application = function () { ...@@ -204,13 +207,14 @@ ARCS.Application = function () {
204 }; 207 };
205 }; 208 };
206 209
207 -ARCS.Application.setDependency = function (app, key) { 210 +Application.setDependency = function (app, key) {
208 app.setDependency(key); 211 app.setDependency(key);
209 }; 212 };
210 213
211 214
212 215
213 -ARCS.Component.create(ARCS.Application); 216 +Component.create(Application);
214 -ARCS.Application.slot("setSheet"); 217 +Application.slot("setSheet");
215 -ARCS.Application.slot("finish"); 218 +Application.slot("finish");
216 219
220 +export default {Application: Application};
......
...@@ -5,18 +5,13 @@ ...@@ -5,18 +5,13 @@
5 //"use strict"; 5 //"use strict";
6 6
7 7
8 +
9 +
8 /** 10 /**
9 * Main source: describes all the methods needed by the ARCS engine 11 * Main source: describes all the methods needed by the ARCS engine
10 * @file 12 * @file
11 */ 13 */
12 14
13 -/**
14 - * Defines all elements needed for Augmented Reality Component System
15 - * @namespace
16 - */
17 -var ARCS = ARCS || {};
18 -
19 -
20 15
21 /****************************************************************************** 16 /******************************************************************************
22 * Helper functions to determine environment 17 * Helper functions to determine environment
...@@ -24,9 +19,12 @@ var ARCS = ARCS || {}; ...@@ -24,9 +19,12 @@ var ARCS = ARCS || {};
24 19
25 /** 20 /**
26 * @return {boolean} true if ARCS is run in a node.js environment 21 * @return {boolean} true if ARCS is run in a node.js environment
27 - */ 22 + */
28 -ARCS.isInNode = function () {
29 - return (typeof require === 'function' && require.resolve);
30 -};
31 23
24 +export default function isInNode() {
25 + return (typeof process !== 'undefined') &&
26 + (process.release.name.search(/node|io.js/) !== -1);
27 +
28 + // return (typeof require === 'function' && require.resolve);
29 +};
32 30
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
8 * 8 *
9 * @namespace 9 * @namespace
10 */ 10 */
11 -ARCS.Component = { 11 +var Component = {
12 /** Error message */ 12 /** Error message */
13 SourceIsNotComponent : {message : "Source is not a component"}, 13 SourceIsNotComponent : {message : "Source is not a component"},
14 /** Error message */ 14 /** Error message */
...@@ -124,13 +124,13 @@ ARCS.Component = { ...@@ -124,13 +124,13 @@ ARCS.Component = {
124 var orig, p; 124 var orig, p;
125 // here we can perform various checks. 125 // here we can perform various checks.
126 if (source.signals === undefined) { 126 if (source.signals === undefined) {
127 - throw ARCS.Component.SourceIsNotComponent; 127 + throw Component.SourceIsNotComponent;
128 } 128 }
129 if (source.signals[signal] === undefined) { 129 if (source.signals[signal] === undefined) {
130 - throw ARCS.Component.UndefinedSignal; 130 + throw Component.UndefinedSignal;
131 } 131 }
132 if (destination[slt] === undefined) { 132 if (destination[slt] === undefined) {
133 - throw ARCS.Component.UndefinedSlot; 133 + throw Component.UndefinedSlot;
134 } 134 }
135 // we must also check if the signals dispose of their own implementation 135 // we must also check if the signals dispose of their own implementation
136 if (!source.hasOwnProperty('signals')) { 136 if (!source.hasOwnProperty('signals')) {
...@@ -170,7 +170,7 @@ ARCS.Component = { ...@@ -170,7 +170,7 @@ ARCS.Component = {
170 */ 170 */
171 invoke : function (destination, slt, value) { 171 invoke : function (destination, slt, value) {
172 if (destination[slt] === undefined) { 172 if (destination[slt] === undefined) {
173 - throw ARCS.Component.UndefinedSlot; 173 + throw Component.UndefinedSlot;
174 } 174 }
175 175
176 176
...@@ -188,3 +188,5 @@ ARCS.Component = { ...@@ -188,3 +188,5 @@ ARCS.Component = {
188 } 188 }
189 } 189 }
190 }; 190 };
191 +
192 +export default { Component: Component};
......
1 /****************************************************************************** 1 /******************************************************************************
2 * Connection implementation 2 * Connection implementation
3 * ***************************************************************************/ 3 * ***************************************************************************/
4 +import Component from './component.js';
5 +
4 /** 6 /**
5 * Defines a connection between two components 7 * Defines a connection between two components
6 * @param source {object} component at the source 8 * @param source {object} component at the source
...@@ -9,14 +11,14 @@ ...@@ -9,14 +11,14 @@
9 * @param slot {string} name of the signal receiving data 11 * @param slot {string} name of the signal receiving data
10 * @class 12 * @class
11 */ 13 */
12 -ARCS.Connection = function (source, signal, destination, slot) { 14 +let Connection = function (source, signal, destination, slot) {
13 /** 15 /**
14 * Connects two components as described in this object 16 * Connects two components as described in this object
15 * @function ARCS.Connection#connect 17 * @function ARCS.Connection#connect
16 */ 18 */
17 this.connect = function () { 19 this.connect = function () {
18 try { 20 try {
19 - ARCS.Component.connect(source, signal, destination, slot); 21 + Component.connect(source, signal, destination, slot);
20 } catch(e) { console.log(e, source, signal, destination, slot); } 22 } catch(e) { console.log(e, source, signal, destination, slot); }
21 }; 23 };
22 /** 24 /**
...@@ -24,7 +26,7 @@ ARCS.Connection = function (source, signal, destination, slot) { ...@@ -24,7 +26,7 @@ ARCS.Connection = function (source, signal, destination, slot) {
24 * described in this object. 26 * described in this object.
25 */ 27 */
26 this.disconnect = function () { 28 this.disconnect = function () {
27 - ARCS.Component.disconnect(source, signal, destination, slot); 29 + Component.disconnect(source, signal, destination, slot);
28 }; 30 };
29 31
30 this.getSource = function() { 32 this.getSource = function() {
...@@ -49,7 +51,10 @@ ARCS.Connection = function (source, signal, destination, slot) { ...@@ -49,7 +51,10 @@ ARCS.Connection = function (source, signal, destination, slot) {
49 * @param context {object} the context in which this connection takes place. 51 * @param context {object} the context in which this connection takes place.
50 * @return a connection 52 * @return a connection
51 */ 53 */
52 -ARCS.Connection.cast = function (obj, context) { 54 +Connection.cast = function (obj, context) {
53 - return new ARCS.Connection(context.getComponent(obj.source)/*[obj.source].instance*/, obj.signal, 55 + return new Connection(context.getComponent(obj.source)/*[obj.source].instance*/, obj.signal,
54 context.getComponent(obj.destination)/*[obj.destination].instance*/, obj.slot); 56 context.getComponent(obj.destination)/*[obj.destination].instance*/, obj.slot);
55 }; 57 };
58 +
59 +
60 +export default { Connection: Connection};
......
1 +import StateMachine from './statemachine.js';
2 +import isInNode from './arcs.js';
3 +
1 /** 4 /**
2 * @class ARCS.Context 5 * @class ARCS.Context
3 * @classdesc Class representing a context containing libraries and components 6 * @classdesc Class representing a context containing libraries and components
4 * used by different parts of the framework. 7 * used by different parts of the framework.
5 * @param ctx {object} an object representing data for the context. 8 * @param ctx {object} an object representing data for the context.
6 */ 9 */
7 -ARCS.Context = function( ctx ) { 10 +let Context = function( ctx ) {
8 var components = {}; 11 var components = {};
9 var constants = {}; 12 var constants = {};
10 var factories = {}; 13 var factories = {};
...@@ -17,7 +20,7 @@ ARCS.Context = function( ctx ) { ...@@ -17,7 +20,7 @@ ARCS.Context = function( ctx ) {
17 var instanciateComponents; 20 var instanciateComponents;
18 21
19 22
20 - factories.StateMachine = ARCS.Statemachine; 23 + factories.StateMachine = Statemachine;
21 24
22 25
23 if (ctx !== undefined) { 26 if (ctx !== undefined) {
...@@ -43,9 +46,9 @@ ARCS.Context = function( ctx ) { ...@@ -43,9 +46,9 @@ ARCS.Context = function( ctx ) {
43 var loadDataFile =async function(fileName) { 46 var loadDataFile =async function(fileName) {
44 var dataPromise ; 47 var dataPromise ;
45 48
46 - if (ARCS.isInNode()) { 49 + if (isInNode()) {
47 return new Promise(function (resolve, reject) { 50 return new Promise(function (resolve, reject) {
48 - var dep = require(fileName); 51 + var dep = require(/* webpackIgnore: true */fileName);
49 if (dep !== undefined) { 52 if (dep !== undefined) {
50 resolve(dep); 53 resolve(dep);
51 } else { 54 } else {
...@@ -62,7 +65,7 @@ ARCS.Context = function( ctx ) { ...@@ -62,7 +65,7 @@ ARCS.Context = function( ctx ) {
62 var i; 65 var i;
63 // we will use different instances of require either the one of node 66 // we will use different instances of require either the one of node
64 // or the one from require.js 67 // or the one from require.js
65 - ARCS.Context.currentContext = self; 68 + Context.currentContext = self;
66 69
67 var res=[]; 70 var res=[];
68 for(i=0; i < libraries.length; i++) { 71 for(i=0; i < libraries.length; i++) {
...@@ -125,7 +128,7 @@ ARCS.Context = function( ctx ) { ...@@ -125,7 +128,7 @@ ARCS.Context = function( ctx ) {
125 this.loadLibrary = function (libName, cbFunction) { 128 this.loadLibrary = function (libName, cbFunction) {
126 var libUrl = libName, libActualName = libName; 129 var libUrl = libName, libActualName = libName;
127 130
128 - ARCS.Context.currentContext = self; 131 + Context.currentContext = self;
129 if (typeof libName !== "string") { 132 if (typeof libName !== "string") {
130 libActualName = libName.name; 133 libActualName = libName.name;
131 libUrl = libName.url; 134 libUrl = libName.url;
...@@ -135,11 +138,11 @@ ARCS.Context = function( ctx ) { ...@@ -135,11 +138,11 @@ ARCS.Context = function( ctx ) {
135 libraries.push(libActualName); 138 libraries.push(libActualName);
136 } 139 }
137 // TODO promisify call to cbFunction 140 // TODO promisify call to cbFunction
138 - return import(libUrl).then( function(module) { 141 + return import(/* webpackIgnore: true */libUrl).then( function(module) {
139 // TODO insert here component factories 142 // TODO insert here component factories
140 for (p in module.default) { 143 for (p in module.default) {
141 if (module.default.hasOwnProperty(p)) { 144 if (module.default.hasOwnProperty(p)) {
142 - ARCS.Context.currentContext.setFactory(p,module.default[p]); 145 + Context.currentContext.setFactory(p,module.default[p]);
143 } 146 }
144 } 147 }
145 148
...@@ -309,7 +312,7 @@ ARCS.Context = function( ctx ) { ...@@ -309,7 +312,7 @@ ARCS.Context = function( ctx ) {
309 312
310 313
311 /** pseudo-singleton to current context being used */ 314 /** pseudo-singleton to current context being used */
312 -ARCS.Context.currentContext = null; 315 +Context.currentContext = null;
313 -
314 316
317 +export default {Context: Context};
315 318
......
...@@ -36,7 +36,7 @@ WS = [ \r\n\t]* ...@@ -36,7 +36,7 @@ WS = [ \r\n\t]*
36 ******************************************************************************/ 36 ******************************************************************************/
37 37
38 38
39 -ARCS.EventLogicParser = (function() { 39 +let EventLogicParser = (function() {
40 /* 40 /*
41 * Generated by PEG.js 0.8.0. 41 * Generated by PEG.js 0.8.0.
42 * 42 *
...@@ -661,3 +661,5 @@ ARCS.EventLogicParser = (function() { ...@@ -661,3 +661,5 @@ ARCS.EventLogicParser = (function() {
661 parse: parse 661 parse: parse
662 }; 662 };
663 })(); 663 })();
664 +
665 +export default { EventLogicParser: EventLogicParser};
......
1 // no longer needed with the use of imports 1 // no longer needed with the use of imports
2 2
3 -export { ARCS as default};
...\ No newline at end of file ...\ No newline at end of file
3 +import Component from './component.js';
4 +import StateMachine from './statemachine.js';
5 +import isInNode from './arcs.js';
6 +import Context from './context.js';
7 +import Invocation from './invocation.js';
8 +import Connection from './connection.js';
9 +import Sheet from './sheet.js';
10 +import Application from './application.js';
11 +
12 +export default {
13 + Component: Component,
14 + isInNode : isInNode,
15 + StateMachine: StateMachine,
16 + Context: Context,
17 + Invocation: Invocation,
18 + Connection: Connection,
19 + Sheet: Sheet,
20 + Application: Application
21 +};
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
8 * @param value {mixed} value passed to the invoked slot 8 * @param value {mixed} value passed to the invoked slot
9 * @constructor 9 * @constructor
10 */ 10 */
11 -ARCS.Invocation = function (destination, slot, value) { 11 +
12 +let Invocation = function (destination, slot, value) {
12 this.getDestination = function () { 13 this.getDestination = function () {
13 return destination; 14 return destination;
14 }; 15 };
...@@ -36,19 +37,19 @@ ARCS.Invocation = function (destination, slot, value) { ...@@ -36,19 +37,19 @@ ARCS.Invocation = function (destination, slot, value) {
36 * @param context {object} the context in which this invocation takes place. 37 * @param context {object} the context in which this invocation takes place.
37 * @return an invocation 38 * @return an invocation
38 */ 39 */
39 -ARCS.Invocation.cast = function (obj, context) { 40 +Invocation.cast = function (obj, context) {
40 if (obj.value !== undefined) { 41 if (obj.value !== undefined) {
41 var component = context.getComponent(obj.destination); 42 var component = context.getComponent(obj.destination);
42 if (component === undefined) { 43 if (component === undefined) {
43 console.error("[ARCS] Destination ",obj.destination, " is undefined"); 44 console.error("[ARCS] Destination ",obj.destination, " is undefined");
44 } 45 }
45 46
46 - return new ARCS.Invocation(component, obj.slot, obj.value); 47 + return new Invocation(component, obj.slot, obj.value);
47 } 48 }
48 49
49 // this one looks odd, seems there is a failure in the logic. 50 // this one looks odd, seems there is a failure in the logic.
50 if (obj.ref !== undefined) { 51 if (obj.ref !== undefined) {
51 - return new ARCS.Invocation(context.getComponent(obj.destination), obj.slot, context.getConstant(obj.ref)); 52 + return new Invocation(context.getComponent(obj.destination), obj.slot, context.getConstant(obj.ref));
52 } 53 }
53 }; 54 };
54 55
...@@ -61,6 +62,8 @@ ARCS.Invocation.cast = function (obj, context) { ...@@ -61,6 +62,8 @@ ARCS.Invocation.cast = function (obj, context) {
61 };*/ 62 };*/
62 63
63 64
64 -ARCS.Invocation.PRE_CONNECTION = 0;
65 -ARCS.Invocation.POST_CONNECTION = 1;
66 -ARCS.Invocation.CLEAN_UP = 2;
...\ No newline at end of file ...\ No newline at end of file
65 +Invocation.PRE_CONNECTION = 0;
66 +Invocation.POST_CONNECTION = 1;
67 +Invocation.CLEAN_UP = 2;
68 +
69 +export default { Invocation: Invocation};
......
1 /****************************************************************************** 1 /******************************************************************************
2 * Sheet implementation 2 * Sheet implementation
3 * ***************************************************************************/ 3 * ***************************************************************************/
4 +import Context from './context.js';
5 +import Invocation from './invocation.js';
6 +import Connection from './connection.js';
7 +
4 /** 8 /**
5 * Constructs a sheet 9 * Constructs a sheet
6 * @param context {object} a context object 10 * @param context {object} a context object
...@@ -11,8 +15,8 @@ ...@@ -11,8 +15,8 @@
11 * and a set of {@link ARCS.Connection}. Sheets have two high level operations: 15 * and a set of {@link ARCS.Connection}. Sheets have two high level operations:
12 * activation and deactivation. 16 * activation and deactivation.
13 */ 17 */
14 -ARCS.Sheet = function (ctx /*context*/) { 18 +let Sheet = function (ctx /*context*/) {
15 - var context = new ARCS.Context(); 19 + var context = new Context();
16 var preconnections = [], postconnections = [], cleanups = [], connections = [], 20 var preconnections = [], postconnections = [], cleanups = [], connections = [],
17 invokePreconnections, invokePostconnections, invokeCleanups, 21 invokePreconnections, invokePostconnections, invokeCleanups,
18 connect, disconnect, getComponentName, 22 connect, disconnect, getComponentName,
...@@ -74,14 +78,14 @@ ARCS.Sheet = function (ctx /*context*/) { ...@@ -74,14 +78,14 @@ ARCS.Sheet = function (ctx /*context*/) {
74 }; 78 };
75 79
76 this.addPreConnection = function (obj) { 80 this.addPreConnection = function (obj) {
77 - var pre = ARCS.Invocation.cast(obj, context); 81 + var pre = Invocation.cast(obj, context);
78 pre.id = preCount++; 82 pre.id = preCount++;
79 preconnections.push(pre); 83 preconnections.push(pre);
80 return pre.id; 84 return pre.id;
81 }; 85 };
82 86
83 this.addPostConnection = function (obj) { 87 this.addPostConnection = function (obj) {
84 - var post = ARCS.Invocation.cast(obj, context); 88 + var post = Invocation.cast(obj, context);
85 post.id = postCount++; 89 post.id = postCount++;
86 postconnections.push(post); 90 postconnections.push(post);
87 return post.id; 91 return post.id;
...@@ -89,14 +93,14 @@ ARCS.Sheet = function (ctx /*context*/) { ...@@ -89,14 +93,14 @@ ARCS.Sheet = function (ctx /*context*/) {
89 93
90 94
91 this.addCleanup = function (obj) { 95 this.addCleanup = function (obj) {
92 - var cleanup = ARCS.Invocation.cast(obj, context); 96 + var cleanup = Invocation.cast(obj, context);
93 cleanup.id = cleanCount++; 97 cleanup.id = cleanCount++;
94 cleanups.push(cleanup); 98 cleanups.push(cleanup);
95 return cleanup.id; 99 return cleanup.id;
96 }; 100 };
97 101
98 this.addConnection = function (obj) { 102 this.addConnection = function (obj) {
99 - var connection = ARCS.Connection.cast(obj, context); 103 + var connection = Connection.cast(obj, context);
100 connection.id = connCount++; 104 connection.id = connCount++;
101 connections.push(connection); 105 connections.push(connection);
102 return connection.id; 106 return connection.id;
...@@ -187,7 +191,7 @@ ARCS.Sheet = function (ctx /*context*/) { ...@@ -187,7 +191,7 @@ ARCS.Sheet = function (ctx /*context*/) {
187 191
188 192
189 var cacheConnectionsInvocations = function(object) { 193 var cacheConnectionsInvocations = function(object) {
190 - var i = 0, castInvocation = ARCS.Invocation.cast, castConnection = ARCS.Connection.cast; 194 + var i = 0, castInvocation = Invocation.cast, castConnection = Connection.cast;
191 for (i = 0; i < object.preconnections.length; i++) { 195 for (i = 0; i < object.preconnections.length; i++) {
192 preconnections.push(castInvocation(object.preconnections[i], context)); 196 preconnections.push(castInvocation(object.preconnections[i], context));
193 } 197 }
...@@ -208,7 +212,7 @@ ARCS.Sheet = function (ctx /*context*/) { ...@@ -208,7 +212,7 @@ ARCS.Sheet = function (ctx /*context*/) {
208 */ 212 */
209 this.import = function (object) { 213 this.import = function (object) {
210 if (object.hasOwnProperty("context")) { 214 if (object.hasOwnProperty("context")) {
211 - context = new ARCS.Context(object.context); 215 + context = new Context(object.context);
212 context.setParent(ctx); 216 context.setParent(ctx);
213 } 217 }
214 218
...@@ -267,3 +271,5 @@ ARCS.Sheet = function (ctx /*context*/) { ...@@ -267,3 +271,5 @@ ARCS.Sheet = function (ctx /*context*/) {
267 //console.log("setting parent"); 271 //console.log("setting parent");
268 context.setParent(ctx); 272 context.setParent(ctx);
269 }; 273 };
274 +
275 +export default {Sheet: Sheet};
......
1 /****************************************************************************** 1 /******************************************************************************
2 * Statemachine implementation 2 * Statemachine implementation
3 * ***************************************************************************/ 3 * ***************************************************************************/
4 +
5 +import Component from './component.js';
6 +import TransitionNetwork from './transitionnetwork.js';
7 +import EventLogicParser from './eventlogicparser.js';
8 +
4 /** 9 /**
5 * Describes a statemachine 10 * Describes a statemachine
6 * @param obj {object} an object describing a state machine. If obj is empty then the statemachine is empty 11 * @param obj {object} an object describing a state machine. If obj is empty then the statemachine is empty
7 * @class 12 * @class
8 */ 13 */
9 -ARCS.Statemachine = new ARCS.Component.create(function (obj) { 14 +let Statemachine = new Component.create(function (obj) {
10 // dynamic construction: properties are initial state that have properties 15 // dynamic construction: properties are initial state that have properties
11 // that are tokens and value that are the final state 16 // that are tokens and value that are the final state
12 var initial = "", final = "", transitions = {}, currentState = "", self= this; 17 var initial = "", final = "", transitions = {}, currentState = "", self= this;
...@@ -35,7 +40,7 @@ ARCS.Statemachine = new ARCS.Component.create(function (obj) { ...@@ -35,7 +40,7 @@ ARCS.Statemachine = new ARCS.Component.create(function (obj) {
35 tokenEvents = {}; 40 tokenEvents = {};
36 for (t in transitions[s]) { 41 for (t in transitions[s]) {
37 if (transitions[s].hasOwnProperty(t)) { 42 if (transitions[s].hasOwnProperty(t)) {
38 - network = ARCS.TransitionNetwork.build(astTokens[t],tokenEvents).promise; 43 + network = TransitionNetwork.build(astTokens[t],tokenEvents).promise;
39 network.then( 44 network.then(
40 function() { 45 function() {
41 var token; 46 var token;
...@@ -164,3 +169,4 @@ ARCS.Statemachine = new ARCS.Component.create(function (obj) { ...@@ -164,3 +169,4 @@ ARCS.Statemachine = new ARCS.Component.create(function (obj) {
164 ['requestSheet', 'requestTermination'] 169 ['requestSheet', 'requestTermination']
165 ); 170 );
166 171
172 +export default { StateMachine: StateMachine};
......
1 // this class creates a promise that can be deferred as long as necessary. 1 // this class creates a promise that can be deferred as long as necessary.
2 // calls to accept or reject will solve the promise. 2 // calls to accept or reject will solve the promise.
3 3
4 -ARCS.TokenEvent = function() { 4 +let TokenEvent = function() {
5 var refResolve; 5 var refResolve;
6 var refReject; 6 var refReject;
7 7
...@@ -17,4 +17,6 @@ ARCS.TokenEvent = function() { ...@@ -17,4 +17,6 @@ ARCS.TokenEvent = function() {
17 this.abort = function() { 17 this.abort = function() {
18 refReject(); 18 refReject();
19 }; 19 };
20 -};
...\ No newline at end of file ...\ No newline at end of file
20 +};
21 +
22 +export default {TokenEvent: TokenEvent};
......
1 /* the aim of the transition network is to build a network of promises */ 1 /* the aim of the transition network is to build a network of promises */
2 +import TokenEvent from './tokenevent.js';
2 3
3 -ARCS.TransitionNetwork = function() { 4 +
5 +let TransitionNetwork = function() {
4 // object storing token events (that is to say references to promises) 6 // object storing token events (that is to say references to promises)
5 this.promise = {}; 7 this.promise = {};
6 8
...@@ -16,7 +18,7 @@ ARCS.TransitionNetwork = function() { ...@@ -16,7 +18,7 @@ ARCS.TransitionNetwork = function() {
16 18
17 }; 19 };
18 20
19 -ARCS.TransitionNetwork.build = function(tree, tokenEvents) { 21 +TransitionNetwork.build = function(tree, tokenEvents) {
20 var res; 22 var res;
21 var tmpTN; 23 var tmpTN;
22 var rightTN; 24 var rightTN;
...@@ -27,22 +29,22 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) { ...@@ -27,22 +29,22 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) {
27 if (tokenEvents.hasOwnProperty(tree)) { 29 if (tokenEvents.hasOwnProperty(tree)) {
28 tokenEvent = tokenEvents[tree]; 30 tokenEvent = tokenEvents[tree];
29 } else { 31 } else {
30 - tokenEvents[tree] = tokenEvent = new ARCS.TokenEvent(); 32 + tokenEvents[tree] = tokenEvent = new TokenEvent();
31 } 33 }
32 - var tn = new ARCS.TransitionNetwork(); 34 + var tn = new TransitionNetwork();
33 tn.promise = tokenEvent.promise; 35 tn.promise = tokenEvent.promise;
34 return tn; 36 return tn;
35 } 37 }
36 38
37 - res = ARCS.TransitionNetwork.build(tree[0],tokenEvents); 39 + res = TransitionNetwork.build(tree[0],tokenEvents);
38 var i; 40 var i;
39 for (i=1; i < tree.length; i++) { 41 for (i=1; i < tree.length; i++) {
40 if (tree[i].hasOwnProperty('and')) { 42 if (tree[i].hasOwnProperty('and')) {
41 - rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents); 43 + rightTN = TransitionNetwork.build(tree[i]['and'], tokenEvents);
42 tmpTN = res.and(rightTN); 44 tmpTN = res.and(rightTN);
43 } else { 45 } else {
44 if (tree[i].hasOwnProperty('or')) { 46 if (tree[i].hasOwnProperty('or')) {
45 - rightTN = ARCS.TransitionNetwork.build(tree[i]['or'], tokenEvents); 47 + rightTN = TransitionNetwork.build(tree[i]['or'], tokenEvents);
46 tmpTN = res.or(rightTN); 48 tmpTN = res.or(rightTN);
47 } else { 49 } else {
48 console.warn('[ARCS] Illegal tree'); 50 console.warn('[ARCS] Illegal tree');
...@@ -52,4 +54,6 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) { ...@@ -52,4 +54,6 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) {
52 } 54 }
53 55
54 return res; 56 return res;
55 -};
...\ No newline at end of file ...\ No newline at end of file
57 +};
58 +
59 +export default {TransitionNetwork: TransitionNetwork};
......
1 +const path = require('path');
2 +
3 +module.exports = {
4 + entry: './src/exports.js',
5 + mode: 'none',
6 + output: {
7 + filename: 'arcs.js',
8 + path: path.resolve(__dirname, 'build'),
9 + },
10 + module: {
11 + parser: {
12 + javascript: {
13 + commonjsMagicComments: true
14 + }
15 + }
16 + }
17 +};