Problem with compose reducers

Hi,

I’m having trouble building my application, it works fine when I use ionic serve but when trying to build I get this error :

[14:13:43]  Error: Error encountered resolving symbol values statically. Function calls are not supported. 
        Consider replacing the function or lambda with a reference to an exported function, resolving 
        symbol AllReducers in .tmp/app/app.module.ts, resolving 
        symbol AppModule in.tmp/app/app.module.ts, resolving 
        symbol AppModule in .tmp/app/app.module.ts 
[14:13:43]  ngc failed 
[14:13:43]  ionic-app-script task: "build" 
[14:13:43]  Error: Error 

I understand where the problem come from, here is the part in my app.module.ts file that provoc the error.

export function AllReducers () {
   return compose(
       localStorageSync(['session'], true),
       combineReducers
   )({
       session: SessionReducer,
       categories: CategoryReducer,
       products: ProductReducer,
       presences: PresenceReducer,
       clients: ClientReducer,
       navigation: NavigationReducer,
       current_categories: CurrentCategoriesReducer,
   });
};

@NgModule({
  declarations: [
      MyApp,
      LoginPage,
      LogoutPage,
      HomePage,
      CatalogPage,
      CategoryPage,
      ProductPage,
      PresencePage,
      ClientListPage,
      ClientViewPage,
  ],
  imports: [
      IonicModule.forRoot(MyApp),
      EffectsModule.run(SessionEffects),
      EffectsModule.run(CatalogEffects),
      EffectsModule.run(PresenceEffects),
      EffectsModule.run(ClientEffects),
      StoreModule.provideStore(AllReducers())
  ],
...

The problem come from the call to AllReducers() when I remove the parentheses the build works fine but the app does not work anymore.
I have tried with a export const allReducers = compose(...); but it doesn’t work eather.

Here are my ionic info :

Cordova CLI: 6.5.0
Ionic Framework Version: 2.0.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 0.0.36
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v4.2.6
Xcode version: Not installed

How should I declare and call my AllReducers export so that it works properly with eveything ?

Thanks for any help.
David

Not sure there’s enough code to diagnose this. Why doesn’t AllReducers have parameters for action and payload? Or maybe you’re using the word reducer in a non-Redux way?

I thought in here it was mostly for declarations so no matter what the class types are.
I am in a Redux way I think (not sure I grasp the whole concept there yet).

I found a beggining of an answer here: https://github.com/angular/angular/issues/10789#issuecomment-242220591

Side point: I don’t put mine in app.module.ts. I created a separate reducers folder, and I import content into app.module.ts, in order to be able to use StoreModule.provideStore(reducer). Seems cleaner to me.

Main point: the method signature of reducer for me is export function reducer(state: any, action: any) and reducer itself is a composition of reducers that operate on slices of state, and those smaller reducers are all strictly typed pure functions. It seems from your error message that something, somewhere, isn’t a function.

Suggestion: get it working with one slice of state, then combine reducers one by one.

I think I understand but can you provide an example please ?

I think you are right, here is one of my reducers :

import {ActionReducer, Action} from '@ngrx/store';
import {Map} from 'immutable';
import {CatalogActions} from '../actions/catalog.actions';

let defaultState = Map<string, any>({});

export const ProductReducer: ActionReducer<any> = (state: Map<string, any> = defaultState, action: Action) => {
    switch (action.type) {
        case CatalogActions.CLEAR_PRODUCTS:
            return Map<string, any>({});
        case CatalogActions.LOAD_PRODUCTS_SUCCESS:
            return state.merge(action.payload);
        default:
            return state;
    };
};

Have you seen this?

How wow I think I see what you mean to show me by a main reducer that contains all other reducers.
I’m gonna try to implement this that way and get back after.

Thanks a lot.

All right based on what you showed me I tryed this :

  1. Created a global reducer :

     export const AllReducers: ActionReducer<AppState> = compose(
         localStorageSync(['session'], true),
         combineReducers)
         ({
             session: SessionReducer,
             categories: CategoryReducer,
             products: ProductReducer,
             presences: PresenceReducer,
             clients: ClientReducer,
             navigation: NavigationReducer,
             current_categories: CurrentCategoriesReducer,
          });
    
  2. Included it in my NgModule imports :

     ...
     imports: [
         StoreModule.provideStore(AllReducers),
     ...
    

And I style get the same error :frowning: when building :

 Error: Error encountered resolving symbol values statically. Function calls are not supported. 
        Consider replacing the function or lambda with a reference to an exported function, resolving 
        symbol AllReducers in .tmp/includes/reducers.ts, resolving 
        symbol AppModule in .tmp/app/app.module.ts, resolving 
        symbol AppModule in .tmp/app/app.module.ts

Even after updateing version of IonicAppScript to the last version still not working.

Cordova CLI: 6.5.0
Ionic Framework Version: 2.0.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.3
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v4.2.6
Xcode version: Not installed