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

@adludio/fsm

v3.0.0

Published

Finite state machines over erx

Downloads

13

Readme

fsm

A finite state machine using erx

Overview and structure

Our FSM is responsible for maintaining current state and triggering navigation to other states. It is basically a description of the user journey during the running of an adunit; what happens and when it happens. When initialising the machine, the FSM takes two parameters:

  • Triggers
  • States

The Triggers object is a set of conditions that determine whether or not the machine will navigate to the next state. (when/how) The States object is what happens while in each respective state. (what)

As a wise man once said; ”Watch this” (triggers) ”Do that” (states)

Trigger example:

"start": {
  "paint:start:reveal-layer": () => "revealing"
},
"win": {...},
...

When in the start state, if a "paint:start:reveal-layer" event is "sent" to the machine, then machine.goto("revealing") state (and then run that "revealing" state function)

State example:

"start": {
  animations: (m, state) => {
    let rep = m.whileIn(anim.start(state), "start");
    return update.stream(state.events, rep);
  },
  onEnter: () => {},
  onExit: () => {}
},
"win": {...},
...

When in "start" state, "onEnter" and then "animations" functions are run. When leaving "start" state, the "onExit" function is run. States are broken down into three parts:

  • animations
  • onEnter
  • onExit

The animations function is used for determining which animations will play in that state. The update.stream function is thennable, allowing you to chain animations if you please. An onAnimationEvent is pushed to cyan's eventBus automatically after every animation has concluded, which may or may not be caught with an appropriate trigger.

The onEnter function is used to "set-up" the scene for the next state and ensure that code can be run before the animations even occur. Examples of how this could be useful include, adding a node that you want to animate in the state, or adding a component to a node (in reality, adding a nodeId to the systems object) so that the user can interact with that node and trigger a state change.

The onExit function is used for clearing up unwanted ... stuff; nodes, components, clearing Timeouts etc. It is fired whenever you exit the attached state.

Old FSM 1.01 -> New ?

A small but significant refactor of FSM was required in order to increase the flexibility in order to deal with edge cases and ensure predictable behaviour, in preparation for the creation of a new Studio product harnessing a new programmatically generated json structure (cyan-json). An instance of FSM was previously constructed with 3 props; new FSM(states(triggers), transitions, entries).

First of all "states" was renamed to "triggers" and "entries" renamed to "states" to better describe their use, and the underlying logic tweaked to allow for passing of state events, or the state names themselves.

Secondly the "transitions" object was merged with entries and made specific to a single state in the form of hooks (onEnter, onExit), rather than being a function that is called when navigating between two states.

Third, code that would normally be run in the entry function could be split in terms of the concerns into animations (that must happen during the state) and everything else. This nicely provides a standard so that states correspond indirectly to the animations inside them. (That was the worst sentence ever)

What we need to think about during the upgrading process

  • Dev builders should be encouraged to use update.goTo() instead of m.goto() to avoid having stale data in the next state.
  • Dev builders need to adhere to new data structure, and should be encouraged to use animations in animations object, and to make use of the hooks to prepare and cleanup the scene.
  • Dev builds currently use asterisk for cyan dependency (latest), and so any cyan adunits built in the past would use latest version...does this mean latest version always has to backwards compatible? Are we gonna create a separate tag and further increase complexity regarding which cyan being used depending on the application? ...