Skip to content
This repository has been archived by the owner on Jan 10, 2018. It is now read-only.

Using ngrx store with angular 2 AOT #355

Closed
ritox842 opened this issue Mar 13, 2017 · 3 comments
Closed

Using ngrx store with angular 2 AOT #355

ritox842 opened this issue Mar 13, 2017 · 3 comments

Comments

@ritox842
Copy link

ritox842 commented Mar 13, 2017

Hey all.

I'm trying to use ngrx/store with angular 2 AOT but I'm facing difficulties.
I saw this issue
#190
It's very much the same and solved some of the problems I was faced with but still It wont compile.
I think the reason is that I have nested reducers in the root reducer level but I'm not sure.

This is my root reducer:

export function rootReducer() {
  return compose(combineReducers)({
    app: appReducer,
    event: eventReducer,
    lobby: LobbyReducer,
    betCard: combineReducers({
      staticData: betCardStatic,
      dynamicData: betCardDynamic,
      participants: participantsReducer
    }),
    betSlip: betSlip,
    openBet: openBetReducer,
    userProfile: combineReducers
    (
      {
        information: userInformationReducer,
        limits: limitsReducer,
        notifications: notificationsReducer
      }
    ),
    cashier: combineReducers({
      balance: cashierReducer,
      deposit: depositReducer
    }),
    myBets: myBetsReducer,
    edit: combineReducers({
      bet: editBetReducer
    }),
    social: combineReducers({
      connections: connectionsReducer,
      groups: groupsReducer
    }),
    privacy: privacyReducer
  });
}

And this is my app module :
StoreModule.provideStore(rootReducer)

The error Im getting is
Uncaught TypeError: Cannot read property 'information' of undefined

Witch I'm guessing it's the reducer that's under 'userProfile' reducer.
Lastly, This is my 'userInformationReducer':

export function userInformationReducer(state = userInformationInitState, action: Action) {
.......
}

Anyone now how to solve it?

@brandonroberts
Copy link
Member

brandonroberts commented Mar 13, 2017

Your reducers should take the state and action and return a new reduced state.

export function rootReducer(state, action) {
  const reducer = compose(combineReducers)({
    ...
  });

  return reducer(state, action);
}

See this example app root reducer for reference: https://github.com/ngrx/example-app/blob/master/src/app/reducers/index.ts#L66-L83

@ritox842
Copy link
Author

Thanks a lot @brandonroberts !!

Finally it works!

@valimero
Copy link

Tanks a lot too @brandonroberts !

Thats works for me too !!!!

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

No branches or pull requests

3 participants