Skip to content

Actions #3

@miroslaw-bogacz

Description

@miroslaw-bogacz

I know class is "blee" but I like when an action is class

In this implementation, you can add payload's interface for any action

export class IncrementCounter implements Action {
  readonly type = INCREMENT;
  constructor(public payload: any) {}
}

export class DecrementCounter implements Action {
  readonly type = DECREMENT;
  constructor(public payload: any) {}
}

export type CounterActions =
  IncrementCounter
  | DecrementCounter;

👍

vs

function newAction(type: string) {
  return (payload?: any): CounterAction => ({ payload, type });
}

export const incrementCounter: () => CounterAction = newAction(INCREMENT);
export const decrementCounter: () => CounterAction = newAction(DECREMENT);

❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions