Skip to content

Latest commit

 

History

History
29 lines (25 loc) · 834 Bytes

action.md

File metadata and controls

29 lines (25 loc) · 834 Bytes

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
enum MessageAction {
    onShare,
    shared,
}

class MessageActionCreator {
    static Action onShare(Map<String, Object> payload) {
        return Action(MessageAction.onShare, payload: payload);
    }

    static Action shared() {
        return const Action(MessageAction.shared);
    }
}