Git Product home page Git Product logo

angular.amo.module.state_machine's Introduction

angular.amo.module.state_machine

ステートマシンを作るためのヘルパーを提供する

インストール方法

bower install -S angular.amo.module.state_machine
%script(src="bower_components/angular.amo.module.state_machine/dist/js/state_machine.min.js")

使い方

StateSetter

StateSetter は State 変更のための汎用的な関数を提供する。

angular.module "yourApp", ["amo.module.state_machine"]
.factory "SomeFsm", ["amo.module.state_machine.StateSetter", (StateSetter) ->
  (action = {}) ->
    setState = StateSetter()
  
    class DefaultState
      Entry: setState.defaultAction
      Exit: setState.defaultAction
      toState1: setState.defaultAction
      toState2: setState.defaultAction
      toEnd: setState.defaultAction
  
    INIT = new class extends DefaultState
      toState1: -> setState STATE1
    STATE1 = new class extends DefaultState
      toState2: -> setState STATE2
    STATE2 = new class extends DefaultState
      Entry: -> action.entryState2?()
      Exit: -> action.exitState2?()
      toState1: -> setState STATE1
      toEnd: -> setState DONE
    DONE = new class extends DefaultState
  
    return setState.getFsm INIT
]

setState.defaultAction

何もしない関数を返す。

setState.getFsm initState

外部公開用の fsm を返す。 fsm は、それ自身が 関数となっており、現在の ステート を返すようになっている。そのため、これを使う場では下記のようにしてステートを変更することが出来る。

angular.module "yourApp"
.factory "AnotherObj", ["SomeFsm", (SomeFsm) ->
  fsm = SomeFsm()
  fsm().toState1()
  ...
]

fsm.changing

ステートが変更中かどうかを返す。 この関数は Entry, Exit 内で呼ばれた場合に true, それ以外の場所では false を返す。 また、この値が true の時には ステートを変更できない。

angular.amo.module.state_machine's People

Contributors

amo12937 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.