Jean-Yves Didier

solved 'and' bug on statemachine; preparing for publication of next version

This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
{
"name": "arcsjs",
"version": "0.9.6",
"version": "0.9.7",
"description": "Augmented Reality Component System in web browser and node environment",
"homepage": "http://arcs.ibisc.fr",
"repository": {
......
......@@ -69,8 +69,18 @@ let Connection = function (source, signal, destination, slot) {
* @return a connection
*/
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);
if (obj.from !== undefined) {
let components = obj.from.split('.');
obj.source = components[0];
obj.signal = components[1];
}
if (obj.to !== undefined) {
let components = obj.to.split('.');
obj.destination = components[0];
obj.slot = components[1];
}
return new Connection(context.getComponent(obj.source), obj.signal,
context.getComponent(obj.destination), obj.slot);
};
......
......@@ -26,21 +26,24 @@ let Context = function( ctx ) {
if (ctx !== undefined) {
libraries = ctx.libraries;
var p;
for (p in ctx.components) {
Object.assign(components,ctx.components);
Object.assign(constants, ctx.constants);
//var p;
/*for (p in ctx.components) {
if (ctx.components.hasOwnProperty(p)) {
components[p] = ctx.components[p];
}
}
*/
if (ctx.constants !== undefined) {
/*if (ctx.constants !== undefined) {
for (p in ctx.constants) {
if (ctx.constants.hasOwnProperty(p)) {
constants[p] = ctx.constants[p];
}
}
}
}*/
}
......@@ -75,6 +78,10 @@ let Context = function( ctx ) {
return Promise.all(res);
};
// TODO if, one day, we want to instanciate a component with several components,
// it would be done in two phases:
// 1/ new cmp = new XXX()
// 2/ XXX.apply(cmp, [...])
var instanciateComponents = async function() {
var p, promises=[];
for (p in components) {
......@@ -288,14 +295,17 @@ let Context = function( ctx ) {
// this stunt seems better than using
// Object.setPrototypeOf or using [object].__proto__
// due to javascript engine optimizations
var newObj = Object.create(proto);
var p ;
// TODO would it be better to use the 2nd version of create
//var newObj = Object.create(proto);
let newObj = Object.create(proto, obj);
/*var p ;
for (p in obj) {
if (obj.hasOwnProperty(p)) {
newObj[p] = obj[p];
}
}
}*/
return newObj;
};
......
......@@ -52,12 +52,18 @@ let Invocation = function (destination, slot, value) {
* @return an invocation
*/
Invocation.cast = function (obj, context) {
if (obj.call !== undefined) {
let components = obj.call.split('.');
obj.destination = components[0];
obj.slot = components[1];
}
let component = context.getComponent(obj.destination);
if (component === undefined) {
console.error("[ARCS] Destination ",obj.destination, " is undefined");
}
if (obj.value !== undefined) {
return new Invocation(component, obj.slot, obj.value);
}
......
......@@ -15,7 +15,7 @@ const OrNode = function(tokenEvents, left, right) {
const AndNode = function(tokenEvents, left, right) {
this.eval = function(tokenEvents) {
return left.eval(tokenEvents) && left.eval(tokenEvents);
return left.eval(tokenEvents) && right.eval(tokenEvents);
};
};
......
......@@ -62,6 +62,7 @@ let signalHandler = function(chai, utils) {
} else {
obj[slot].call(obj);
}
/*self.expect(handler.triggered).to.equal(true);*/
self.assert(
handler.triggered,
"expected #{this} to emit signal "+signal.name,
......@@ -79,18 +80,23 @@ let signalHandler = function(chai, utils) {
}
if (signal.options.hasOwnProperty("withArgs") && signal.options.withArgs.length > 0) {
let args = signal.options.withArgs;
let cmp = (args.length === handler.data.length);
/*let dcmp = false;
console.log(args,handler.data,args.length, handler.data.length, cmp, dcmp);
console.log(self.assert);*/
self.assert(
args.length === handler.data.length,
cmp,
//handler.data.length === 0,
"expected #{this} to have " + args.length + " arguments",
"expected #{this} not to have " + args.length + " arguments"
);
for(let i=0; i < args.length; i++) {
for(let i=0; i < handler.data.length; i++) {
new chai.Assertion(handler.data[i]).to.deep.equal(
args[i],
"expected #{this} to equal \"" + args[i] +"\""
);
}
}
}
});
});
......@@ -320,6 +326,30 @@ describe('statemachine', function() {
sm.start();
expect(sm).to.emit('requestSheet', { withArgs: ["end"]}).when('b');
});
it ('should not trigger a transition when only one event is fired (version a)', function() {
let sm = new ARCS.StateMachine({
initial: "start",
transitions: {
start: { "a&b" :"end"}
}
});
sm.start();
expect(sm).to.not.emit('requestSheet', { withArgs: ["end"]}).when('a');
});
it ('should not trigger a transition when only one event is fired (version b)', function() {
let sm = new ARCS.StateMachine({
initial: "start",
transitions: {
start: { "a&b" :"end"}
}
});
sm.start();
expect(sm).to.not.emit('requestSheet', { withArgs: ["end"]}).when('b');
});
it ('should trigger a transition when two events are fired', function() {
let sm = new ARCS.StateMachine({
......