pf

portable-fsm

Simple, node/browser compatible generic FSM system

Showing:

Popularity

Downloads/wk

1

GitHub Stars

2

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

portable-fsm

Simple, node/browser compatible generic FSM system

Examples

var
    FSM = require('portable-fsm'),
    fsm = new FSM();

fsm.debug = true;

fsm.addState({
    Start: {
        init: 'InProgress'
    },
    InProgress: {
        abort: 'Cancelled',
        complete: 'Done'
    }
});

fsm
    .on('InProgress', function() {
        console.log('Progress start');
        if(Math.random() > 0.5) {
            console.log(' -> Aborting...');
            fsm.consume('abort');
        } else {
            console.log(' -> Completing...');
            fsm.consume('complete');
        }
    }, function() {
            console.log('Progress end');
    })
    .on('Cancelled', function() {
        console.log('Operation cancelled');
    })
    .on('Done', function() {
        console.log('Operation completed');
    });

fsm
    .when('complete', function() {
        console.log('ALL DONE!');
    })
    .when('abort', function() {
        console.log('ABORT! ABORT! ABORT!');
    });

fsm.consume('init');

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial