Socket
Socket
Sign inDemoInstall

elm-ts

Package Overview
Dependencies
17
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    elm-ts

A porting of TEA to TypeScript featuring fp-ts, rxjs6 and React


Version published
Weekly downloads
169
decreased by-17.56%
Maintainers
1
Install size
604 kB
Created
Weekly downloads
 

Changelog

Source

0.6.0

  • Bug Fix

    • XMLHttpRequest's response headers in Response object (@StefanoMagrassi)
  • New Feature

    • new sendBy function in Http module which carries the full Response object (@StefanoMagrassi)

Readme

Source

elm-ts

A porting of The Elm Architecture to TypeScript featuring fp-ts, RxJS and React.

Installation

npm i elm-ts fp-ts rxjs react

Note: fp-ts, rxjs and react are peer dependencies

Differences from Elm

  • no ports
  • React instead of virtual-dom (pluggable)
  • Navigation is based on history

React

import * as React from 'elm-ts/lib/React'
import { render } from 'react-dom'
import * as component from './examples/Counter'

const main = React.program(component.init, component.update, component.view)

React.run(main, dom => render(dom, document.getElementById('app')!))

How to derive decoders from io-ts codecs

import * as t from 'io-ts'
import { failure } from 'io-ts/lib/PathReporter'

function fromCodec<A>(codec: t.Decoder<unknown, A>): Decoder<A> {
  return flow(
    codec.decode,
    E.mapLeft(errors => failure(errors).join('\n'))
  )
}

Enable debugger in development mode

For Html (and its specializations) programs:

import { programWithDebugger } from 'elm-ts/lib/Debug/Html'
import * as React from 'elm-ts/lib/React'
import { render } from 'react-dom'
import * as component from './examples/Counter'

const program = process.env.NODE_ENV === 'production' ? React.program : programWithDebugger

const main = program(component.init, component.update, component.view)

React.run(main, dom => render(dom, document.getElementById('app')!))

For Navigation (and its specializations) programs:

import { programWithDebuggerWithFlags } from 'elm-ts/lib/Debug/Navigation'
import * as Navigation from 'elm-ts/lib/Navigation'
import * as React from 'elm-ts/lib/React'
import { render } from 'react-dom'
import * as component from './examples/Navigation'

const program = process.env.NODE_ENV === 'production' ? Navigation.programWithFlags : programWithDebuggerWithFlags

const main = program(component.locationToMsg, component.init, component.update, component.view)

React.run(main(component.flags), dom => render(dom, document.getElementById('app')!))

Stop the application

If you need to stop the application for any reason, you can use the withStop combinator:

import { withStop } from 'elm-ts/lib/Html'
import * as React from 'elm-ts/lib/React'
import { render } from 'react-dom'
import { fromEvent } from 'rxjs'
import * as component from './examples/Counter'

const stopSignal$ = fromEvent(document.getElementById('stop-btn'), 'click')

const program = React.program(component.init, component.update, component.view)

const main = withStop(stopSignal$)(program)

React.run(main, dom => render(dom, document.getElementById('app')!))

The combinator takes a Program and stops consuming it when the provided Observable emits a value.

In case you want to enable the debugger, you have to use some specific functions from the Debug sub-module:

// instead of `programWithDebuggerWithFlags`
import { programWithDebuggerWithFlagsWithStop } from 'elm-ts/lib/Debug/Navigation'
import { withStop } from 'elm-ts/lib/Html'
import * as Navigation from 'elm-ts/lib/Navigation'
import * as React from 'elm-ts/lib/React'
import { render } from 'react-dom'
import * as component from './examples/Navigation'

const stopSignal$ = fromEvent(document.getElementById('stop-btn'), 'click')

const program =
  process.env.NODE_ENV === 'production'
    ? Navigation.programWithFlags
    : programWithDebuggerWithFlagsWithStop(stopSignal$)

const main = withStop(stopSignal$)(program(component.locationToMsg, component.init, component.update, component.view))

React.run(main(component.flags), dom => render(dom, document.getElementById('app')!))

Examples

Documentation

Keywords

FAQs

Last updated on 02 Sep 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc