Action

  • Action contains two fields
    • type
    • payload
  • Recommended way of writing action
    • Create an action.dart file for a component|adapter that contains two classes
      • An enumeration class for the type field
      • An ActionCreator class is created for the creator of the Action, which helps to constrain the type of payload.
    • Effect Accepted Action which's type is named after on{verb}
    • Reducer Accepted Action which's type is named after {verb}
    • Sample code
  1. enum MessageAction {
  2. onShare,
  3. shared,
  4. }
  5.  
  6. class MessageActionCreator {
  7. static Action onShare(Map<String, Object> payload) {
  8. return Action(MessageAction.onShare, payload: payload);
  9. }
  10.  
  11. static Action shared() {
  12. return const Action(MessageAction.shared);
  13. }
  14. }