JavaScript state machine and its application in workflow

Source: Internet
Author: User

#javascript状态机及在工作流中的应用 # #状态机什么叫状态机 (finite state machine), the written explanation can be found by search engines. In layman's terms, a collection of code is a set of state definitions, lookups, transitions, and event distributions. The corresponding design pattern is called state machine mode, which is often used in game programming, but also in the application of workflow. In the workflow, we often have a series of steps: Step 1, Step 2, Step 3, step 4. We first need to define these steps, and then define the conditions for these steps to switch, in the case of the client, it is generally certain condition validation through, can be a field, it can be some interface, there is the completion of the previous step. # #工作流我们要完成一项较复杂的工作, often require multiple steps, and these steps also have prerequisites and flow control, the actual business is the workflow. # #小应用比如我们要进行一个报销的审批, there are several steps: Start, employee submission reimbursement, Project Manager review, director Audit, financial approval, supplementary information. Business is: * * process is in sequence, before the financial approval, you can supplement the information, but to supplement the information will be from the project manager to start approval. * * We in the traditional code, if you want to put the above states are written together, there must be a lot of if else conditions to judge. At this time, the state machine can be used to abstract these content, to form a high degree of separation, reusability, easy to understand code. Search for ' JavaScript finite state machine ' in Google, the first result is the code on GitHub, I took it for demonstration, details click [Demo] (http://gh.p2227.com/demo/fsm/) Check it out, or use the code bcause. [Simple state machine Demo] (http://images.cnitblog.com/blog/84053/201408/232349419241810.jpg) # #后记 * Of course, what we're going to do is impossible to accomplish with a pure front end, The front end is just a guarantee that the user has the correct input when using the software normally. * State machine in the process of using a lot of complex situations, it depends on the power of the encapsulation code, such as the state machine above does not support sub-state.

JavaScript state machine and its application in workflow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.