Skip to content
A reusable rater for Elm.
Elm HTML Shell
Branch: master
Clone or download
Latest commit 3f4a201 Oct 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Build a rater Oct 8, 2019
.gitignore Build a rater Oct 8, 2019
LICENSE Add a LICENSE Oct 8, 2019
README.md Update the README Oct 8, 2019
build.sh Build a rater Oct 8, 2019
elm.json Build a rater Oct 8, 2019
example-raters.png Update the README Oct 8, 2019
index.html Build a rater Oct 8, 2019

README.md

Elm Rater

A reusable rater for Elm.

A screenshot of example raters

Usage

N.B. Work in progress. Not a library you can elm install as yet. But feel free to reuse the code, Rater and Rater.Rating as you see fit.

import Rater
import Rater.Rating as Rating exposing (Rating)

-- ...

type alias Model =
  { rating : Rating
  , rater : Rater.State

  -- ...
  }

-- ...

init : Model
init =
  { rating = Rating.rate 3 5
  , rater = Rater.init

  -- ...
  }

-- ...

type Msg
  = NewRaterMsg Rater.Msg
  | ChangedRater Int
  -- ...

-- ...

update : Msg -> Model -> Model
update msg model =
  case msg of
    NewRaterMsg raterMsg ->
      let
        (newState, maybeMsg) =
          Rater.update ChangedRater model.rating raterMsg model.rater

        newModel =
          { model | rater = newState }
      in
        case maybeMsg of
          Nothing ->
            newModel

          Just newMsg ->
            update newMsg newModel

    ChangedRater newAmount ->
      { model | rating = Rating.change newAmount model.rating }

    -- ...

-- ...

view : Model -> Html Msg
view model =
  div
    []
    [ Html.map NewRaterMsg (Rater.view model.rating model.rater) ]

Demo

Check out the demo and view its code if you want to learn how to handle more advanced use cases.

Credits

The video of the API design session that Evan and Greg recorded was an invaluable resource.

The following libraries also provided great working examples of how to approach API design in Elm:

You can’t perform that action at this time.