Skip to content

Instantly share code, notes, and snippets.

@nilsmehlhorn
nilsmehlhorn / matcher.ts
Last active Jan 31, 2020
Small and configurable full-text search on objects in TypeScript
View matcher.ts
export type Matcher<T> = (query: string) => T[];
export type ValueProject<T> = (target: T) => Array<string | number>;
export type MatcherFactory = <T>(targets: T[], project: ValueProject<T>) => Matcher<T>;
export const defaultProject = <T>(target: T) => Object.values(target);
const isMatchable = prop => typeof prop == 'number' || typeof prop == 'string'
@jsonberry
jsonberry / helpful-javascript-utilities.js
Last active Oct 6, 2020
Helpful JavaScript Utilities
View helpful-javascript-utilities.js
// zip arrays together
// Catalin Dumitru @colin_dumitru
// Jason Awbrey @jsawbrey
const zip = (a, b) => a.map((n, i) => [n, b[i]])
// merge objects in an array together
// caution: properties are overridden if duplicated
// @a [{a},{b}]
// @returns [{a, b}]
// Jason Awbrey @jsawbrey
@jsonberry
jsonberry / onload.js
Last active Jun 22, 2021
Window vs. Document Loading Events
View onload.js
/**
Taken from: http://stackoverflow.com/questions/588040/window-onload-vs-document-onload
According to Parsing HTML documents - The end,
The browser parses the HTML source and runs deferred scripts.
A DOMContentLoaded is dispatched at the document when all the HTML has been parsed and have run. The event bubbles to the window.
The browser loads resources (like images) that delay the load event.
A load event is dispatched at the window.
Therefore, the order of execution will be
DOMContentLoaded event listeners of window in the capture phase
DOMContentLoaded event listeners of document
@Dorus
Dorus / index.js
Last active May 6, 2021 — forked from xgrommx/index.js
How we can make methods of observable via other methods
View index.js
const flatMap = (fn, stream, resultSelector) =>
stream.flatMap((x, xi) => fn(x).map((y, yi) => resultSelector(x, y, xi, yi)));
const flatMapLatest = (fn, stream) =>
stream.publish(s => s.flatMap(v => fn(v).takeUntil(s)));
const flatMapLatest = (fn, stream, resultSelector) => stream.publish(s => {
return s.flatMap(v => fn(v), resultSelector).takeUntil(s));
});
@staltz
staltz / introrx.md
Last active Jun 24, 2021
The introduction to Reactive Programming you've been missing
View introrx.md