Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including state-manager with all npm packages installed. Try it out:

var stateManager = require("state-manager")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

state-manager v1.0.1

versatile state managing abstraction

state-manager

versatile state managing abstraction

usage

    /* ============ example #1 ============ 
        basic usage
    =====================================*/

    var StateManager = require('state-manager')
    var myStates = StateManager.create()
        .add('state1', {
            create: function () {
                console.log('hello from state 1')
            }
        })
        .add('state2', {
            create: function () {
                console.log('hello from state 2')
            }
        })

    // to activate a state
    myStates.go('state1')
    
    // some time later perhaps from within state1 itself
    myState.go('state2')


    /* ============ example #2 ============ 
        optional state methods
    =====================================*/

    var StateManager = require('state-manager')
    var myStates = StateManager.create()
        .add('state1', {
            preload: function (done) {
                // call done() to move onto 'create'
                done()
            },
            create: function () {
            },
            destroy: function () {
                // called when you switch to another state
            }
        })


    /* ============ example #3 ============ 
        pattern #1
    =====================================*/
    
    var StateManager = require('state-manager')
    var myStates = StateManager.create()
        .add('state1', state1())
    
    function state1 () {
        var foo = 123
        return {
            create: function () {
                console.log(foo)
            }
        }
    }

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free