Skip to content

Instantly share code, notes, and snippets.

@dvtate
Created July 8, 2022 01:23
Show Gist options
  • Save dvtate/e2aa70ef64a44eb05132c2eeae3c1028 to your computer and use it in GitHub Desktop.
Save dvtate/e2aa70ef64a44eb05132c2eeae3c1028 to your computer and use it in GitHub Desktop.
idk just thinking
// Contains entire app state
type State = {
name: String;
// ...
}
// Initializes state
function init(): State {
return {
name : "",
// ...
}
}
// Update function handles event changes
function update(state: State, ev: Event): State {
// pattern match on event
switch (ev.type) {
case Event.Type.InputChanged:
if (ev.input.id = "name-input")
return State { ...state, name: ev.input.value };
// branch on all possible event types
// if event type not handled, compiler errors
}
// alternatively could use function overloading
}
// Draws the app after update is called
function draw(state: State): DOM {
return GUISE("template.guise")
.bindValue("name-value", state.name)
// ... rest of the dynamically updated values
// Or maybe have entire GUISE template here?
// Elm has a super performant way checking what parts of DOM need to be updated
// Could maybe use similar algorithm here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment