update: A method to notify changes after run a set of instructions.
refresh: A method to force to notify changes.
*bind: A method to bind an instance to it.
*unbind: A method to unbind an instance to it.
*dispose: A method to remove all listeners and free resources.
Usage
Declaration
UseReducer can be initialized using the constructor class:
Writting the action
The action is a class that inherits from the RtAction class.
This class contains the action type and payload that will be dispatched to the reducer method.
Writting the reducer method
The reducer method is a function that takes the current state and an action, and returns a new state.
This method is responsible for updating the state based on the action dispatched.
The state is immutable, so it should return a new state object.
Dispatching an action and reading the state
The dispatch method is responsible for dispatching an action to the reducer method.
After dispatching an action, you can read the state using the value property.
Using the action callable
The actions can be created as a callable class, extending from RtActionCallable e.g.:
RtActionCallable has a call method that returns the new state based on the state and payload.
The action callable can be applied in reducer method:
And dispatched as:
Updating the state
Use update method to notify changes after run a set of instructions:
Use refresh method to force to notify changes.
Listening to changes
When value has changed, the UseReducer will emit the following events(learn about it here):
Lifecycle.willUpdate event is triggered before the value change or update, refresh methods have been invoked.
Lifecycle.didUpdate event is triggered after the value change or update, refresh methods have been invoked.