javascript - What is a Finite State Machine and What is it Used For? -
recently, i've begun doing research finite state machines in javascript , found library makes them easier implement. while think i've grasped thought state machine used tracking , changing "state" of object (e.g., 'ready', 'complete', 'inactive', etc.,), don't think understand practical implications of them. please help clarifying following:
what exactly finite state machine [or called state machine? i've heard referred both ways]? what practical uses finite state machines (in javascript)? when not want utilize finite state machine? what books, articles, tutorials, etc., offer more in-depth @ finite state machines (in javascript)?
a finite state machine abstract concept. such, concept of state machine orthogonal particular language. if look @ wikipedia, says "is mathematical model of computation used design both computer programs , sequential logic circuits".
this means fsm used mathematical concept used computer scientists address questions discipline, "can xyz computed @ all?"
based on question, , link, think mean inquire state diagram (or statechart) different. when create state diagram, dividing programme in series of states, , events can occur in states. example, programme might in "editingform" state, receive event "dosave", , go "saving" state, receive event 'save complete", , go "viewing" state.
this abstraction incredibly useful because allows programmer conceptually organize things should happen when, when implemented correctly, leads cleaner , more organized code. in turn leads fewer bugs. state diagram, depending on implementation, can prevent unintended effects handling events defined state -- example, "viewing" not have 'save' event defined, if programme in "viewing" state save meaningless, should happen in "editing" state.
if @ overview of framework link, notice there bunch of handlers can utilize hook entering states, leaving states, actions happening, etc. allows things correspond state/action. example, on entering "editing" state might nowadays form user , enable save button. on entering "saving" state might disable button , fire request save. on receiving "savecomplete" event might transition "viewing" state, remove form, , show else.
javascript state-machines finite-state-machine
No comments:
Post a Comment