This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sourcecode | |
| case class Symbol(name: String)(implicit line: sourcecode.Line) | |
| case class Struct(tag: Symbol, entries: Map[Symbol, Struct]) | |
| sealed trait TypeTerm | |
| case class Union(cases: Map[Symbol, Map[Symbol, TypeTerm]]) extends TypeTerm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ns = [ | |
| { name: "a", x: 200.01, y: 200.01 }, | |
| { name: "b", x: 220, y: 220 }, | |
| { name: "c", x: 180, y: 200.01 }, | |
| { name: "d", x: 182, y: 201 }, | |
| { name: "e", x: 230, y: 170 }, | |
| { name: "f", x: Math.random() * 400, y: Math.random() * 400 }, | |
| { name: "g", x: Math.random() * 400, y: Math.random() * 400 }, | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const match = <T>(item: T) => < | |
| Matchers extends ((item: T) => Match<any> | undefined)[] | |
| >( | |
| ...cases: Matchers | |
| ): Exclude<ReturnType<Matchers[number]>, undefined>["value"] => { | |
| for (const matcher of cases) { | |
| const result = matcher(item) as ReturnType<Matchers[number]>; | |
| if (result) { | |
| return result.value; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DataValid<T, E> { | |
| constructor(public data: T) {} | |
| } | |
| class DataInvalid<T, E> { | |
| constructor(public error: E, public got: unknown) {} | |
| } | |
| type DataValidity<T, E> = DataValid<T, E> | DataInvalid<T, E>; | |
| type DataValidator<T, E> = (data: unknown) => DataValidity<T, E>; | |
| type DataValidatorData< |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function pipe<A, B>(f: (a: A) => B) { | |
| return { | |
| end: f, | |
| pipe<C>(g: (b: B) => C) { | |
| return pipe((a: A) => g(f(a))); | |
| } | |
| }; | |
| } | |
| function compose<A, B>(f: (a: A) => B) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TaggedUnionValue< | |
| TaggedUnion extends { [K in keyof TaggedUnion]: any[] }, | |
| Tag extends keyof TaggedUnion | |
| > { | |
| constructor( | |
| private readonly tag: Tag, | |
| private readonly value: TaggedUnion[Tag], | |
| ) {} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const status = Symbol(); | |
| const value = Symbol(); | |
| const set = Symbol(); | |
| const listeners = Symbol(); | |
| class Promise { | |
| constructor(callback) { | |
| this[listeners] = []; | |
| this[status] = "pending"; | |
| const resolve = value => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| type Dictionary = Record<string, string | ((arg: any) => string)>; | |
| export type L12n<T extends Dictionary> = T; | |
| export function makeI18n<T extends Dictionary>() { | |
| const Context = React.createContext<T | undefined>(undefined); | |
| const I18ContextConsumer = Context.Consumer; | |
| const I18ContextProvider = Context.Provider; | |
| function I18n<K extends keyof T>( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type DataTypeUnion = ObjectType<any> | ArrayType<any> | PrimitiveTypeUnion; | |
| type PrimitiveTypeUnion = typeof string | typeof number | typeof boolean; | |
| interface QueryType< | |
| Params extends { [key: string]: PrimitiveTypeUnion }, | |
| T extends DataTypeUnion | |
| > { | |
| kind: "query"; | |
| params: Params; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| view: | |
| component: composition of | |
| helper: prepare data for template so no code goes into the tempalte | |
| template: does only view, can dispatch events | |
| container: composition of | |
| injector: grabs data from state | |
| wireframe: conecptual representation of ui, it's a projections of data to display and possible actions | |
| domain: |