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

ivy-stateful

v0.0.2

Published

Simple state machines for Ember.

Downloads

1

Readme

ivy-stateful

Build Status

Simple State Machines for Ember apps, based on Ember Data's DS.Model state machine.

Installation

For Ember CLI >= 0.2.3:

ember install ivy-stateful

For Ember CLI 0.1.5 through 0.2.2:

ember install:addon ivy-stateful

For Ember CLI < 0.1.5:

npm install --save-dev ivy-stateful

Usage

This addon provides a StatefulMixin mixin that makes any Ember.Object into a finite state machine. After mixing it in, you'll need to define a rootState to serve as the root of your state machine, as well as an initialState which will be transitioned into immediately.

Here's the obligatory Vechicle example:

import Ember from 'ember';
import StatefulMixin from 'ivy-stateful/mixins/stateful';

export default Ember.Object.extend(StatefulMixin, {
  initialState: 'parked',

  speed: Ember.computed.readOnly('currentState.speed'),

  rootState: {
    speed: 0,

    parked: {
      enter: function(vehicle) {
        vehicle.takeOffSeatbelt();
      },

      exit: function(vehicle) {
        vehicle.putOnSeatbelt();
      },

      ignite: function(vehicle) {
        vehicle.transitionTo('idling');
      }
    },

    idling: {
      shiftUp: function(vehicle) {
        vehicle.transitionTo('firstGear');
      }
    },

    firstGear: {
      speed: 10,

      idle: function(vehicle) {
        vehicle.transitionTo('idling');
      }
    }
  },

  putOnSeatbelt: function() {
    this.set('seatbeltOn', true);
  },

  takeOffSeatbelt: function() {
    this.set('seatbeltOn', false);
  }
});

You can use send to send events to the current state:

vehicle.get('seatbeltOn') // => false
vehicle.send('ignite');   // puts us in the "idling" state
vehicle.get('seatbeltOn') // => true
vehicle.send('shiftUp');  // puts us in the "firstGear" state
vehicle.get('speed')      // => 10

The receiver (the vehicle in this case) is always the first argument to an event handler, followed by any other arguments passed to send.

If you just want an isolated state machine, ivy-stateful provides one in the form of the StateMachine class.

import StateMachine from 'ivy-stateful/state-machine';

export default StateMachine.extend({
  initialState: 'initial',

  rootState: {
    // ...
  }
});

The StateMachine class is just Ember.Object with StatefulMixin already applied for you.

Running

  • ember server
  • Visit your app at http://localhost:4200.

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.