effe-ts
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

effe-ts

Fork of elm-ts. Effe is the german word for elm.

Install

yarn add effe-ts

Usage

Counter example

import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { html, state } from 'effe-ts'

type Action = { type: 'Increase' } | { type: 'Decrease' }

type Model = number

interface State extends state.State<{}, Model> {}

const init: State = state.of(0)

const update = (action: Action) => (model: Model): State => {
  switch (action.type) {
    case 'Increase':
      return state.of(model + 1)
    case 'Decrease':
      return state.of(model - 1)
  }
}

function view(model: Model): html.Html<JSX.Element, Action> {
  return dispatch => (
    <>
      <span>Counter: {model}</span>
      <button onClick={() => dispatch({ type: 'Increase' })}>+</button>
      <button onClick={() => dispatch({ type: 'Decrease' })}>-</button>
    </>
  )
}

const app = html.program(init, update, view)

html.run(app, dom => ReactDOM.render(dom, document.getElementById('app')!), {})

Further examples

Package Sidebar

Install

npm i effe-ts

Weekly Downloads

0

Version

0.5.0

License

MIT

Unpacked Size

81.8 kB

Total Files

32

Last publish

Collaborators

  • mlegenhausen