From 916cd20aa369fb1c4802cef2d929444d506064b4 Mon Sep 17 00:00:00 2001 From: Jason Fry Date: Mon, 17 Feb 2025 15:07:56 -0500 Subject: [PATCH] Add elm-mode function and main snippets --- snippets/elm-mode/function | 10 ++++++ snippets/elm-mode/main | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 snippets/elm-mode/function create mode 100644 snippets/elm-mode/main diff --git a/snippets/elm-mode/function b/snippets/elm-mode/function new file mode 100644 index 00000000..347cce54 --- /dev/null +++ b/snippets/elm-mode/function @@ -0,0 +1,10 @@ +# -*- mode: snippet -*- +# name: function +# uuid: +# key: :fn +# condition: t +# -- + +$1 : $2 +$1 ${$3} = + $0 diff --git a/snippets/elm-mode/main b/snippets/elm-mode/main new file mode 100644 index 00000000..31200021 --- /dev/null +++ b/snippets/elm-mode/main @@ -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" ] ] + }