Skip to content

Instantly share code, notes, and snippets.

import { of } from 'rxjs';
import { map, mergeMap } from 'rxjs/operators';
of(1).pipe(
map(async () => await Promise.resolve('hello?')),
// mergeMap incuded here because of how it's written in the original code.
// It has no effect on the async value that's passed in.
mergeMap(customerId => {
// Promise { <pending> }
console.log(customerId);
import { of } from 'rxjs';
import { switchMap, map, catchError } from 'rxjs/operators';
of(1, 2, 3, 4, 5).pipe(
switchMap(x => of(x)),
map(x => {
if (x != 3) {
return `x: ${x}`
}
throw 'x is 3';

So a bit of JavaScript 102... The other day we were writing a test to confirm that after a function runs, our store has emitted certain action. In summary:

test('correct actions', () => {
  const expectedActions = ...

  store.run(LOAD);
  const actualActions = store.getActions();
export interface Foldable<F, A> {
reduce: (fn: (b: A, a: A) => A, initial: A, foldable: F) => A;
}
export const getArrayFold = <R, Q extends Array<R> = Array<R>>(): Foldable<Q, R> => {
return {
reduce: (fn, initial, array) => {
return array.reduce(fn, initial);
}
};
import { mergeMap, switchMap, take, mapTo, map } from 'rxjs/operators';
import { fromPromise } from 'rxjs/observable/fromPromise';
import { of } from 'rxjs/observable/of';
import { interval } from 'rxjs/observable/interval';
import { request } from 'universal-rxjs-ajax';
const getIt = () =>
fromPromise((async () => {
await Promise.resolve();
})()).pipe(switchMap(() => request({ url: 'https://api.github.com/users/ajcrites' })
interface KeyVal {
customerID: string;
isLoggedIn: boolean;
count: number;
}
const sensi = <T extends keyof KeyVal>(key: T, value: KeyVal[T]) => {
};
module.exports = (req, res, next) => {
if (!req || !req.length) {
res.status(404);
}
next();
};
const map = <T, R = T>(items: T[], cb: (item: T) => R): R[] => {
const mapped: R[] = [];
for (let item of items) {
mapped.push(cb(item));
}
return mapped;
};
interface Foo {
foo: string;
}
const fn = () => ({
foo: 'bar',
bar: 'baz',
});
const fooImpl: Foo = fn();
import { timer } from 'rxjs/observable/timer';
import { fromEvent } from 'rxjs/observable/fromEvent';
import {
concatMap,
filter,
map,
switchMap,
takeUntil,
tap,
} from 'rxjs/operators';