Store: @Selector() not working when inheriting from a parent @State

Created on 30 May 2019  ·  12Comments  ·  Source: ngxs/store

I'm submitting a...

[ X ] Bug report

Current behavior

When inheriting from a Parent @State class with a @Selector, using that selector on child @State class doesnt return the store value

Expected behavior

Child @State should return the value of the selected value via the @Selector method in its parent class

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/ngxs-inherit-selector-issue-1108

  • Step 1
  • Step 2
  • Step 3

What is the motivation / use case for changing the behavior?

N/A

Environment


Libs:
N/A

Browser:
N/A

For Tooling issues:
N/A

Others:
N/A
core

Most helpful comment

@joaqcid we can close?

All 12 comments

One thing i noticed is that if i add the parent @State to the AppModule it works, but the behavior is not the desired. In this case both parent and child state have the same state.
I wonder if i what i want to do is possible or not…

I'm sorry, maybe I'm missing something, but what behavior do you expect if you don't add the CountState when calling forRoot? We can't manually add this state to the root DI providers.

The behaviour expected is to able to inherit selectors from base abstract classes, to avoid duplicated selectors, for instance for "loading" @selector

Yes, I noticed this problem and it needs to be solved

@joaqcid
You use a selector from the non-imported class:

@Select(CountState.count) count$: Observable<number>;

yeah, i think i was testing with both states, just updated it, you can see it doesnt work, even if use ChildCountState.count

You could just write ChildCountState except of CountState cause I got confused haha :joy:

@arturovt Hi,
Is it going to be resolved? If yes then please mark it as bug or feature as you see it. So we can follow this.
Thanks

Hi!

After reading more the documentation, found i can actually do this with dynamic selectors

export abstract class CountState {
  static get count() {
    return createSelector([this], (state: CountStateModel) => {
      return state.count
    })
  }
}

Updated the stackblitz with working code

You can send us a pull request for updating documentation.

@joaqcid we can close?

yup

Was this page helpful?
0 / 5 - 0 ratings

Related issues

un33k picture un33k  ·  4Comments

splincode picture splincode  ·  4Comments

abalad picture abalad  ·  5Comments

piernik picture piernik  ·  5Comments

TomDemulierChevret picture TomDemulierChevret  ·  3Comments