npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

finitestatemachine

v2.1.5

Published

Fast and optimized finite state machine. Performance oriented JavaScript.

Downloads

6

Readme

finitestatemachine

A finite state machine built to use as a mechanism to feed other/larger components. JavaScript performance oriented.

Universal module defined to be used with requirejs, node, commonjs, or global scoped if no module loader is used.

  • All files in the dist folder are minified for production use.
  • All files in the src directory are the source code for development use.
  • Packages point at the dist minified code with source maps.
  • nodejs
  • npm install
  • npm install -g gulp

gulp test

Each process is dependent upon the previous. If one fails the build process exits.

  • gulp
  • gulp test (Unit specifications)
  • gulp build (Test, folder clean-ups, minification, source maps, renaming)
  • gulp deploy (Test, build, versioning)

npm: npm install finitestatemachine bower: bower install finitestatemachine

var stateExample = {
    enter: function() {},
    leave: function() {},
    events: {                               // Optional
        'event': 'State',
    },
    transitions: {
        beforeEnter: function() {},         // Optional
        beforeEnterFromStill: function() {},// Optional
        leaveToWalking: function() {},      // Optional
    }
};

var movementStates = {
    'Still': {
        enter: function() {
            console.log('Standing Still.');
        },
        leave: function() {
            console.log('Leaving \'Still\'.');
        },
        transitions: {
            beforeEnter: function() {
                console.log('Transitioning to \'Still\'.');
            }
        },
        events: {
            'move': 'Walking',
            'sprint': 'Running'
        }
    },
    'Walking': {
        enter: function() {
            console.log('Walking.');
        },
        leave: function() {
            console.log('Leaving \'Walking\'.');
        },
        transitions: {
            beforeEnter: function() {
                console.log('Transitioning to \'Walking\'.');
            }
        },
        events: {
            'move': 'Running',
            'sprint': 'Running',
            'relax': 'Still',
            'stop': 'Still'
        }
    },
    'Running': {
        enter: function() {
            console.log('Running.');
        },
        leave: function() {
            console.log('Leaving \'Running\'.');
        },
        transitions: {
            beforeEnterFromWalking: function() {
                console.log('Enter \'Running\' from \'Walking\'.');
            },
            leaveToStill: function() {
                console.log('Leave \'Running\' to \'Still\'.');
            }
        },
        events: {
            'relax': 'Walking',
            'stop': 'Still'
        }
    }
}

var listener1 = function(data) {
    console.log('State change listener!');
    console.log(JSON.stringify(data));
};

var movementStateManager = new FiniteStateMachine(this);

console.log('Adding states.');
movementStateManager.initialize(movementStates, 'Still');

console.log('Initial state: ' + movementStateManager.getCurrentStateId());

console.log('Handle event: move');
movementStateManager.handleEvent('move');

console.log('Handle event: move');
movementStateManager.handleEvent('relax');

console.log('Handle event: move');
movementStateManager.handleEvent('sprint');

console.log('Handle event: move');
movementStateManager.handleEvent('relax');
  • See statemanager package release notes.
  • See statemanager package release notes.
  • Complete rework.
  • Built on top of my StateManager (npm/bower install statemanager). A machine is meant to have managers so this makes more sense and extracts reusable functionality.
  • handleStateEvent() is now handleEvent().
  • Added getPreviousState() to fetch the previous state.
  • Changed global variable name to FiniteStateMachine but kept support for global FSM if one doesn't exist to avoid confilcts.
  • Added ability to reset to the initial state.
  • Added ability to pass data to handleStateEvent(event, data), changeState(state, data), and triggerChangeEvents(event, data). This allows for the data to be distributed to all change event listeners.

    Ex. var listener = function(event){ console.log(event.event); console.log(event.from); console.log(event.to); console.log(event.data); // Can be anything but typcially would be an object. }

  • Fixed sourcemap linking for minified files. This is also fixed as part of the build process to automate proper sourcemap creation and linking.
  • Removed ability for addStates' states parameter to be optional.
  • setCurrentState no longer tiggers the change events. Use triggerChangeEvents to explicity trigger events for the current state.
  • changeState has been deprecated to handleStateEvent.
  • changeState now takes a state as the parameter, changes the current state, and triggers the change events with the event.event data being undefined.
  • Previous state remains undefined until the state changes after initial state.
  • Added getPreviousState() to fetch the previous state.
  • Changed global variable name to FiniteStateMachine but kept support for global FSM if one doesn't exist to avoid confilcts.