2019-10-05 01:16:02 +03:00
|
|
|
# ryannhg/elm-app
|
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-10-08 08:22:17 +03:00
|
|
|
|
2019-10-16 07:52:54 +03:00
|
|
|
### try it out
|
2019-10-05 01:16:02 +03:00
|
|
|
|
2019-10-16 07:52:54 +03:00
|
|
|
1. `npm install`
|
2019-10-05 01:16:02 +03:00
|
|
|
|
2019-10-16 07:52:54 +03:00
|
|
|
1. `npm run dev`
|
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-26 20:06:16 +03:00
|
|
|
a wrapper around `Browser.application` (that handles routing and page transitions!)
|
|
|
|
|
2019-10-08 08:22:17 +03:00
|
|
|
```elm
|
|
|
|
module Main exposing (main)
|
2019-10-05 01:16:02 +03:00
|
|
|
|
2019-10-16 07:52:54 +03:00
|
|
|
import Application exposing (Application)
|
|
|
|
import Generated.Pages as Pages
|
2019-10-26 20:06:16 +03:00
|
|
|
import Generated.Route as Route
|
|
|
|
import Global
|
2019-10-24 02:33:21 +03:00
|
|
|
import Layouts.Main
|
2019-10-05 01:16:02 +03:00
|
|
|
|
2019-10-08 08:22:17 +03:00
|
|
|
|
2019-10-26 20:06:16 +03:00
|
|
|
main : Application Global.Flags Global.Model Global.Msg Pages.Model Pages.Msg
|
2019-10-08 08:22:17 +03:00
|
|
|
main =
|
2019-10-16 07:52:54 +03:00
|
|
|
Application.create
|
|
|
|
{ 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
|
|
|
|
}
|
|
|
|
, layout =
|
|
|
|
{ view = Layouts.Main.view
|
|
|
|
, transition = Application.fade 200
|
2019-10-16 07:52:54 +03:00
|
|
|
}
|
|
|
|
, pages =
|
|
|
|
{ init = Pages.init
|
|
|
|
, update = Pages.update
|
|
|
|
, bundle = Pages.bundle
|
|
|
|
}
|
2019-10-08 23:06:03 +03:00
|
|
|
}
|
2019-10-26 20:06:16 +03:00
|
|
|
|
2019-10-08 23:06:03 +03:00
|
|
|
```
|
|
|
|
|
2019-10-26 20:06:16 +03:00
|
|
|
### keep your pages simple
|
|
|
|
|
|
|
|
(No need for elm-fork-knife!)
|
|
|
|
|
|
|
|
- [`Pages.Index`](./example/src/Pages/Index.elm)
|
|
|
|
|
|
|
|
```elm
|
|
|
|
page =
|
|
|
|
Page.static
|
|
|
|
{ view = view
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- [`Pages.Counter`](./example/src/Pages/Counter.elm)
|
|
|
|
|
|
|
|
```elm
|
|
|
|
page =
|
|
|
|
Page.sandbox
|
|
|
|
{ init = init
|
|
|
|
, update = update
|
|
|
|
, view = view
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- [`Pages.Random`](./example/src/Pages/Random.elm)
|
|
|
|
|
|
|
|
```elm
|
|
|
|
page =
|
|
|
|
Page.element
|
|
|
|
{ init = init
|
|
|
|
, update = update
|
|
|
|
, subscriptions = subscriptions
|
|
|
|
, view = view
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
- [`Pages.SignIn`](./example/src/Pages/SignIn.elm)
|
|
|
|
|
|
|
|
```elm
|
|
|
|
page =
|
|
|
|
Page.component
|
|
|
|
{ init = init
|
|
|
|
, update = update
|
|
|
|
, subscriptions = subscriptions
|
|
|
|
, view = view
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### _and_ your top level easy to read!
|
2019-10-08 23:06:03 +03:00
|
|
|
|
2019-10-16 08:02:06 +03:00
|
|
|
- [`Generated.Pages`](./example/src/Generated/Pages.elm)
|
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-10-26 20:06:16 +03:00
|
|
|
### the folder structure
|
2019-10-05 04:25:25 +03:00
|
|
|
|
2019-10-26 20:06:16 +03:00
|
|
|
```
|
|
|
|
src/
|
|
|
|
Api/
|
|
|
|
Users.elm
|
|
|
|
(...)
|
|
|
|
Components/
|
|
|
|
Navbar.elm
|
|
|
|
(...)
|
|
|
|
Data/
|
|
|
|
User.elm
|
|
|
|
(...)
|
|
|
|
Layouts/
|
|
|
|
Main.elm
|
|
|
|
Settings.elm
|
|
|
|
(...)
|
|
|
|
Pages/
|
|
|
|
Index.elm
|
|
|
|
Counter.elm
|
|
|
|
Settings/
|
|
|
|
Account.elm
|
|
|
|
(...)
|
|
|
|
(...)
|
|
|
|
Utils/
|
|
|
|
Cmd.elm
|
|
|
|
(...)
|
|
|
|
Main.elm
|
|
|
|
Global.elm
|
|
|
|
```
|