//// What is TypeScript?
// ts is super set of js
// + types
// + typecheck
// + transpiler(like babel)
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 getCssElmClasses() { | |
const a = [...document.styleSheets] | |
.map((b) => [...b.cssRules]) | |
.flat() | |
.map((b) => b instanceof CSSMediaRule ? [...b.cssRules] : [b]) | |
.flat() | |
.map((b) => b.selectorText) | |
.filter((b) => b) | |
.map((b) => b.split(",")) | |
.flat() |
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 Elm.Kernel.Scheduler exposing (binding, succeed) | |
import Elm.Kernel.Utils exposing (Tuple0) | |
*/ | |
function _Process_sleep(time) | |
{ |
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
export function app<Msg, Model>(model: Model, updateFn: (msg: Msg, model: Model) => Model) { | |
return (msg: Msg) => { | |
defer(() => { | |
model = updateFn(msg, model) | |
}) | |
} | |
} | |
export function defer(fn: () => void): void { | |
Promise.resolve().then(fn) |
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
export type List<A> = Array<A> | |
export type Maybe<A> = A | null | |
export type Cmd<Msg> = Maybe<(_: sendMsg<Msg>) => void> | |
type updateFn<Msg, Model> = (_: Msg) => (_: Model) => [Model, Cmd<Msg>] | |
type sendMsg<Msg> = (_: Msg) => void | |
export let elmTsRuntime: <Msg, Model>(_: [Model, Cmd<Msg>]) => (_: updateFn<Msg, Model>) => void | |
elmTsRuntime = ([model, cmd]) => update => { | |
const sendMsg = (msg: any) => { |
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
try { | |
main() | |
} catch (e) { | |
document.body.textContent = "" | |
create(document.body, "h1", "m-3").textContent = "😔" | |
create(document.body, "pre", "m-3").textContent = e | |
throw e | |
} | |
function main() { |
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
declare const Elm: Elm | |
interface Elm { | |
Main: AppConstructor<unknown, { port1: SubscribePort<unknown>; port2: SendPort<unknown> }> | |
} | |
interface AppConstructor<Flags, Ports> { | |
init(options: { node?: HTMLElement; flags: Flags }): { ports: Ports } | |
} |
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
port module Main exposing (..) | |
type alias Input = | |
{ argv : List String, stdin : String } | |
type alias Output = | |
{ code : Int, stdout : String, stderr : String } |
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
export function createState(reducer) { | |
const State = createContext([]) | |
function getInitialState() { | |
return reducer(undefined, { type:"@@INIT" }) | |
} | |
function StateProvider({ children }) { | |
return createElement(State.Provider, { value: useReducer(reducer, undefined, getInitialState), children }) | |
} |
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
new class { | |
constructor() { | |
this.nodes = this.find('.position_sticky').map(el => { return { el, placeholder: null } }) | |
window.addEventListener('scroll', e => this.go(), { passive: true }) | |
this.go() | |
} | |
go() { | |
this.nodes.forEach(node => this.check(node)) | |
} |
NewerOlder