State machine implementation
I’ve implemented state machine logic into the web application. One or more state machines can be used within the application – user access state, group states, event states etc – with the current state of each state machine stored within the Session object.
A generic JavaScript function has been added to invoke an action upon a state machine upon the server. The call back result, like nearly all server-side requests, can return updates to one or more elements on the web page.
For example, if the User Access state changes from Anonymous to Authenticated User:
For example, an Event will have an Event Membership state machine for each user that view the event. By default, when a user first views the Event it will start at the Non-member state. When they join the Event, the state will change to Member. This change will trigger an update upon the Event’s views. The Event must then republish its views to the HtmlResponse object based upon the user’s changed membership state.
The possible changes between states of a state machine are coded within each individual state class. The changes between states are triggered by actions upon the state machine. The state machine first asks the current state if it supports the requested action, e.g. the Login action upon the User Access state machine. If the current state is Anonymous User, and the requested action is Login, then the state will accept the action. The state will then process the action, and return the resulting state (possibly returning itself).
In the initial implementation, the state objects can update the HtmlResponse object themselves. I believe that corresponding UI views should be coded to handle UI changes. For example, there would be a Login View at the top of the webpage. This view will be a dependent of the User Access state machine, but will also be able to invoke actions upon the state machine when the user attempts to login or logout. But, at the UI level, it is just another dependent view that will be triggered when there is a state change.
A generic JavaScript function has been added to invoke an action upon a state machine upon the server. The call back result, like nearly all server-side requests, can return updates to one or more elements on the web page.
For example, if the User Access state changes from Anonymous to Authenticated User:
- The User Login panel will be updated
- All buttons on the screen that would have prompted the user to login or register will change such that they actually perform their intended function
- Modules will update to show data etc that was not viewable by unknown users.
For example, an Event will have an Event Membership state machine for each user that view the event. By default, when a user first views the Event it will start at the Non-member state. When they join the Event, the state will change to Member. This change will trigger an update upon the Event’s views. The Event must then republish its views to the HtmlResponse object based upon the user’s changed membership state.
The possible changes between states of a state machine are coded within each individual state class. The changes between states are triggered by actions upon the state machine. The state machine first asks the current state if it supports the requested action, e.g. the Login action upon the User Access state machine. If the current state is Anonymous User, and the requested action is Login, then the state will accept the action. The state will then process the action, and return the resulting state (possibly returning itself).
In the initial implementation, the state objects can update the HtmlResponse object themselves. I believe that corresponding UI views should be coded to handle UI changes. For example, there would be a Login View at the top of the webpage. This view will be a dependent of the User Access state machine, but will also be able to invoke actions upon the state machine when the user attempts to login or logout. But, at the UI level, it is just another dependent view that will be triggered when there is a state change.