Skip to content

Add elm-mode function and main snippets #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions snippets/elm-mode/function
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- mode: snippet -*-
# name: function
# uuid:
# key: :fn
# condition: t
# --

$1 : $2
$1 ${$3} =
$0
66 changes: 66 additions & 0 deletions snippets/elm-mode/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- mode: snippet -*-
# name: main
# key: trigger-key
# condition: t
# --

module Main exposing (main)

import Browser exposing (Document, UrlRequest, application)
import Browser.Navigation as Nav
import Html
import Url exposing (Url)


type alias Model =
{ key : Nav.Key
, url : Url
}


init : () -> Url -> Nav.Key -> ( Model, Cmd Msg )
init _ url key =
( Model key url, Cmd.none )


main =
application
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
, onUrlChange = UrlChanged
, onUrlRequest = UrlRequested
}


subscriptions : Model -> Sub Msg
subscriptions _ =
Sub.none


type Msg
= UrlChanged Url
| UrlRequested UrlRequest


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
UrlChanged newUrl ->
( { model | url = newUrl }, Cmd.none )

UrlRequested urlRequest ->
case urlRequest of
Browser.Internal url ->
( model, Nav.pushUrl model.key (Url.toString url) )

Browser.External href ->
( model, Nav.load href )


view : Model -> Document Msg
view model =
{ title = "Elm App"
, body = [ Html.p [] [ Html.text "hello, world" ] ]
}