Jean-Yves Didier

can now bundle things with webpack

......@@ -116,18 +116,18 @@ module.exports = function (grunt) {
concat: {
dist: {
src: [
'src/arcs.js',
'src/component.js',
'src/context.js',
'src/invocation.js',
'src/connection.js',
'src/arcs.js', *
'src/component.js', *
'src/context.js', *
'src/invocation.js', *
'src/connection.js', *
'src/sheet.js',
'src/eventlogicparser.js',
'src/tokenevent.js',
'src/transitionnetwork.js',
'src/statemachine.js',
'src/eventlogicparser.js', *
'src/tokenevent.js', *
'src/transitionnetwork.js', *
'src/statemachine.js', *
'src/application.js',
'src/exports.js'
'src/exports.js' *
],
dest: 'build/arcs.js'
},
......
This diff is collapsed. Click to expand it.
......@@ -12,6 +12,12 @@
],
"author": "Jean-Yves Didier",
"license": "GPL-3.0-or-later",
"dependencies": {
"tracking": ">=1.1.3",
"three": ">=0.131",
"js-aruco": ">=0.1",
"codemirror": ">=5.62"
},
"devDependencies": {
"bower": ">=1.3.9",
"grunt": ">=0.4.5",
......
/******************************************************************************
* Application implementation
* ***************************************************************************/
import Context from './context.js';
import Sheet from './sheet.js';
import Component from './component.js';
/**
* Creates an application runnable by the ARCS engine.
......@@ -11,8 +14,8 @@
* to load all external scripts describing components, instanciate
* all components and then start the application
*/
ARCS.Application = function () {
var context = new ARCS.Context(),
let Application = function () {
var context = new Context(),
sheets = {},
controller = {},
dependencies = [],
......@@ -68,13 +71,13 @@ ARCS.Application = function () {
// then we should work on sheets
sheetList = Object.keys(sheets);
for (i = 0; i < sheetList.length; i++) {
temp = new ARCS.Sheet(context);
temp = new Sheet(context);
temp.import(sheets[sheetList[i]], context);
sheets[sheetList[i]] = temp;
}
ARCS.Component.connect(controller, "requestSheet", self, "setSheet");
ARCS.Component.connect(controller, "requestTermination", self, "finish");
Component.connect(controller, "requestSheet", self, "setSheet");
Component.connect(controller, "requestTermination", self, "finish");
controller.start();
};
......@@ -173,7 +176,7 @@ ARCS.Application = function () {
*
*/
this.import = function (object) {
context = new ARCS.Context(object.context/*.components*/);
context = new Context(object.context/*.components*/);
sheets = object.sheets;
controller = object.controller;
if (controller === undefined) {
......@@ -204,13 +207,14 @@ ARCS.Application = function () {
};
};
ARCS.Application.setDependency = function (app, key) {
Application.setDependency = function (app, key) {
app.setDependency(key);
};
ARCS.Component.create(ARCS.Application);
ARCS.Application.slot("setSheet");
ARCS.Application.slot("finish");
Component.create(Application);
Application.slot("setSheet");
Application.slot("finish");
export default {Application: Application};
......
......@@ -5,18 +5,13 @@
//"use strict";
/**
* Main source: describes all the methods needed by the ARCS engine
* @file
*/
/**
* Defines all elements needed for Augmented Reality Component System
* @namespace
*/
var ARCS = ARCS || {};
/******************************************************************************
* Helper functions to determine environment
......@@ -24,9 +19,12 @@ var ARCS = ARCS || {};
/**
* @return {boolean} true if ARCS is run in a node.js environment
*/
ARCS.isInNode = function () {
return (typeof require === 'function' && require.resolve);
};
*/
export default function isInNode() {
return (typeof process !== 'undefined') &&
(process.release.name.search(/node|io.js/) !== -1);
// return (typeof require === 'function' && require.resolve);
};
......
......@@ -8,7 +8,7 @@
*
* @namespace
*/
ARCS.Component = {
var Component = {
/** Error message */
SourceIsNotComponent : {message : "Source is not a component"},
/** Error message */
......@@ -124,13 +124,13 @@ ARCS.Component = {
var orig, p;
// here we can perform various checks.
if (source.signals === undefined) {
throw ARCS.Component.SourceIsNotComponent;
throw Component.SourceIsNotComponent;
}
if (source.signals[signal] === undefined) {
throw ARCS.Component.UndefinedSignal;
throw Component.UndefinedSignal;
}
if (destination[slt] === undefined) {
throw ARCS.Component.UndefinedSlot;
throw Component.UndefinedSlot;
}
// we must also check if the signals dispose of their own implementation
if (!source.hasOwnProperty('signals')) {
......@@ -170,7 +170,7 @@ ARCS.Component = {
*/
invoke : function (destination, slt, value) {
if (destination[slt] === undefined) {
throw ARCS.Component.UndefinedSlot;
throw Component.UndefinedSlot;
}
......@@ -188,3 +188,5 @@ ARCS.Component = {
}
}
};
export default { Component: Component};
......
/******************************************************************************
* Connection implementation
* ***************************************************************************/
import Component from './component.js';
/**
* Defines a connection between two components
* @param source {object} component at the source
......@@ -9,14 +11,14 @@
* @param slot {string} name of the signal receiving data
* @class
*/
ARCS.Connection = function (source, signal, destination, slot) {
let Connection = function (source, signal, destination, slot) {
/**
* Connects two components as described in this object
* @function ARCS.Connection#connect
*/
this.connect = function () {
try {
ARCS.Component.connect(source, signal, destination, slot);
Component.connect(source, signal, destination, slot);
} catch(e) { console.log(e, source, signal, destination, slot); }
};
/**
......@@ -24,7 +26,7 @@ ARCS.Connection = function (source, signal, destination, slot) {
* described in this object.
*/
this.disconnect = function () {
ARCS.Component.disconnect(source, signal, destination, slot);
Component.disconnect(source, signal, destination, slot);
};
this.getSource = function() {
......@@ -49,7 +51,10 @@ ARCS.Connection = function (source, signal, destination, slot) {
* @param context {object} the context in which this connection takes place.
* @return a connection
*/
ARCS.Connection.cast = function (obj, context) {
return new ARCS.Connection(context.getComponent(obj.source)/*[obj.source].instance*/, obj.signal,
Connection.cast = function (obj, context) {
return new Connection(context.getComponent(obj.source)/*[obj.source].instance*/, obj.signal,
context.getComponent(obj.destination)/*[obj.destination].instance*/, obj.slot);
};
export default { Connection: Connection};
......
import StateMachine from './statemachine.js';
import isInNode from './arcs.js';
/**
* @class ARCS.Context
* @classdesc Class representing a context containing libraries and components
* used by different parts of the framework.
* @param ctx {object} an object representing data for the context.
*/
ARCS.Context = function( ctx ) {
let Context = function( ctx ) {
var components = {};
var constants = {};
var factories = {};
......@@ -17,7 +20,7 @@ ARCS.Context = function( ctx ) {
var instanciateComponents;
factories.StateMachine = ARCS.Statemachine;
factories.StateMachine = Statemachine;
if (ctx !== undefined) {
......@@ -43,9 +46,9 @@ ARCS.Context = function( ctx ) {
var loadDataFile =async function(fileName) {
var dataPromise ;
if (ARCS.isInNode()) {
if (isInNode()) {
return new Promise(function (resolve, reject) {
var dep = require(fileName);
var dep = require(/* webpackIgnore: true */fileName);
if (dep !== undefined) {
resolve(dep);
} else {
......@@ -62,7 +65,7 @@ ARCS.Context = function( ctx ) {
var i;
// we will use different instances of require either the one of node
// or the one from require.js
ARCS.Context.currentContext = self;
Context.currentContext = self;
var res=[];
for(i=0; i < libraries.length; i++) {
......@@ -125,7 +128,7 @@ ARCS.Context = function( ctx ) {
this.loadLibrary = function (libName, cbFunction) {
var libUrl = libName, libActualName = libName;
ARCS.Context.currentContext = self;
Context.currentContext = self;
if (typeof libName !== "string") {
libActualName = libName.name;
libUrl = libName.url;
......@@ -135,11 +138,11 @@ ARCS.Context = function( ctx ) {
libraries.push(libActualName);
}
// TODO promisify call to cbFunction
return import(libUrl).then( function(module) {
return import(/* webpackIgnore: true */libUrl).then( function(module) {
// TODO insert here component factories
for (p in module.default) {
if (module.default.hasOwnProperty(p)) {
ARCS.Context.currentContext.setFactory(p,module.default[p]);
Context.currentContext.setFactory(p,module.default[p]);
}
}
......@@ -309,7 +312,7 @@ ARCS.Context = function( ctx ) {
/** pseudo-singleton to current context being used */
ARCS.Context.currentContext = null;
Context.currentContext = null;
export default {Context: Context};
......
......@@ -36,7 +36,7 @@ WS = [ \r\n\t]*
******************************************************************************/
ARCS.EventLogicParser = (function() {
let EventLogicParser = (function() {
/*
* Generated by PEG.js 0.8.0.
*
......@@ -661,3 +661,5 @@ ARCS.EventLogicParser = (function() {
parse: parse
};
})();
export default { EventLogicParser: EventLogicParser};
......
// no longer needed with the use of imports
export { ARCS as default};
\ No newline at end of file
import Component from './component.js';
import StateMachine from './statemachine.js';
import isInNode from './arcs.js';
import Context from './context.js';
import Invocation from './invocation.js';
import Connection from './connection.js';
import Sheet from './sheet.js';
import Application from './application.js';
export default {
Component: Component,
isInNode : isInNode,
StateMachine: StateMachine,
Context: Context,
Invocation: Invocation,
Connection: Connection,
Sheet: Sheet,
Application: Application
};
......
......@@ -8,7 +8,8 @@
* @param value {mixed} value passed to the invoked slot
* @constructor
*/
ARCS.Invocation = function (destination, slot, value) {
let Invocation = function (destination, slot, value) {
this.getDestination = function () {
return destination;
};
......@@ -36,19 +37,19 @@ ARCS.Invocation = function (destination, slot, value) {
* @param context {object} the context in which this invocation takes place.
* @return an invocation
*/
ARCS.Invocation.cast = function (obj, context) {
Invocation.cast = function (obj, context) {
if (obj.value !== undefined) {
var component = context.getComponent(obj.destination);
if (component === undefined) {
console.error("[ARCS] Destination ",obj.destination, " is undefined");
}
return new ARCS.Invocation(component, obj.slot, obj.value);
return new Invocation(component, obj.slot, obj.value);
}
// this one looks odd, seems there is a failure in the logic.
if (obj.ref !== undefined) {
return new ARCS.Invocation(context.getComponent(obj.destination), obj.slot, context.getConstant(obj.ref));
return new Invocation(context.getComponent(obj.destination), obj.slot, context.getConstant(obj.ref));
}
};
......@@ -61,6 +62,8 @@ ARCS.Invocation.cast = function (obj, context) {
};*/
ARCS.Invocation.PRE_CONNECTION = 0;
ARCS.Invocation.POST_CONNECTION = 1;
ARCS.Invocation.CLEAN_UP = 2;
\ No newline at end of file
Invocation.PRE_CONNECTION = 0;
Invocation.POST_CONNECTION = 1;
Invocation.CLEAN_UP = 2;
export default { Invocation: Invocation};
......
/******************************************************************************
* Sheet implementation
* ***************************************************************************/
import Context from './context.js';
import Invocation from './invocation.js';
import Connection from './connection.js';
/**
* Constructs a sheet
* @param context {object} a context object
......@@ -11,8 +15,8 @@
* and a set of {@link ARCS.Connection}. Sheets have two high level operations:
* activation and deactivation.
*/
ARCS.Sheet = function (ctx /*context*/) {
var context = new ARCS.Context();
let Sheet = function (ctx /*context*/) {
var context = new Context();
var preconnections = [], postconnections = [], cleanups = [], connections = [],
invokePreconnections, invokePostconnections, invokeCleanups,
connect, disconnect, getComponentName,
......@@ -74,14 +78,14 @@ ARCS.Sheet = function (ctx /*context*/) {
};
this.addPreConnection = function (obj) {
var pre = ARCS.Invocation.cast(obj, context);
var pre = Invocation.cast(obj, context);
pre.id = preCount++;
preconnections.push(pre);
return pre.id;
};
this.addPostConnection = function (obj) {
var post = ARCS.Invocation.cast(obj, context);
var post = Invocation.cast(obj, context);
post.id = postCount++;
postconnections.push(post);
return post.id;
......@@ -89,14 +93,14 @@ ARCS.Sheet = function (ctx /*context*/) {
this.addCleanup = function (obj) {
var cleanup = ARCS.Invocation.cast(obj, context);
var cleanup = Invocation.cast(obj, context);
cleanup.id = cleanCount++;
cleanups.push(cleanup);
return cleanup.id;
};
this.addConnection = function (obj) {
var connection = ARCS.Connection.cast(obj, context);
var connection = Connection.cast(obj, context);
connection.id = connCount++;
connections.push(connection);
return connection.id;
......@@ -187,7 +191,7 @@ ARCS.Sheet = function (ctx /*context*/) {
var cacheConnectionsInvocations = function(object) {
var i = 0, castInvocation = ARCS.Invocation.cast, castConnection = ARCS.Connection.cast;
var i = 0, castInvocation = Invocation.cast, castConnection = Connection.cast;
for (i = 0; i < object.preconnections.length; i++) {
preconnections.push(castInvocation(object.preconnections[i], context));
}
......@@ -208,7 +212,7 @@ ARCS.Sheet = function (ctx /*context*/) {
*/
this.import = function (object) {
if (object.hasOwnProperty("context")) {
context = new ARCS.Context(object.context);
context = new Context(object.context);
context.setParent(ctx);
}
......@@ -267,3 +271,5 @@ ARCS.Sheet = function (ctx /*context*/) {
//console.log("setting parent");
context.setParent(ctx);
};
export default {Sheet: Sheet};
......
/******************************************************************************
* Statemachine implementation
* ***************************************************************************/
import Component from './component.js';
import TransitionNetwork from './transitionnetwork.js';
import EventLogicParser from './eventlogicparser.js';
/**
* Describes a statemachine
* @param obj {object} an object describing a state machine. If obj is empty then the statemachine is empty
* @class
*/
ARCS.Statemachine = new ARCS.Component.create(function (obj) {
let Statemachine = new Component.create(function (obj) {
// dynamic construction: properties are initial state that have properties
// that are tokens and value that are the final state
var initial = "", final = "", transitions = {}, currentState = "", self= this;
......@@ -35,7 +40,7 @@ ARCS.Statemachine = new ARCS.Component.create(function (obj) {
tokenEvents = {};
for (t in transitions[s]) {
if (transitions[s].hasOwnProperty(t)) {
network = ARCS.TransitionNetwork.build(astTokens[t],tokenEvents).promise;
network = TransitionNetwork.build(astTokens[t],tokenEvents).promise;
network.then(
function() {
var token;
......@@ -164,3 +169,4 @@ ARCS.Statemachine = new ARCS.Component.create(function (obj) {
['requestSheet', 'requestTermination']
);
export default { StateMachine: StateMachine};
......
// this class creates a promise that can be deferred as long as necessary.
// calls to accept or reject will solve the promise.
ARCS.TokenEvent = function() {
let TokenEvent = function() {
var refResolve;
var refReject;
......@@ -17,4 +17,6 @@ ARCS.TokenEvent = function() {
this.abort = function() {
refReject();
};
};
\ No newline at end of file
};
export default {TokenEvent: TokenEvent};
......
/* the aim of the transition network is to build a network of promises */
import TokenEvent from './tokenevent.js';
ARCS.TransitionNetwork = function() {
let TransitionNetwork = function() {
// object storing token events (that is to say references to promises)
this.promise = {};
......@@ -16,7 +18,7 @@ ARCS.TransitionNetwork = function() {
};
ARCS.TransitionNetwork.build = function(tree, tokenEvents) {
TransitionNetwork.build = function(tree, tokenEvents) {
var res;
var tmpTN;
var rightTN;
......@@ -27,22 +29,22 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) {
if (tokenEvents.hasOwnProperty(tree)) {
tokenEvent = tokenEvents[tree];
} else {
tokenEvents[tree] = tokenEvent = new ARCS.TokenEvent();
tokenEvents[tree] = tokenEvent = new TokenEvent();
}
var tn = new ARCS.TransitionNetwork();
var tn = new TransitionNetwork();
tn.promise = tokenEvent.promise;
return tn;
}
res = ARCS.TransitionNetwork.build(tree[0],tokenEvents);
res = TransitionNetwork.build(tree[0],tokenEvents);
var i;
for (i=1; i < tree.length; i++) {
if (tree[i].hasOwnProperty('and')) {
rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents);
rightTN = TransitionNetwork.build(tree[i]['and'], tokenEvents);
tmpTN = res.and(rightTN);
} else {
if (tree[i].hasOwnProperty('or')) {
rightTN = ARCS.TransitionNetwork.build(tree[i]['or'], tokenEvents);
rightTN = TransitionNetwork.build(tree[i]['or'], tokenEvents);
tmpTN = res.or(rightTN);
} else {
console.warn('[ARCS] Illegal tree');
......@@ -52,4 +54,6 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) {
}
return res;
};
\ No newline at end of file
};
export default {TransitionNetwork: TransitionNetwork};
......
const path = require('path');
module.exports = {
entry: './src/exports.js',
mode: 'none',
output: {
filename: 'arcs.js',
path: path.resolve(__dirname, 'build'),
},
module: {
parser: {
javascript: {
commonjsMagicComments: true
}
}
}
};