Skip to content

Instantly share code, notes, and snippets.

@pelonpelon
Created April 29, 2015 22:08
Show Gist options
  • Save pelonpelon/aad56813a99946d64f38 to your computer and use it in GitHub Desktop.
Save pelonpelon/aad56813a99946d64f38 to your computer and use it in GitHub Desktop.
Example finite state machine - credit: Nijiko Yonskai (https://github.com/Nijikokun)
function state (namespace) {
if (!namespace) return internalState[internalState.length - 1]
internalState.push([namespace, options])
m.redirect(namespace, options)
}
function goto (namespace, options) {
return function (e) {
e.preventDefault()
e.stopPropagation()
state((typeof namespace === 'function' ? namespace() : namespace), options)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment