Skip to content
/ jelms Public

Elm inspired state management for TypeScript apps

Notifications You must be signed in to change notification settings

anylabs/jelms

Repository files navigation

Jelms

Elm inspired state management for TypeScript apps. Tiny size (223 bytes minified and gzipped) makes it a perfect partner in crime with Preact.

Examples

You can some some examples under the Jelms Examples repo. Here is the canonical counter app:

import { h, render } from "preact"
import { program } from "jelms"

type Model = {
  readonly counter: number
}

type Decrement = {
  type: "Decrement"
}

type Increment = {
  type: "Increment"
}

type Msg = Decrement | Increment

program<Model, Msg>({
  init() {
    return { counter: 0 }
  },

  update(model, msg) {
    switch (msg.type) {
      case "Decrement":
        return { counter: model.counter - 1 }

      case "Increment":
        return { counter: model.counter + 1 }
    }
  },

  view(model, emit) {
    render(
      <div>
        <h1>{model.counter}</h1>
        <button onClick={() => emit({ type: "Decrement" })}>-</button>
        <button onClick={() => emit({ type: "Increment" })}>+</button>
      </div>,
      document.body,
    )
  },
})

About

Elm inspired state management for TypeScript apps

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published