This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.1.0
README

History

Manage browser history and link creation using the HTML5 history API.

type alias History view = { parser : String -> view , router : view -> String }

History's prime concern is turning URIs into views, and views into URIs.

type alias Router view = view -> String
type alias Parser view = String -> view
type alias Path = List String

A path is just a URI split up into sections. For example /account/1234/settings would convert to the path ["account", "1234", "settings"].

create : (Path -> view) -> (view -> Path) -> History view

Create a history manager by supplying one function that goes from Path to view, and one that goes the other way from view to Path.

module History exposing (History, Router, Parser, Path, create)

{-| Manage browser history and link creation using the HTML5 history API.

@docs History, Router, Parser, Path, create
-}

import String exposing (split, join)
import Utils exposing (removePrefix)


{-| History's prime concern is turning URIs into views, and views into URIs.
-}
type alias History view =
    { parser : String -> view
    , router : view -> String
    }


{-| -}
type alias Router view =
    view -> String


{-| -}
type alias Parser view =
    String -> view


{-| A path is just a URI split up into sections. For example
`/account/1234/settings` would convert to the path
`["account", "1234", "settings"]`.
-}
type alias Path =
    List String


{-| Create a history manager by supplying one function that goes from
`Path` to `view`, and one that goes the other way from `view` to
`Path`.
-}
create : (Path -> view) -> (view -> Path) -> History view
create fromPath toPath =
    { parser = fromUri fromPath
    , router = toUri toPath
    }


fromUri : (Path -> view) -> Parser view
fromUri fromPath =
    removePrefix "#/" >> split "/" >> fromPath


toUri : (view -> Path) -> Router view
toUri toPath =
    toPath >> join "/" >> (++) "#/"