asr-fsm-navigation
Use a fsm finite state machine definition to navigate around an abstract-state-router application using dispatch events
Last updated 2 years ago by tehshrike .
WTFPL · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install asr-fsm-navigation 
SYNC missed versions from official npm registry.

Given an fsm description of how users should be able to navigate between states:

Watches for dispatch and dispatchInput events, interprets the first argument to be the action type, and when it sees one it has a command for, it tells the abstract-state-router to navigate to that state (inheriting all parameters from the current state).

const asrFsmNavigation('asr-fsm-navigation')
const makeAsrStateWatcher = require('asr-active-state-watcher')

const stateWatcher = makeAsrStateWatcher(stateRouter)
const startFsmNavigation = asrFsmNavigation(stateRouter, stateWatcher)

var stopNavigating = startFsmNavigation({
	'parent1': {
		GO_TO_PARENT2_CHILD1: 'parent2.child1',
		GO_TO_PARENT2_CHILD2: 'parent2.child2'
	},
	'parent2.child1': {
		GO_TO_PARENT1: 'parent1'
	},
	'parent2.child2': {
		GO_TO_PARENT1: 'parent1',
		GO_TO_PARENT1_CHILD2: 'parent1.child2'
	}
})

If the user is at the parent1.child1 state and dispatches a GO_TO_PARENT2_CHILD1 event, the module will navigate to the parent2.child1 state.

State navigation options

You can pass in an options object when you start the navigator. Defaults to { inherit: true }.

const startFsmNavigation = asrFsmNavigation(stateRouter, stateWatcher)

startFsmNavigation({
	'parent1': {
		GO_TO_PARENT2_CHILD1: 'parent2.child1',
		GO_TO_PARENT2_CHILD2: 'parent2.child2'
	},
	'parent2.child2': {
		GO_TO_PARENT1: 'parent1',
	}
}, {
	inherit: false
})

Querystring parameters

For each action, you can specify particular parameter values that will be set when navigating to the next state.

To do this, give an object with name/parameters parameters, instead of a string for a state destination:

const startFsmNavigation = asrFsmNavigation(stateRouter, stateWatcher)

startFsmNavigation({
	'parent1.child1': {
		GO_TO_PARENT2_CHILD1: {
			name: 'parent2.child1',
			parameters: {
				shiny: 'yes'
			}
		}
	},
	'parent2.child1': {
		GO_TO_PARENT1: 'parent1',
	}
}, {
	inherit: false
})

Current Tags

  • 1.0.0                                ...           latest (2 years ago)

4 Versions

  • 1.0.0                                ...           2 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           5 years ago
  • 0.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |