All Projects → hopsoft → State_jacket

hopsoft / State_jacket

Licence: mit
A simple & intuitive state machine

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to State jacket

Transitions
A lightweight, object-oriented finite state machine implementation in Python with many extensions
Stars: ✭ 4,082 (+81540%)
Mutual labels:  state-machine
State Machine Cat
write beautiful state charts 🙀
Stars: ✭ 509 (+10080%)
Mutual labels:  state-machine
Little State Machine
📠 React custom hook for persist state management
Stars: ✭ 654 (+12980%)
Mutual labels:  state-machine
Qpc
QP/C real-time embedded framework/RTOS for embedded systems based on active objects (actors) and hierarchical state machines
Stars: ✭ 379 (+7480%)
Mutual labels:  state-machine
Tinyfsm
A simple C++ finite state machine library
Stars: ✭ 452 (+8940%)
Mutual labels:  state-machine
Sml
SML: C++14 State Machine Library
Stars: ✭ 540 (+10700%)
Mutual labels:  state-machine
Pvm
Build workflows, activities, BPMN like processes, or state machines with PVM.
Stars: ✭ 348 (+6860%)
Mutual labels:  state-machine
Stately.js
Stately.js is a JavaScript based finite-state machine (FSM) engine for Node.js and the browser.
Stars: ✭ 785 (+15600%)
Mutual labels:  state-machine
Aasm
AASM - State machines for Ruby classes (plain Ruby, ActiveRecord, Mongoid, NoBrainer, Dynamoid)
Stars: ✭ 4,474 (+89380%)
Mutual labels:  state-machine
Django River
Django workflow library that supports on the fly changes ⛵
Stars: ✭ 609 (+12080%)
Mutual labels:  state-machine
React
🔼 UI-Router for React
Stars: ✭ 386 (+7620%)
Mutual labels:  state-machine
Fsm As Promised
A finite state machine library using ES6 promises
Stars: ✭ 446 (+8820%)
Mutual labels:  state-machine
Copycat
A novel implementation of the Raft consensus algorithm
Stars: ✭ 551 (+10920%)
Mutual labels:  state-machine
Machinery
State machine thin layer for structs (+ GUI for Phoenix apps)
Stars: ✭ 367 (+7240%)
Mutual labels:  state-machine
Rxautomaton
🤖 RxSwift + State Machine, inspired by Redux and Elm.
Stars: ✭ 711 (+14120%)
Mutual labels:  state-machine
Harvest
🌾 Harvest: Apple's Combine.framework + State Machine, inspired by Elm.
Stars: ✭ 352 (+6940%)
Mutual labels:  state-machine
Automatonymous
A state machine library for .Net - 100% code - No doodleware
Stars: ✭ 516 (+10220%)
Mutual labels:  state-machine
Behaviortree.cpp
Behavior Trees Library in C++. Batteries included.
Stars: ✭ 793 (+15760%)
Mutual labels:  state-machine
Finite machine
A minimal finite state machine with a straightforward syntax.
Stars: ✭ 772 (+15340%)
Mutual labels:  state-machine
State machines
Adds support for creating state machines for attributes on any Ruby class
Stars: ✭ 571 (+11320%)
Mutual labels:  state-machine

Lines of Code Maintainability Build Status Coverage Status Downloads

StateJacket

An Intuitive State Transition System & State Machine

StateJacket provides an intuitive approach to building complex state machines by isolating the concerns of the state transition system & state machine.

Install

gem install state_jacket

Example

Let's define states & transitions (i.e. the state transition system) & a state machine for a turnstyle.

Turnstyle

State Transition System

system = StateJacket::StateTransitionSystem.new
system.add :opened => [:closed, :errored]
system.add :closed => [:opened, :errored]
system.lock # prevent further changes

system.to_h.inspect  # => {"opened"=>["closed", "errored"], "closed"=>["opened", "errored"], "errored"=>nil}
system.transitioners # => ["opened", "closed"]
system.terminators   # => ["errored"]

system.can_transition? :opened => :closed  # => true
system.can_transition? :closed => :opened  # => true
system.can_transition? :errored => :opened # => false
system.can_transition? :errored => :closed # => false

State Machine

Define the events that trigger transitions defined by the state transition system (i.e. the state machine).

machine = StateJacket::StateMachine.new(system, state: "closed")
machine.on :open, :closed => :opened
machine.on :close, :opened => :closed
machine.lock # prevent further changes

machine.to_h.inspect # => {"open"=>[{"closed"=>"opened"}], "close"=>[{"opened"=>"closed"}]}
machine.events       # => ["open", "close"]

machine.state            # => "closed"
machine.is_event? :open  # => true
machine.is_event? :close # => true
machine.is_event? :other # => false

machine.can_trigger? :open # => true
machine.can_trigger? :close # => false

machine.state         # => "closed"
machine.trigger :open # => "opened"
machine.state         # => "opened"

# you can also pass a block when triggering events
machine.trigger :close do |from_state, to_state|
  # custom logic can be placed here
  from_state # => "opened"
  to_state   # => "closed"
end

machine.state # => "closed"

# this is a noop because can_trigger?(:close) is false
machine.trigger :close # => nil

machine.state # => "closed"

begin
  machine.trigger :open do |from_state, to_state|
    raise # the transition isn't performed if an error occurs in the block
  end
rescue
end

machine.state # => "closed"
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].