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 ccepted Action which’s type is named after {verb}
    • Sample code
  1. enum MessageAction {
  2. onShare,
  3. shared,
  4. }
  5. class MessageActionCreator {
  6. static Action onShare(Map<String, Object> payload) {
  7. return Action(MessageAction.onShare, payload: payload);
  8. }
  9. static Action shared() {
  10. return const Action(MessageAction.shared);
  11. }
  12. }