Skip to content

Instantly share code, notes, and snippets.

this.store.select('games').pipe(untilDestroyed(this)).subscribe((res: IGames) => {});
import { Observable, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
function isFunction(value) {
return typeof value === 'function';
}
export const untilDestroyed = (
componentInstance,
destroyMethodName = 'ngOnDestroy'
forkJoin(
this._myService.makeRequest('Request One', 2000),
this._myService.makeRequest('Request Two', 1000),
this._myService.makeRequest('Request Three', 3000)
)
.subscribe(([res1, res2, res3]) => {
this.propOne = res1;
this.propTwo = res2;
this.propThree = res3;
});
@Sluchaika
Sluchaika / epics.ts
Last active December 27, 2018 13:39
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import {
environment as env
} from '../../../environments/environment';
import { Effect, ofType, Actions } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { switchMap } from 'rxjs/operators';
import { of, forkJoin } from 'rxjs';
import { catchError } from 'rxjs/internal/operators';
@Effect()
getGames: Observable<Action> = this.actions$.pipe(
ofType(GamesActions.GET_GAMES_REQUESTED),
switchMap(() => {
return forkJoin(this.http
.get(`${env.apiURL}/games?locale=${regionConfig.locale}`), this.http
.get(`${env.apiURL}/games/catalogues/${regionConfig.locale}`))
.defaultIfEmpty([])
.map(results => of(new GetGamesFailure(results)))
.subscribe(console.log);
@Effect({ dispatch: false })
getUser: Observable<Action> = this.actions$.pipe(
ofType(UserActionTypes.userGetAccount),
mergeMap((value: GetAccountAction) => {
const key: StateKey<number> = makeStateKey<number>('userData');
const data: UserData = this.transferState.get(key, null);
if (data) {
return Observable.of(new UpdateUserSuccess(data));
} else {
this.auth.validateUser().pipe(
...
changePosValue(pos) {
this.onStartSlideshow();
this.cPos = pos;
}
...
xp-slide(*ngFor="let slide of slides", [slide]="slide")
xp-slider-nav([slides]="slides", (changePos)="changePosValue($event)")
export class SliderNavComponent {
@Input() slides;
@Output() changePos: EventEmitter<String> = new EventEmitter<String>();
onChangeSlide (slideId) {
this.changePos.emit(slideId);
}
}
export class SomeChildComponent implements OnChanges {
@Input() save;
ngOnChanges(changes: SimpleChanges) {
if (changes.save && changes.save.currentValue) {
this.onSave();
}
}
onSave() {...}
}