Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

root action #33

Closed
lstkz opened this issue Dec 22, 2017 · 6 comments · Fixed by #36
Closed

root action #33

lstkz opened this issue Dec 22, 2017 · 6 comments · Fixed by #36
Assignees
Labels

Comments

@lstkz
Copy link

lstkz commented Dec 22, 2017

I am confused how to create the root action properly.

From docs:

// example reducer
export const reducer: Reducer<State> = (state = 0, action: RootAction) => {
// root actions
export type RootAction =
  | ReactRouterAction
  | CountersActions[keyof CountersActions]
  | TodosActions[keyof TodosActions]
  | ToastsActions[keyof ToastsActions];
// example action creators
import { createAction, getType } from 'react-redux-typescript';

// Action Creators
export const actionCreators = {
  incrementCounter: createAction('INCREMENT_COUNTER'),
  showNotification: createAction('SHOW_NOTIFICATION', 
    (message: string, severity: Severity = 'default') => ({
      type: 'SHOW_NOTIFICATION', payload: { message, severity },
    })
  ),
};

CountersActions[keyof CountersActions] is equal to action creator types, not action types.
Should I define both action creator and actions separately?
Also ToastsActions[keyof ToastsActions]; doesn't work, but typeof ToastsActions[keyof typeof ToastsActions]; works.

@jakubrohleder
Copy link

I've just found this issue, I think it should help you: piotrwitek/typesafe-actions#4

@piotrwitek
Copy link
Owner

piotrwitek commented Dec 23, 2017

Hello @lsentkiewicz
Sorry but RootAction is currently outdated.

I'm in the middle of rework of entire action creators and reducer section as I made a few improvements in typing patterns for them, so expect a new solution soon.

At this moment you can check the issue linked above or check the RootAction file that is located in the Playground Project: https://github.com/piotrwitek/react-redux-typescript-guide/blob/master/playground/src/redux/root-action.ts

@piotrwitek
Copy link
Owner

Please check a new and updated Store Configuration Section

@lstkz
Copy link
Author

lstkz commented Dec 28, 2017

thanks @piotrwitek!

@lstkz
Copy link
Author

lstkz commented Jan 3, 2018

In the current readme.md

export const allActions = {
  ...countersAC,
  ...todosAC,
  ...toastsAC,
};

const returnOfActions =
  Object.values(allActions).map(getReturnOfExpression);

should be changed to

export const allActions = [
  ...Object.values(countersAC),
  ...Object.values(todosAC),
  ...Object.values(toastsAC),
];

const returnOfActions = allActions.map(getReturnOfExpression);

because multiple modules can contain the same names.
Example countersAC.loaded() and todosAC.loaded(), and duplicated names are overriden.

@piotrwitek
Copy link
Owner

@lsentkiewicz yes that make sense, thanks!
I'll update it with the next PR which I'm working on right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants