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

mistic

v0.1.3

Published

A state machine.

Downloads

11

Readme

mistic

A simple state machine.

File size: 7176 bytes. Supported platforms: browser and server. Supported language versions: ES5+.

Supports heirarchical states.

Note: When using mistic server-side, its constituent files currently need to be referred to directly. You will also need to install the following modules: mixx, niid, partial-application, kwire, noopaam, and sprest.

Example

var state = require('./mistic/state');
var stateful = require('./mistic/stateful');
var Transition = require('./mistic/transition');
var StateMachine = require('./mistic/machine');

// Your object type to make stateful.
function Bug(title) {
	this.title = title;
	this.assigneeEmail = null;
}

// Define the possible bug states.
var bugState = {
	open: Object.create(state, {
		value: { value: 'OPEN' }
	}),
	assigned: Object.create(state, {
		value: { value: 'ASSIGNED' }
	}),
	resolved: Object.create(state, {
		value: { value: 'RESOLVED' }
	})
};

// Define a wrapper around your object (decorator pattern).
// You can also make the object stateful directly.
function BugStateful(bug, machine) {
    this.bug = bug;
    this.machine = machine;
}

BugStateful.prototype = Object.create(stateful);

BugStateful.prototype.open = function() {
    return this.triggerTransition({targetState: bugState.open});
};

BugStateful.prototype.assign = function(assigneeEmail) {
    return this.triggerTransition({targetState: bugState.assigned}, assigneeEmail);
};

BugStateful.prototype.resolve = function() {
    return this.triggerTransition({targetState: bugState.resolved});
};

// Define the valid transitions for your stateful object.
var open = new Transition({
	startStates: [state.open],
	endStates: [state.open],
});

var assign = new Transition({
	startStates: [state.open, state.assigned],
	endStates: [state.assigned],
	transitionAction: function (options, assigneeEmail) {
		options.statefulObject.bug.assigneeEmail = assigneeEmail;
	}
});

var resolve = new Transition({
	startStates: [state.assigned],
	endStates: [state.resolved]
});

// Instantiate the state machine.
machine = new StateMachine({
    name: 'bug-tracker',
    transitions: [open, assign, resolve],
    initialState: state.open,
});

var bug = new Bug('bug title');
var stateful = new BugStateful(bug, machine);

// Trigger a state transition.
var result = stateful.assign(assigneeEmail);

// Transition is successful and affects the object.
expect(stateful.currentState.value === 'ASSIGNED').toBe(true);
expect(stateful.bug.assigneeEmail).toBe(assigneeEmail);

License & Copyright

This software is released under the MIT License. It is Copyright 2015, Ben Aston. I may be contacted at [email protected].

How to Contribute

Pull requests including bug fixes, new features and improved test coverage are welcomed. Please do your best, where possible, to follow the style of code found in the existing codebase.