Skip to content

State Machine

rohenaz edited this page Mar 18, 2018 · 5 revisions

Silica includes a Finite State Machine. To use, first make sure your controller extends the FSM:

class MyController extends Silica.Controllers.FSM.Controller {

To define states:

static get states() {
    return {
      "results": class extends Silica.Controllers.FSM.State {
        constructor() {
          super();
          this.currentView = "/views/customers/index.html";
        }

        onEnter() {}
        onExit() {}
}

To transition to a state (this ex assumes your controller is a singleton):

    (new MyController()).transition("results");

To get the current state:

controller.currentState

To call a function or get a property from the current state:

controller.handle("funcName|propertyName")

The parent controller is passed as the first argument of a state's onEnter, constructor, and onExit methods. To call a function on the state's parent controller:

onEnter(cntrl) {
   cntrl.parentFunc()
}

Clone this wiki locally