Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@steelbreeze/state
Advanced tools
Readme
Executable finite state machine for TypeScript and JavaScript.
If you like @steelbreeze/state, please star it...
Note: v8 is now live and contains breaking changes but offers a further simplified code base performance improvements. See the release notes for more information.
Warning: v8 does not yet contain any support for serialization due to the challanges brought by the introduction of deferred events which are cached within the state machine instance alongside the active state configuration.
npm i @steelbreeze/state
The API is broken up into two distinct parts:
Together, they enable multiple instances of the same state machine model.
The full API reference can be found here.
import * as state from "@steelbreeze/state";
// create event class that a transition will respond to
class MyEvent {
public constructor(public fieldA: string, public fieldB: number) { }
public toString(): string {
return JSON.stringify(this);
}
}
// log state entry, exit and trigger event evaluation
state.log.add(message => console.info(message), state.log.Entry | state.log.Exit | state.log.Evaluate);
// create the state machine model elements
const model = new state.State("model");
const initial = new state.PseudoState("initial", model, state.PseudoStateKind.Initial);
const stateA = new state.State("stateA", model);
const stateB = new state.State("stateB", model);
// create the transition from initial pseudo state to stateA
initial.to(stateA);
// create a transtion from stateA to stateB a for events of type MyEvent with a guard condition
stateA.on(MyEvent).when(myEvent => myEvent.fieldB > 2).to(stateB);
// create an instance of the state machine model
let instance = new state.Instance("instance", model);
// send the machine events for evaluation
instance.evaluate(new MyEvent("test", 1));
instance.evaluate(new MyEvent("test", 3));
var state = require("@steelbreeze/state");
// create event class that a transition will respond to
class MyEvent {
constructor(fieldA, fieldB) { this.fieldA = fieldA; this.fieldB = fieldB; }
toString() { return JSON.stringify(this); }
}
// log state entry, exit and trigger event evaluation
state.log.add(message => console.info(message), state.log.Entry | state.log.Exit | state.log.Evaluate);
// create the state machine model elements
const model = new state.State("model");
const initial = new state.PseudoState("initial", model, state.PseudoStateKind.Initial);
const stateA = new state.State("stateA", model);
const stateB = new state.State("stateB", model);
// create the transition from initial pseudo state to stateA
initial.to(stateA);
// create a transtion from stateA to stateB a for events of type MyEvent with a guard condition
stateA.on(MyEvent).when(myEvent => myEvent.fieldB > 2).to(stateB);
// create an instance of the state machine model
let instance = new state.Instance("instance", model);
// send the machine events for evaluation
instance.evaluate(new MyEvent("test", 1));
instance.evaluate(new MyEvent("test", 3));
The output of the above code will be:
instance enter model
instance enter model.default
instance enter model.default.initial
instance leave model.default.initial
instance enter model.default.stateA
instance evaluate {"fieldA":"test","fieldB":1}
instance evaluate {"fieldA":"test","fieldB":3}
instance leave model.default.stateA
instance enter model.default.stateB
Note that in the example above, a default region is inserted as a child of
model
and parent ofinitial
,stateA
andstateB
; the name of default regions copy their parent state hence seeingmodel.model
in the output above.
MIT License
Copyright (c) 2022 David Mesquita-Morris
FAQs
Finite state machine for TypeScript and JavaScript
The npm package @steelbreeze/state receives a total of 280 weekly downloads. As such, @steelbreeze/state popularity was classified as not popular.
We found that @steelbreeze/state demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.