Git Product home page Git Product logo

Comments (7)

johadi avatar johadi commented on June 8, 2024 22

@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.

albyrock87 avatar albyrock87 commented on June 8, 2024 16

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.

thomasmost avatar thomasmost commented on June 8, 2024 6

Geez! -- so we have to rewrite all of our reducers as named functions just to get AOT working???

from ngrx-actions.

albyrock87 avatar albyrock87 commented on June 8, 2024 4

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.

amcdnl avatar amcdnl commented on June 8, 2024

I think its this: StoreModule.forFeature('security', securityReducer),, should securityReducer be an object?

from ngrx-actions.

leon avatar leon commented on June 8, 2024

@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.

YussufElarif avatar YussufElarif commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.