Store: Calling a static function in selector function will result in undefined value

Created on 6 Feb 2019  路  8Comments  路  Source: ngxs/store

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => https://github.com/ngxs/store/blob/master/CONTRIBUTING.md
[ ] Other... Please describe:

Current behavior


If I call a helper static function from my selector function it does not continue afterwards and my observable emits undefined value.

Expected behavior


I should be able to call a static function and the flow should continue.

Minimal reproduction of the problem with instructions

  @Selector() 
  static pandas(state: string[]) {
    this.doNothing();
    return state.filter(s => s.indexOf('panda') > -1);
  }

  static doNothing() {}

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


To be able to write complex selectors using helper functions

Environment


Libs:
- @angular/core version: 7.1.4
- @ngxs/store version: 3.3.3


Browser:
- [x] Chrome (desktop) version 71
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

For Tooling issues:
- Node version: XX  
- Platform:  

Others:

All 8 comments

Create stackblitz example please

@splincode this is undefined inside selector, just call console.log(typeof this), also it's wrapped in try-catch thus there is no exception like cannot read property 'doNothing' of undefined

@ogix this is related to context call loss, I'll try to have a look this evening

ok, thanks!

I looked at the source code and found this.
https://github.com/ngxs/store/blob/bf13efed028ec2bbe3ca1561730237ad7f796abc/packages/store/src/utils/selector-utils.ts#L20

Shouldn't this be written in TS syntax?
const wrappedFn = (...args: any[]) => {

@ogix fixed man :rocket:

Was this page helpful?
0 / 5 - 0 ratings