Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxJS Lettable Operators #583

Closed
phillipzada opened this issue Nov 20, 2017 · 2 comments
Closed

RxJS Lettable Operators #583

phillipzada opened this issue Nov 20, 2017 · 2 comments

Comments

@phillipzada
Copy link
Contributor

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[x] Documentation issue or request

What is the current behavior?

No examples using the lettable operators in example or documentation for effects
https://github.com/ReactiveX/rxjs/blob/master/doc/lettable-operators.md

Expected behavior:

Documentation and example app to be updated

Minimal reproduction of the problem with instructions:

N/A

Version of affected browser(s),operating system(s), npm, node and ngrx:

N/A

Other information:

Would like to submit a PR to show in one effect and documentation how to utilise Lettable Operators

@MattiJarvinen
Copy link

For those who need this "now".

// rxjs
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import { 
  catchError,
  debounceTime, 
  distinctUntilChanged,
  map, 
  skip, 
  switchMap, 
  takeUntil,
} from 'rxjs/operators';

// @ngrx/platform
import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Action, Store } from '@ngrx/store';

// application 
import {
  DistrictActionType,
  LoadDistrictsAction,
  SearchDistrictErrorAction
} from '../actions/district';
import { DistrictService } from '../services/district.service';
import { District } from '../models/district';

@Injectable()
export class DistrictEffects {

  @Effect()
  public search$: Observable<Action> = this.actions$
    .ofType(DistrictActionType.SEARCH_DISTRICT) // event type to listen
    .pipe(
    // wait 300 ms for additional changes to occur
    debounceTime(300),
    distinctUntilChanged(),
    // just the payload
    map(toPayload),
    switchMap(query => {

      if (query) {
        console.warn('District search not implemented');
      }

      const nextSearch$ = this.actions$.ofType(DistrictActionType.SEARCH_DISTRICT).skip(1);

      return this.districtService.list()
        .pipe(
        takeUntil(nextSearch$),
        map((districts: District[]) => {
          return new LoadDistrictsAction(districts);
        }),
        catchError((err: any) => {
          console.log('err in effect UserEffects', err);
          return of(new SearchDistrictErrorAction(err))
        })
        );
    }),
  );
  constructor(
    private actions$: Actions,
    private districtService: DistrictService,
  ) { }
}

@MattiJarvinen
Copy link

For readers of my previous example.

Currently there is an angular-cli issue realted to Rxjs/operators import:
bug: all RxJS operators pulled into prod bundle when using lettable imports from 'rxjs/operators'
angular/angular-cli#9069 (comment)

This is related to:

Workaround based on comments might be to use deep imports like 'rxjs/operators/catchError'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants