Comments (7)
@thomascmost I don't think is necessary rewriting your reducers. I was experiencing same issue but changing my reducers from arrow functions to named functions (function declaration) works for me.
instead of :
export const securityReducer = function (state: SecurityState, action: StoreAction) {
return createReducer<SecurityState>(AuthStore)(state, action);
};
I changed it to:
export function securityReducer(state: SecurityState, action: StoreAction) {
return createReducer<SecurityState>(AuthStore)(state, action);
};
and everything works fine. cc: @leon
from ngrx-actions.
Hi @leon, the problem is that AoT compilation is very strict, and requires a function declaration, not a const that holds a function reference. I know, it's stupid, but it works this way for now.
from ngrx-actions.
Geez! -- so we have to rewrite all of our reducers as named functions just to get AOT working???
from ngrx-actions.
Hi @leon ,
try with the following implementation:
let xReducerInstance;
export function xReducer(state: XState, action: Action) {
return (xReducerInstance || (xReducerInstance = createReducer<XState>(XStore)))(state, action);
}
from ngrx-actions.
I think its this: StoreModule.forFeature('security', securityReducer),
, should securityReducer
be an object?
from ngrx-actions.
@amcdnl I got it working with @albyrock87's suggestion.
I think forFeature takes either a map of reducers or a single reducer.
I find it strange as to why @albyrock87's suggestion is different from:
export const securityReducer = createReducer<SecurityState>(SecurityStore);
It's creating a variable that holds a reference to the reducer.
Very strange :)
from ngrx-actions.
Referencing a reusable function reducer also causes this problem. Even when it has been changed to functions from const
function listReducer(Enum) {
return function(state, action) {
switch(action.type)
case Enum.Pending:
...
...
...
}
}
export function categoryReducer () {
return listReducer(CategoryEnum);
}
export function skillReducer() {
return listReducer(SkillEnum);
}
StoreModule.forFeature('shared', {
category: categoryReducer(),
skill: skillReducer()
});
Update:
For those of you who have this problem, add the state and action to the function as parameters and pass them through to the reusable function...
function listReducer(Enum) {
return function(state, action) {
switch(action.type)
case Enum.Pending:
...
...
...
}
}
export function categoryReducer(state, action) {
return listReducer(CategoryEnum)(state, action);
}
export function skillReducer(state, action) {
return listReducer(SkillEnum)(state, action);
}
StoreModule.forFeature('shared', {
category: categoryReducer,
skill: skillReducer
});
from ngrx-actions.
Related Issues (20)
- Action options HOT 1
- Store DI
- Example Stored + Entity HOT 3
- Return Store initial state to be used in the tests
- Can it be used with redux? HOT 1
- New @Effect decorator HOT 3
- @Action - samples in the README and articles are incorrect?
- NgrxActionsModule.forFeature - not working?
- @Dispatch
- Question: Unit testing with the @Select decorator
- RxJs 6 - Property 'pipe' does not exist in type 'Actions<Action>' HOT 1
- feat: support angular v6
- Question: any ETA for a ng6 compatible version? HOT 5
- Cannot find module 'ngrx-actions' HOT 8
- NgrxActionsModule nested reducers
- Publish 4.0.1 to NPM?
- Unexpected state mutation in reducers
- @Effect() decorator does not work HOT 1
- NGRX 7.x Upgrade HOT 2
- PLEASE DELETE. CREATED BY MISTAKE :D
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngrx-actions.