Skip to content

Releases: gausby/bon-etat

v3.0.0

Choose a tag to compare

@gausby gausby released this 07 Oct 17:43

Breaking change: The state names in transition events are now written in capital case.

var FSM = require('bon-etat');
var Door = FSM({
    opened: {
        close: 'closed'
    },
    closed: {
        open: 'opened',
        break: 'broken beyond repair'
    },
    'broken beyond repair': {}
});

When going from the closed-state to the broken beyond repair state, the event would previously be written frontDoor.on('goingFromClosedToBroken beyond repair', function() {}); now it should be written as frontDoor.on('goingFromClosedToBrokenBeyondRepair', function() {});.

var frontDoor = new Door();

frontDoor.on('goingFromClosedToBrokenBeyondRepair', function() {
    console.log('call the repair man!');
});

frontDoor.change('close');
frontDoor.change('break');
// output: 'call the repair man!'

Also, when a state machine enters a state with no possible states to transition to (ie, the 'broken beyond repair' state in the previous example), it will emit final (function(from)), if the state machine receives further stimulus it will emit inFinal (function(state)).

var backDoor = new Door();
backDoor.on('final', function(from) {
    console.log('we got here from %s', from);
});

backDoor.on('inFinal', function(state) {
    console.log('the door is still %s', state);
});

backDoor.change('close');
backDoor.change('break');
// output 'we got here from closed'
backDoor.change('open');
// output 'the door is still broken beyond repair'

v2.0.0

Choose a tag to compare

@gausby gausby released this 01 Oct 17:55

Bon-état will now generate whole objects instead of just the change function (as the previous version did). This should make it possible, and efficient, to have thousands of the same state machine running at the same time.

var FSM = require('bon-etat');
var turnstile = {
    locked: {
        coin: 'unlocked',
        push: 'locked'
    },
    unlocked: {
        push: 'locked',
        coin: 'unlocked'
    }
}

var Turnstile = FSM(turnstile);

var entrance = new Turnstile();
console.log(entrance.state); // 'locked'

The state that the instance should be initialised with can be passed in during initialisation, ie. var entrance = new Turnstile('unlocked'); would initialise the instance in unlocked state.

The before functions has been removed. They did not seem necessary, as other transition events carried that information in their name or arguments.

Finally, we are now able to print the generated code for a state machine, by passing the definition to bonEtat.toString:

var bonEtat = require('bon-etat');
var turnstile = {
    locked: {
        coin: 'unlocked',
        push: 'locked'
    },
    unlocked: {
        push: 'locked',
        coin: 'unlocked'
    }
};

console.log(bonEtat.toString(turnstile)); // print the generated code

Initial release

Choose a tag to compare

@gausby gausby released this 15 Sep 11:16
1.0.0

Initial commit