Skip to content

Instantly share code, notes, and snippets.

@kofigumbs
Last active September 2, 2017 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kofigumbs/96befae3edee4b96783ae2ea4ef57a23 to your computer and use it in GitHub Desktop.
Save kofigumbs/96befae3edee4b96783ae2ea4ef57a23 to your computer and use it in GitHub Desktop.
Simple illustration of The Elm Architecture
// This is the thing you give to Elm, your purely functional core,
// which exposes init, view, and update.
const app = require('./business-logic')
// This represents the implementations for all the side effects
// that your program knows how to requests.
// There is only one public function, perform(cmd: Cmd<Msg>) -> Promise<Msg>.
const runtime = require('./side-effects')
// Let's do some a actual work!
var [ model, initialCmd ] = app.init()
function main(cmd) {
runtime.perform(cmd).then(msg => {
// Call into the app in order to get the updated model and command.
[ newModel, newCmd ] = app.update(msg, model)
// Keep track of the state globally.
// This ensures that parallel commands always use the most recent version.
model = newModel
// Display HTML (this illustration doesn't cover HTML events).
app.view(model)
// Recurse into main to do the next command!
main(newCmd)
})
}
main(initialCmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment