Skip to content

Instantly share code, notes, and snippets.

View dbrack's full-sized avatar

Dominik Brack dbrack

View GitHub Profile
const handler = {
get(target, propKey, receiver) {
if (/^_[0-9]+$/.test(propKey)) {
const result = [];
const first = Number(receiver);
const last = Number(propKey.slice(1));
for (let i=first; i<=last; i++) {
result.push(i);
}
return result;
export type Tuple2<A, B> = [A, B];
export type Tuple3<A, B, C> = [A, B, C];
export type Tuple4<A, B, C, D> = [A, B, C, D];
export type Tuple5<A, B, C, D, E> = [A, B, C, D, E];
export type Tuple6<A, B, C, D, E, F> = [A, B, C, D, E, F];
export type Tuple7<A, B, C, D, E, F, G> = [A, B, C, D, E, F, G];
export type Tuple8<A, B, C, D, E, F, G, H> = [A, B, C, D, E, F, G, H];
export type Tuple9<A, B, C, D, E, F, G, H, I> = [A, B, C, D, E, F, G, H, I];
export type Tuple10<A, B, C, D, E, F, G, H, I, J> = [A, B, C, D, E, F, G, H, I, J];

Using server-sent events

Why and how?

  • Documentation: https://web.dev/articles/eventsource-basics
  • Use case: broadcasting data from server to browsers
  • Benefits:
    • Easy to understand and implement (only a few lines of code)
    • No library is needed
  • Can use same HTTP(S) authentication as elsewhere in the app (which can’t be done with websockets)
import invariant from "tiny-invariant";
class AmalgoBox extends HTMLElement {
get input() {
return this.querySelector("input") as HTMLInputElement;
}
get button() {
return this.querySelector("button") as HTMLButtonElement;
}