在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:jakesgordon/javascript-state-machine开源软件地址:https://github.com/jakesgordon/javascript-state-machine开源编程语言:JavaScript 99.6%开源软件介绍:Javascript State MachineA library for finite state machines. NOTE for existing users
InstallationIn a browser: <script src='state-machine.js'></script>
Using npm: npm install --save-dev javascript-state-machine In Node.js: var StateMachine = require('javascript-state-machine'); UsageA state machine can be constructed using: var fsm = new StateMachine({
init: 'solid',
transitions: [
{ name: 'melt', from: 'solid', to: 'liquid' },
{ name: 'freeze', from: 'liquid', to: 'solid' },
{ name: 'vaporize', from: 'liquid', to: 'gas' },
{ name: 'condense', from: 'gas', to: 'liquid' }
],
methods: {
onMelt: function() { console.log('I melted') },
onFreeze: function() { console.log('I froze') },
onVaporize: function() { console.log('I vaporized') },
onCondense: function() { console.log('I condensed') }
}
}); ... which creates an object with a current state property:
... methods to transition to a different state:
... observer methods called automatically during the lifecycle of a transition:
... along with the following helper methods:
TerminologyA state machine consists of a set of States
A state machine changes state by using Transitions
A state machine can perform actions during a transition by observing Lifecycle Events
A state machine can also have arbitrary Data and Methods. Multiple instances of a state machine can be created using a State Machine Factory. DocumentationRead more about
ContributingYou can Contribute to this project with issues or pull requests. Release NotesSee RELEASE NOTES file. LicenseSee MIT LICENSE file. ContactIf you have any ideas, feedback, requests or bug reports, you can reach me at [email protected], or via my website: Code inComplete |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论