mirror of
https://github.com/ryannhg/elm-spa.git
synced 2024-11-22 09:44:55 +03:00
document things
This commit is contained in:
parent
fb3af0ff1e
commit
d94b630c8e
@ -1,6 +1,53 @@
|
||||
# ryannhg/elm-app
|
||||
> a package for creating single page apps with Elm!
|
||||
> an experiment for creating single page apps with Elm!
|
||||
|
||||
|
||||
### try it out
|
||||
|
||||
1. `npm install`
|
||||
|
||||
1. `npm run dev`
|
||||
|
||||
|
||||
### overview
|
||||
|
||||
```elm
|
||||
module Main exposing (main)
|
||||
|
||||
import Application exposing (Application)
|
||||
import Generated.Pages as Pages
|
||||
import Generated.Route as Route
|
||||
import Layout as Layout
|
||||
|
||||
|
||||
main : Application () Pages.Model Pages.Msg
|
||||
main =
|
||||
Application.create
|
||||
{ routing =
|
||||
{ fromUrl = Route.fromUrl
|
||||
, toPath = Route.toPath
|
||||
}
|
||||
, layout =
|
||||
{ view = Layout.view
|
||||
}
|
||||
, pages =
|
||||
{ init = Pages.init
|
||||
, update = Pages.update
|
||||
, bundle = Pages.bundle
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### supporting code
|
||||
|
||||
- [`Generated.Route`](./src/Generated/Route.elm)
|
||||
|
||||
- [`Generated.Pages`](./src/Generated/Pages.elm)
|
||||
|
||||
- [`Layout`](./src/Layout.elm)
|
||||
|
||||
- [`Pages.Homepage`](./src/Pages/Homepage.elm) (a static page)
|
||||
|
||||
- [`Pages.Counter`](./src/Pages/Counter.elm) (a sandbox page)
|
||||
|
||||
- [`Pages.Random`](./src/Pages/Random.elm) (a static page)
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"checks" : {
|
||||
"SingleFieldRecord": false
|
||||
"SingleFieldRecord": false,
|
||||
"ImportAll": false
|
||||
}
|
||||
}
|
@ -4,7 +4,8 @@
|
||||
"description": "> a barebones example app made with ryannhg/elm-app",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"example": "parcel example/index.html"
|
||||
"dev": "parcel example/index.html",
|
||||
"build": "parcel example/index.html"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
26
examples/basic/src/Components/Navbar.elm
Normal file
26
examples/basic/src/Components/Navbar.elm
Normal file
@ -0,0 +1,26 @@
|
||||
module Components.Navbar exposing (view)
|
||||
|
||||
import Generated.Route as Route exposing (Route)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes as Attr
|
||||
|
||||
|
||||
view : Html msg
|
||||
view =
|
||||
header [ Attr.class "navbar" ]
|
||||
(List.map viewLink
|
||||
[ ( "Homepage", Route.Homepage )
|
||||
, ( "Counter", Route.Counter )
|
||||
, ( "Random", Route.Random )
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
viewLink : ( String, Route ) -> Html msg
|
||||
viewLink ( label, route ) =
|
||||
a
|
||||
[ Attr.href (Route.toPath route)
|
||||
, Attr.style "margin-right" "1rem"
|
||||
]
|
||||
[ text label
|
||||
]
|
@ -2,6 +2,7 @@ module Generated.Pages exposing (Model, Msg, bundle, init, update)
|
||||
|
||||
import Application
|
||||
import Generated.Route as Route exposing (Route)
|
||||
import Html exposing (Html)
|
||||
import Pages.Counter as Counter
|
||||
import Pages.Homepage as Homepage
|
||||
import Pages.NotFound as NotFound
|
||||
@ -98,7 +99,7 @@ update appMsg appModel =
|
||||
Application.keep appModel
|
||||
|
||||
|
||||
bundle : Model -> Application.Bundle Msg
|
||||
bundle : Model -> { view : Html Msg, subscriptions : Sub Msg }
|
||||
bundle appModel =
|
||||
case appModel of
|
||||
HomepageModel model ->
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Layout exposing (view)
|
||||
|
||||
import Generated.Route as Route exposing (Route)
|
||||
import Components.Navbar
|
||||
import Html exposing (..)
|
||||
import Html.Attributes as Attr
|
||||
|
||||
@ -11,22 +11,6 @@ view { page } =
|
||||
[ Attr.style "margin" "2rem auto"
|
||||
, Attr.style "max-width" "720px"
|
||||
]
|
||||
[ header [ Attr.class "navbar" ]
|
||||
(List.map viewLink
|
||||
[ ( "Homepage", Route.Homepage )
|
||||
, ( "Counter", Route.Counter )
|
||||
, ( "Random", Route.Random )
|
||||
]
|
||||
)
|
||||
[ Components.Navbar.view
|
||||
, page
|
||||
]
|
||||
|
||||
|
||||
viewLink : ( String, Route ) -> Html msg
|
||||
viewLink ( label, route ) =
|
||||
a
|
||||
[ Attr.href (Route.toPath route)
|
||||
, Attr.style "margin-right" "1rem"
|
||||
]
|
||||
[ text label
|
||||
]
|
||||
|
@ -6,11 +6,7 @@ import Generated.Route as Route
|
||||
import Layout as Layout
|
||||
|
||||
|
||||
type alias Flags =
|
||||
()
|
||||
|
||||
|
||||
main : Application Flags Pages.Model Pages.Msg
|
||||
main : Application () Pages.Model Pages.Msg
|
||||
main =
|
||||
Application.create
|
||||
{ routing =
|
||||
|
Loading…
Reference in New Issue
Block a user