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

miso.storyboard

v0.0.1

Published

Storyboard is a state management library that makes orchestrating the flows of your application easy using storyboards.

Downloads

7

Readme

Miso.Storyboard

Miso.Storyboard is a control flow library for organising your interactive content as scenes, making it easy to handle complex transitions and manage state. Each scene can have handlers for how it should act when it becomes the active scene and when it is no longer the active scene. Storyboards nest, in that every single scene can actually be its own complex storyboard.

 var app = new Miso.Storyboard({
  initial : 'unloaded',
  scenes : {
    'unloaded' : {
      exit : function() {
        console.log('exiting of unloaded complete');
      }
    },
    'loaded' : {
      enter : function() {
        console.log('entering the loaded scene');
      }
    }
  }
});

app.start();
app.to('loaded');

Handling Asynchronous transitions

Every scene has two handlers enter and exit, which are called when the scene is entered and exited respectively. Both of these handlers can be made to be asynchronous, making it possible to use them to handle complex animated transions in a relatively simple manner. Handlers are made asynchronous by calling a this.async in the handler. This will return a function when can be called when the final callback is complete, this is called the resolution function. The to function will in turn then return a deferred that will not resolve (or reject) until all the handlers involved are complete.

var app = new Miso.Storyboard({
  initial : 'unloaded',
  scenes : {
    'unloaded' : {
      exit : function() {
        var done = this.async();
        $('#loading').fadeOut(500, function() {
          done();
        });
      }
    },
    'loaded' : {
      enter : function() {
        var done = this.async();
        $('#mainscreen').fadeIn(500, function() {
          done();
        });
      }
    }
  }
});

app.start();
var loadingComplete = app.to('loaded');
loadingComplete.done(function() {
  console.log('app now loaded');
});
var app = new Miso.Storyboard({
  initial : 'unloaded',
  scenes : {
    unloaded : {},
    loaded : {}
  }
});

app.start();
var complete = app.to('loaded');
complete.done(function() {
  console.log('transition complete!');
});

It is also possible to pass in your own deferred to the to method, along with an array of arguments that will be passed to the exit and enter handlers.

var app = new Miso.Storyboard({
  initial : 'unloaded',
  scenes : {
    unloaded : {},
    loaded : {
      enter : function(id) {
        console.log('user ID is '+id);
      }
    }
  }
});

var complete = _.Deferred();
complete.done(function() { 
  console.log('done!');
});

app.start();
app.to('overview', [userID], complete);

Conditional movement between scenes

The enter and exit handlers can also be used to control whether it's possible to move between scenes. If a handler returns false, or if it is asynchronous, passes false to its resolution function the transition will be rejected. This can be managed inside handlers or by binding functions to the fail method of the deferred returned by to.

var app = new Miso.Storyboard({
  initial : 'unloaded',
  scenes : {
    unloaded : {
      exit : function() {
        var done = this.async();

        data.remoteFetch({
          error : function() {
            // data fetch failed? don't continue transitioning.
            done(false)
          },
          success : function() {
            // data fetch succeeded, continue transitioning.
            done();
          }
        });
      }
    },
    loaded : {
      enter : function() {
        return false;
      }
    }
  }
});

app.start();
var complete = app.to('loaded');
complete.fail(function() {
  console.log('transition failed!');
});

Organising your code

You can pass additional methods to the definitions scenes in your storyboard to help structure your code in a more logical manner and break down big functions.

var app = new Miso.Storyboard({
  initial : 'unloaded',
  scenes : {
    unloaded : {
      loadData : function() { ... },
      displayLoadingScreen : function() { ... },
      enter : function() {
        this.displayLoadingScreen();
        this.loadData();
      }
    },
    loaded : {}
  }
});
app.start();

Nesting Storyboards

It is also possible to nest Miso Storyboards inside each other, making it possible to control state at each level of your code. For example if you had a slideshow inside a larger storyboard, it could in turn be its own storyboard, with each slide being a scene, with handlers defining each move between slides in a custom manner.

var walkthrough = new Miso.Scene({
  initial : 'one',
  scenes : {
    one : {},
    two : {},
    three : {}
  }
});

var app = new Miso.Scene({
  inital 'unloaded',
  scenes : {
    unloaded : {},
    walkthrough : loadedScene
  }
});

Contributing

To build Scene you'll need npm, node.js's package management system and grunt

npm install

To build Miso.Storyboard, call

grunt

from the project root.