Skip to content

Instantly share code, notes, and snippets.

View armanozak's full-sized avatar

Levent Arman Özak armanozak

View GitHub Profile
@armanozak
armanozak / rxjs-7_firstValueFrom-lastValueFrom.ts
Created May 3, 2021 08:52
[What's New in RxJS 7] RxJS 7 firstValueFrom and lastValueFrom #blog #rxjs
import { interval, firstValueFrom, lastValueFrom } from "rxjs";
import { map, take } from "rxjs/operators";
const count1To5$ = interval(1000).pipe(
take(5),
map(i => i + 1)
);
firstValueFrom(count1To5$).then(console.log);
// (after ~1s) 1
@armanozak
armanozak / rxjs-6_toPromise-no-error.ts
Created May 3, 2021 08:53
[What's New in RxJS 7] RxJS 6 no error with toPromise #blog #rxjs
import { EMPTY } from "rxjs";
EMPTY.toPromise().then(console.log);
// (asynchronously) undefined
@armanozak
armanozak / rxjs-7_lastValueFrom-EmptyErrorImpl.ts
Created May 3, 2021 08:54
[What's New in RxJS 7] RxJS 7 EmptyErrorImpl with lastValueFrom #blog #rxjs
import { EMPTY, firstValueFrom } from "rxjs";
lastValueFrom(EMPTY).catch(console.log);
// (asynchronously) EmptyErrorImpl
@armanozak
armanozak / rxjs-7_detect-empty-error.ts
Created May 3, 2021 08:58
[What's New in RxJS 7] RxJS 7 detect empty error with EmptyError #blog #rxjs
import { EMPTY, EmptyError, lastValueFrom } from "rxjs";
lastValueFrom(EMPTY).catch(err => console.log(err instanceof EmptyError));
// (asynchronously) true
@armanozak
armanozak / rxjs-7_createErrorClass.ts
Created May 3, 2021 09:00
[What's New in RxJS 7] How EmptyError is created in RxJS #blog #rxjs
export const EmptyError: EmptyErrorCtor = createErrorClass(
_super =>
function EmptyErrorImpl(this: any) {
_super(this);
this.name = "EmptyError";
this.message = "no elements in sequence";
}
);
@armanozak
armanozak / rxjs-7_alternative_EmptyError_constructor.ts
Created May 3, 2021 09:01
[What's New in RxJS 7] An alternative available for ES6+ builds #blog #rxjs
export class EmptyError extends Error {
constructor() {
super("no elements in sequence");
this.name = "EmptyError";
}
}
@armanozak
armanozak / rxjs-6_forkJoin-dictionary.ts
Created May 3, 2021 09:02
[What's New in RxJS 7] Observable dictionaries in RxJS 6 forkJoin #blog #rxjs
import { forkJoin, interval } from "rxjs";
import { map } from "rxjs/operators";
const count1To5$ = interval(1000).pipe(
take(5),
map(i => i + 1)
);
const count6To9$ = interval(1000).pipe(
take(4),
@armanozak
armanozak / rxjs-7_combineLatest-dictionary.ts
Created May 3, 2021 09:03
[What's New in RxJS 7] Observable dictionaries in RxJS 7 combineLatest #blog #rxjs
import { combineLatest, interval } from "rxjs";
import { map } from "rxjs/operators";
const count1To5$ = interval(1000).pipe(
take(5),
map(i => i + 1)
);
const count6To9$ = interval(1000).pipe(
take(4),
@armanozak
armanozak / rxjs-6_combineLatest.ts
Created May 3, 2021 09:04
[What's New in RxJS 7] RxJS 6 combineLatest #blog #rxjs
import { interval } from "rxjs";
import { combineLatest, map } from "rxjs/operators";
const count1To5$ = interval(1000).pipe(
take(5),
map(i => i + 1)
);
const count6To9$ = interval(1000).pipe(
take(4),
@armanozak
armanozak / rxjs-7_combineLatestWith.ts
Created May 3, 2021 09:04
[What's New in RxJS 7] RxJS 7 combineLatestWith #blog #rxjs
import { interval } from "rxjs";
import { combineLatestWith, map } from "rxjs/operators";
const count1To5$ = interval(1000).pipe(
take(5),
map(i => i + 1)
);
const count6To9$ = interval(1000).pipe(
take(4),