single page apps made easy
Go to file
2019-10-31 15:37:41 -05:00
cli new cli works 2019-10-31 15:32:08 -05:00
examples cli generates things for you 2019-10-31 00:05:55 -05:00
src holy boy, no more typing things 2019-10-30 23:55:56 -05:00
.gitignore cli generates things for you 2019-10-31 00:05:55 -05:00
.npmignore create .npmignore because speed 2019-10-31 15:37:41 -05:00
elm-analyse.json a fresh start :) 2019-10-15 23:52:54 -05:00
elm.json whoops, dat was v close 2019-10-29 21:45:53 -05:00
netlify.toml a fresh start :) 2019-10-15 23:52:54 -05:00
package-lock.json generate pages from cli tool 2019-10-24 00:41:17 -05:00
package.json Update package.json 2019-10-31 15:15:05 -05:00
README.md prevent lying by deleting false facts 2019-10-29 19:25:18 -05:00

ryannhg/elm-spa

an experiment for creating single page apps with Elm!

try it out

  1. npm install

  2. npm run dev

overview

module Main exposing (main)

import Application exposing (Application)
import Generated.Pages as Pages
import Generated.Route as Route
import Global


main : Application Global.Flags Global.Model Global.Msg Pages.Model Pages.Msg
main =
    Application.create
        { routing =
            { routes = Route.routes
            , toPath = Route.toPath
            , notFound = Route.NotFound ()
            }
        , global =
            { init = Global.init
            , update = Global.update
            , subscriptions = Global.subscriptions
            }
        , page = Pages.page
        }

keep your pages simple

(Instead of making everything an elm-fork-knife!)

page =
    Page.static
        { view = view
        }
page =
    Page.sandbox
        { init = init
        , update = update
        , view = view
        }
page =
    Page.element
        { init = init
        , update = update
        , subscriptions = subscriptions
        , view = view
        }
page =
    Page.component
        { init = init
        , update = update
        , subscriptions = subscriptions
        , view = view
        }

and your top level easy to read!

init appRoute =
    case appRoute of
        Route.Index route ->
            index.init route

        Route.Counter route ->
            counter.init route

        Route.Random route ->
            random.init route

( It's like magic, but actually it's just functions. )

the folder structure

src/
  Api/        -- for backend things
  Components/ -- reusable ui
  Data/       -- types used everywhere
  Layouts/    -- shared views
  Pages/      -- all your pages
  Utils/      -- helpers
  Global.elm  -- shared app state
  Main.elm    -- the entrypoint