0.3.1 • Published 1 year ago

statorade v0.3.1

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

Statorade

Statorade is an event-driven state machine with many protections in place to prevent you from shooting yourself in the foot, with very helpful and descriptive error handling in place.

At it's core, it is as basic as it gets: the only way to change state is by triggering an event. States define ways that they handle events, most commonly in order to change states.

$ npm install --save statorade

const Statorade = require('statorade');


const trafficLight = new Statorade();


// Define the states.

trafficLight.addState('greenLight', {
  // Entry point for 'greenLight' state.
  onEnter: () => console.log('Entered greenLight.'),
  // Events the 'greenLight' state will react to.
  handlers: {
    REQUEST_TURN_YELLOW: (changeState) => changeState('yellowLight')
  }
});

trafficLight.addState('yellowLight', {
  onEnter: () => console.log('Entered yellowLight.'),
  handlers: {
    REQUEST_TURN_RED: (changeState) => changeState('redLight')
  }
});

trafficLight.addState('redLight', {
  onEnter: () => console.log('Entered redLight.'),
  handlers: {
    REQUEST_TURN_GREEN: (changeState) => changeState('greenLight')
  }
});


// Initialize the state machine.
trafficLight.init('redLight');


// Fire an event. State will change to green, because the handler in the redLight
// state (the state we have initialized to) is defined to do so.
trafficLight.handle('REQUEST_TURN_GREEN');
0.3.0

1 year ago

0.3.1

1 year ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.0.11

6 years ago

0.1.0

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago