-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Labels
Comments
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,
) { }
} |
For readers of my previous example. Currently there is an angular-cli issue realted to Rxjs/operators import: 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
I'm submitting a...
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
The text was updated successfully, but these errors were encountered: