StateMachine:SSM 的 TypeScript 版本(更少的魔法)

  • V9_118007
    了解作者
  • 12.5KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 03:32
    上传日期
状态机: 状态机 用法: // create instance var machine = new StateMachine . StateMachine ( { verbose : true , name : "MyStateMachine" } ) ; // define states machine . state ( "state1" ) . on ( "event1" , function ( ) { // do something this . go ( "state2" ) ; } ) . on ( "event2" , function ( x , y , z ) { // do something console . log ( "x:" , x , "y:" , y , "z:" , z ) ; } )
StateMachine-master.zip
  • StateMachine-master
  • .travis.yml
    71B
  • package.json
    848B
  • test
  • spec.js
    7.4KB
  • gulpfile.js
    1.7KB
  • src
  • StateMachine.ts
    5.6KB
  • .gitignore
    36B
  • karma.conf.js
    1.6KB
  • README.md
    1018B
  • bower.json
    463B
  • build
  • StateMachine.js.map
    15.7KB
  • StateMachine.js
    2.2KB
  • StateMachine.d.ts
    2.6KB
内容介绍
# StateMachine: [![Build Status](https://travis-ci.org/icholy/StateMachine.svg?branch=master)](https://travis-ci.org/icholy/StateMachine) > State Machine **Usage:** ``` js // create instance var machine = new StateMachine.StateMachine({ verbose: true, name: "MyStateMachine" }); // define states machine.state("state1") .on("event1", function () { // do something this.go("state2"); }) .on("event2", function (x, y, z) { // do something console.log("x:", x, "y:", y, "z:", z); }) .on("enter", function () { // special event that gets run when the state is entered }); machine.state("state2") .on("event2", function () { // do something else this.go("state1"); }) .on("exit", function () { // special event that gets run when the state is exited }); // set initial state machine.init("state1"); // invoke events machine.emit("event1"); machine.emit("event2", "foo", "bar", "baz"); //get current state name console.log(machine.current.name); ```
评论
    相关推荐