Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

backbone-machina

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-machina

machina.Fsm dressed as a fourth Backbone pillar next to Model, View and Router

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

backbone-machina

machina.Fsm dressed as a fourth Backbone pillar next to Model, View and Router.

pipeline status latest version on npm code hosted on GitLab issue tracker on GitLab author: Julian Gonggrijp license text made with CoffeeScript changelog

Quickstart

$ npm i backbone-machina
import BackboneFsm from 'backbone-machina';

const someFsm = new BackboneFsm({...});
someFsm.on('enter:someState', (fsm, action) => {...});
someFsm.on('exit:anotherState', (fsm, action) => {...});

BackboneFsm is the default and only export of this package. It extends both machina.Fsm and Backbone.Events. In addition, it emits enter:stateName and exit:stateName events so you can hook into the behaviour of your FSM in the same way as you would do with Backbone.Model et al. This fully describes the API.

New in version 1.1.0: BackboneFsm is truly 100% compatible with both interfaces it extends. You can use '*' and 'all' interchangeably as wildcards when subscribing to events. machina.Fsm’s eventListeners option is supported as well. As a result, BackboneFsm can now be used in hierarchical settings as a drop-in replacement for machina.Fsm.

Why you should use this

If you are using Backbone, then you already have some powerful tools at your disposal for managing (changes of) state:

  • Model and Collection for the state of your data;
  • View for the state of your document;
  • Router for the state of the URL that is shown in the browser.

There is fourth type of state, however, that none of these classes captures very well. I would call this contextual state. Examples of contextual state include

  • whether the user has authenticated or not;
  • whether a search is blank, being edited, submitted, successful or unsuccessful;
  • whether there is still a connection with the backend.

Finite state machines are ideal for managing contextual state. There are many libraries out there that provide finite state machines, but I believe machina is the most declarative and also the most powerful of them all. To my knowledge, backbone-machina is the first library that marries Backbone and machina. Head to http://machina-js.org for some impressive examples of what a machina.Fsm can do!

Head over to the wiki for some philosophy on Backbone project organization, which also discusses the place of BackboneFsm in your project.

Keywords

FAQs

Package last updated on 10 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc