-
Notifications
You must be signed in to change notification settings - Fork 311
initialState is not being invoked #273
Comments
Does invoking it in provideStore not work?
|
Not wtih angular2 AOT, you cannot invoke functions On Thu, 17 Nov 2016 at 16:38, Naveen [email protected] wrote:
|
After #269 do we need to initialize ourselves? |
@metanav, i think you referenced a wrong PR. What the function invocation does is to return the object aka values for the initial state. There shouldn't be any changes from you jor any users which are not using AOT. If they arr using AOT, they now have an clean option how to provide a dynamic initial state |
Is there any workaround towards this? I use angular-cli and I have reducers as a function like: export const authReducer: ActionReducer<AuthenticationState> =
(state: AuthenticationState = initialState, action: Action) => {
console.log(action);
switch (action.type) {
case AuthenticationActions.LOGIN: {
return null;
}
case AuthenticationActions.LOGIN_SUCCESS: {
return action.payload;
}
case AuthenticationActions.LOGIN_ERROR: {
return null;
}
case AuthenticationActions.LOGOUT: {
return null;
}
default: {
return state;
}
}
};
...
export function reducers () {
return compose(localStorageSync(['authenticated'], true), combineReducers)({
authenticated: authReducer
});
};
...
imports: [
StoreModule.provideStore(reducers)
] I have effects setted up, and they work, but the reducer is never called, neither with initialState or after when I dispatch functions. Any idea? It may be related to this? |
@bertofer : I have exactly the same problem if you find a workaround it would be great 👍 |
I did a PR for this but no response so far
#272
…On Sat, 14 Jan 2017 at 12:29, Florent CLAPIÉ ***@***.***> wrote:
@bertofer <https://github.com/bertofer> : I have exactly the same problem
if you find a workaround it would be great 👍
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#273 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AQv-Wj2Peft-BHj2StEff0uImR3b1a4kks5rSLGQgaJpZM4K1cJS>
.
|
@alan-agius4 : I am going to to test your PR. Thanks a lot :) |
Hi @florent1933 , I could make it work by calling the reducer with state and action in the exported reducers function, like this: export function reducers (state, action) {
// return composed(state, action);
return compose(localStorageSync(['authenticated'], true), combineReducers)({
authenticated: authReducer
})(state, action);
}; Being this the function provided to |
@alan-agius4 : I think our issue is not related to yours so your PR didn't fix it. @bertofer : Great, it's working 👍 Congrat's! |
@bertofer This works if you're aware ahead of time of the keys you want to populate. However, this makes it static. In order be dynamic, what you really want is to be able to do something like: export const initialState = {router: initialRouterState, ...someExternalInitialStateObject}; Amusingly, AoT will compile like this, but what it compiles to is a train wreck. Here is the compiled result of this expression in AoT: this.__INITIAL_STATE_65 = { router: { path: 0 } }; You see, because AoT is requiring 100% static symbols, the only way to approach this is with functions, which this project does not support. Without this, I have no choice but to fork the project and implement it myself until upstream catches up. |
initialState is not being invoked when it's a function
The text was updated successfully, but these errors were encountered: