store: 6.4.1 breaks @select mocking

This is a…

  • feature request
  • bug report
  • usage question

What toolchain are you using for transpilation/bundling?

Environment

NodeJS Version: 6.10.2 Typescript Version: 2.3.4 Angular Version: 4.0.0 @angular-redux/store version: 6.4.1 @angular/cli version: (if applicable) 1.0.0 OS: MacOS

Link to repo showing the issus

(optional, but helps a lot)

Expected Behaviour:

Mocking Selectors and firing them should actually call all subscribers

progressStub = MockNgRedux.getSelectorStub(StateSelectors.getProgress);
progressStub.next({ steps: [], index: 0 });

Actual Behaviour:

Subscribers are not being called

export class MyComponent implements OnInit {
    @select(StateSelectors.getProgress) progress$: Observable<CreateStreamProgress>;

    ngOnInit() {
        this.progress$.subscribe(progress => { ... }); // <-- not called
    }
}

Stack Trace/Error Message:

Additional Notes:

(optional)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 36 (21 by maintainers)

Commits related to this issue

Most upvoted comments

@ialibhay yeah that makes sense. Thanks!

I’ll try and hack up a fix tonight. We’ll need to make MockNgRedux.reset() somehow hook into all the @select instances… fun times.

As far as I can tell, since the decorator now caches the selection (which is great for the actual app since the store shouldn’t be reset mid-usage there), the mock reset also somehow needs to tell all the decorators to clear their cached state.

Taking a look

@SethDavenport thank you for working on this and fixing. This is a great library and I am using it in earnest!

Fix PR up here: https://github.com/angular-redux/store/pull/414

@ajdaniel can you try 6.4.2-beta.0 and let me know if that fixes the issue for you? If so I’ll push out 6.4.2 officially tomorrow.

@gregkopp Also note that @select((state: AppState) => state.accountState) accountState$ will unfortunately break AoT because it can’t handle anonymous arrow functions 😦

So in your case you can solve both issues by either adopting the PropertySelector approach (@select('accountState') accountState$) or by pulling the arrow function out, giving it a name, and exporting it (to keep AoT happy):

Component:

export const selectAccountState = (state: AppState) => state.accountState;

//...

class AppHeaderComponent {
  @select(selectAccountState) accountState$;

  // ...
}

Test:

// Since we have to export the arrow function for AoT anyway, we might as well import it to
// key our selector stub in the tests:
import { AppHeaderComponent, selectAccountState } from './app-header.component.ts';

// ...

accountSelector = MockNgRedux.getSelectorStub(accountStateSelector);
accountSelector.next({ someProperty: 'someValue' }); 

// ...

I’ll investigate further and get back to you as soon as I can @SethDavenport. Thank you for investigating