Skip to content

Commit

Permalink
random action exits, bugfixes, tests, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed May 10, 2017
1 parent 2f9eb45 commit a5e6e60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jssm",
"version": "0.17.1",
"version": "0.18.0",
"description": "A Javascript state machine with a simple API. Well tested, and typed with Flowtype. MIT License.",
"main": "dist/jssm.es5.browserified.js",
"scripts": {
Expand All @@ -26,9 +26,11 @@
},
"keywords": [
"state",
"state machine",
"state-machine",
"machine",
"finite-state-machine",
"finite state machine",
"fsm",
"fsm-library",
"js",
Expand Down
2 changes: 1 addition & 1 deletion src/js/jssm-types.js
Expand Up @@ -80,7 +80,7 @@ type JssmTransition<NT, DT> = {
from : NT,
to : NT,
name? : string,
action? : string,
action? : NT,
check? : JssmTransitionPermitterMaybeArray<NT, DT>, // validate this edge's transition; usually about data
probability? : number, // for stoch modelling, would like to constrain to [0..1], dunno how
usual? : '' // most common exit, for graphing; likelihood overrides
Expand Down
15 changes: 12 additions & 3 deletions src/js/jssm.js
Expand Up @@ -265,9 +265,18 @@ todo comeback

action_exits_at(whichState : mNT) : Array<mNT> {
return [... (this._reverse_actions.get(whichState) || new Map()).values()] // wasteful
.map( (edgeId:number) => this._edges[edgeId] ) // whargarbl burn out any
.filter( o => o.from === whichState)
.map( filtered => filtered.to );
.map ( (edgeId:number) => this._edges[edgeId] )
.filter ( (o:JssmTransition<mNT, mDT>) => o.from === whichState )
.map ( filtered => filtered.action );
}

probable_action_exits_at(whichState : mNT) : Array<mNT> {
return [... (this._reverse_actions.get(whichState) || new Map()).values()] // wasteful
.map ( (edgeId:number) => this._edges[edgeId] )
.filter ( (o:JssmTransition<mNT, mDT>) => o.from === whichState )
.map ( filtered => ( { action : filtered.action,
probability : filtered.probability } )
);
}


Expand Down

0 comments on commit a5e6e60

Please sign in to comment.