elm-spa/README.md

121 lines
2.5 KiB
Markdown
Raw Normal View History

2019-10-27 01:49:52 +03:00
# ryannhg/elm-spa
2019-10-16 07:52:54 +03:00
> an experiment for creating single page apps with Elm!
2019-10-05 01:16:02 +03:00
2019-11-01 07:44:36 +03:00
### trying it out
2019-10-08 08:22:17 +03:00
2019-11-01 07:45:25 +03:00
__Note__: the API is still experimental! (hoping to post on discourse soon for community feedback)
2019-10-05 01:16:02 +03:00
2019-11-01 07:44:36 +03:00
```
elm install ryannhg/elm-spa
```
2019-10-05 01:16:02 +03:00
2019-10-16 07:52:54 +03:00
### overview
2019-10-05 01:16:02 +03:00
2019-10-08 08:22:17 +03:00
```elm
module Main exposing (main)
2019-10-05 01:16:02 +03:00
2019-11-01 07:44:36 +03:00
import Application
2019-10-16 07:52:54 +03:00
import Generated.Pages as Pages
2019-10-26 20:06:16 +03:00
import Generated.Route as Route
import Global
2019-10-05 01:16:02 +03:00
2019-10-08 08:22:17 +03:00
main =
2019-10-16 07:52:54 +03:00
Application.create
{ ui = Application.usingHtml
2019-11-01 07:44:36 +03:00
, routing =
2019-10-26 20:06:16 +03:00
{ routes = Route.routes
, toPath = Route.toPath
, notFound = Route.NotFound ()
}
, global =
{ init = Global.init
, update = Global.update
, subscriptions = Global.subscriptions
}
2019-10-30 03:25:18 +03:00
, page = Pages.page
2019-10-08 23:06:03 +03:00
}
```
2019-10-26 20:06:16 +03:00
### keep your pages simple
2019-10-27 01:53:14 +03:00
(Instead of making everything an [elm-fork-knife](https://youtu.be/RN2_NchjrJQ?t=2362)!)
2019-10-26 20:06:16 +03:00
2019-11-01 08:37:47 +03:00
- [`Pages.Index`](https://github.com/ryannhg/elm-spa/blob/master/examples/html/src/Pages/Index.elm)
2019-10-26 20:06:16 +03:00
```elm
page =
Page.static
2019-11-01 07:44:36 +03:00
{ title = title
, view = view
2019-10-26 20:06:16 +03:00
}
```
2019-11-01 08:37:47 +03:00
- [`Pages.Counter`](https://github.com/ryannhg/elm-spa/blob/master/examples/html/src/Pages/Counter.elm)
2019-10-26 20:06:16 +03:00
```elm
page =
Page.sandbox
2019-11-01 07:44:36 +03:00
{ title = title
, init = init
2019-10-26 20:06:16 +03:00
, update = update
, view = view
}
```
2019-11-01 08:37:47 +03:00
- [`Pages.Random`](https://github.com/ryannhg/elm-spa/blob/master/examples/html/src/Pages/Random.elm)
2019-10-26 20:06:16 +03:00
```elm
page =
Page.element
2019-11-01 07:44:36 +03:00
{ title = title
, init = init
2019-10-26 20:06:16 +03:00
, update = update
, subscriptions = subscriptions
, view = view
}
```
2019-11-01 08:37:47 +03:00
- [`Pages.SignIn`](https://github.com/ryannhg/elm-spa/blob/master/examples/html/src/Pages/SignIn.elm)
2019-10-26 20:06:16 +03:00
```elm
page =
Page.component
2019-11-01 07:44:36 +03:00
{ title = title
, init = init
2019-10-26 20:06:16 +03:00
, update = update
, subscriptions = subscriptions
, view = view
}
```
2019-11-01 07:44:36 +03:00
### while the top level stays easy to read!
2019-10-08 23:06:03 +03:00
2019-10-26 20:06:16 +03:00
```elm
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. )
2019-10-08 23:06:03 +03:00
2019-11-01 07:44:36 +03:00
### run the example
2019-10-05 04:25:25 +03:00
2019-11-01 08:37:47 +03:00
this project comes with an example in [examples/html](https://github.com/ryannhg/elm-spa/blob/master/examples/html).
2019-10-26 20:10:39 +03:00
2019-11-01 07:44:36 +03:00
Here's how to run it:
1. `git clone https://github.com/ryannhg/elm-spa.git && cd elm-spa`
1. `npm install`
1. `npm run dev`