You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@teamthread/elm-web-components

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teamthread/elm-web-components

Run your Elm apps through web components.

0.1.0
npmnpm
Version published
Weekly downloads
1.1K
6.96%
Maintainers
2
Weekly downloads
 
Created
Source

elm-web-components

A small JavaScript package to let you wrap your Elm applications up in a web component.

Install

yarn add @teamthread/elm-web-components

Example

Given the following Elm app:

module Component exposing (..)

import Html exposing (text, Html)

type Msg
    = NoOp


type alias Model =
    { name : String
    }


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    ( model, Cmd.none )

view : Model -> Html Msg
view model =
  text ("Hello world, my name is: " ++ model.name)


type alias Flags =
    { name : String }

init : Flags -> ( Model, Cmd Msg )
init flags =
    ( Model flags.name, Cmd.none )


main : Program Flags Model Msg
main =
    Html.programWithFlags
        { init = init, update = update, subscriptions = \_ -> Sub.none, view = view }

You can create a custom web element that will render it like so:

import elmWebComponents from '@teamthread/elm-web-components'
import ElmApp from './Main.elm'

elmWebComponents.register('demo-elm-component', Component)

And now in your HTML you can use the component:

<demo-elm-component name="Jack"></demo-elm-component>

Any attributes are passed into your Elm app as Flags, so make sure you use programWithFlags if you care about them. If you don't you can just use Html.program as you would normally.

Ports

You can also hook up a component that uses ports. The third argument to elmWebComponents.register is a function that will be called with the ports object that Elm provides, so you can then hook into it and subscribe and send to them as you would normally:

elmWebComponents.register('component-with-ports', ComponentWithPorts, ports =>
  ports.somePort.send(1)
  ports.someOtherPort.subscribe(...)
)

You can find a full example of this in the example directory.

FAQs

Package last updated on 21 Feb 2018

Did you know?

Socket

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