Skip to content

Instantly share code, notes, and snippets.

@GarryBrown
GarryBrown / app.module.ts
Created February 26, 2018 16:42
Import Effects
import { EffectsModule } from '@ngrx/effects';
import { MovieEffects } from './effects/movie.effects';
@NgModule({
imports: [
...
EffectsModule.forRoot([MovieEffects])
]
})
export class AppModule {}
@GarryBrown
GarryBrown / movie.effect.ts
Created February 26, 2018 16:50
Simple effect to load data
import { Injectable } from '@angular/core';
import { Effect, Actions } from '@ngrx/effects';
import { of } from 'rxjs/observable/of';
import { map, switchMap, catchError } from 'rxjs/operators';
import * as fromRoot from '../../../app/store';
import * as movieActions from '../actions/movie.action';
import * as fromServices from '../../services';
if (isFunction(_unsubscribe)) {
try {
_unsubscribe.call(this);
} catch (e) {
// some error logic
}
}
export interface SubscriptionLike extends Unsubscribable {
unsubscribe(): void;
readonly closed: boolean;
}
constructor(unsubscribe?: () => void) {
if (unsubscribe) {
(<any> this)._unsubscribe = unsubscribe;
}
}
constructor(unsubscribe?: () => void) {
if (unsubscribe) {
(<any> this)._unsubscribe = unsubscribe;
}
}
/** @internal */
protected _parentOrParents: Subscription | Subscription[] | null = null;
/** @internal */
private _subscriptions: SubscriptionLike[] | null = null;
class Subscriber<T> extends Subscription implements Observer<T> {...}
interface Observer<T> {
closed?: boolean;
next: (value: T) => void;
error: (err: any) => void;
complete: () => void;
}
protected destination: Observer<any> | Subscriber<any>;
constructor(destinationOrNext?: PartialObserver<any> | ((value: T) => void) | null,
error?: ((e?: any) => void) | null,
complete?: (() => void) | null) {
super();
switch (arguments.length) {
case A:
this.destination = emptyObserver;
next(value?: T): void {
if (!this.isStopped) {
this._next(value!);
}
}
error(err?: any): void {
if (!this.isStopped) {
this.isStopped = true;
this._error(err);