Skip to content

Instantly share code, notes, and snippets.

@mfeineis
mfeineis / ElmActuallyUsingIntentsAndFacts.elm
Created March 17, 2018 23:56
An exploration of the IntentsAndFacts approach to see what can be improved further - https://ellie-app.com/7TNrzrB6Na1/0
module Main exposing (main)
import Html exposing (Html)
import Html.Events as Events exposing (onClick)
import Http
import Json.Decode as Decode exposing (Decoder, Value)
type CounterState
= CounterState
@mfeineis
mfeineis / ElmFxAndCmdsDiscussion.txt
Created March 16, 2018 20:00
A copy of the discussion that lead to the `ElmFxAndCmds.elm` snippet
norpan [1:21 PM]
Hey, I was just thinking about the `Cmd` being returned from the `init` and `update` functions. I’ve never really liked that, so I was just wondering if anybody else has toyed with the idea to instead return a `List Command` or similar where you’d define your `Command`s just like you define your `Msg`s and then only at the last moment convert them to `Cmd`s?
ilias [1:25 PM]
Luke is doing something like that, or experimenting with it
opsb [1:25 PM]
@norpan I have an `AppCmd msg` which only gets converted to `Cmd`s as late as possible. It implements the same API as Cmd, `AppCmd.batch, AppCmd.none etc.` but it allows me to have a lot more control when testing for instance. (edited)
norpan [1:25 PM]
exactly, that’s my thinking too
opsb [1:26 PM]
It also makes it easier to have commands like `AppCmd.logout`
@mfeineis
mfeineis / ElmClipboard.elm
Created March 14, 2018 12:58
WIP: A gist for trying to get the `copy` event working with ports in Elm. https://ellie-app.com/pyMQZgFwga1/1
port module Main exposing (main)
import Html exposing (Html)
import Html.Events as Events exposing (onWithOptions)
import Json.Decode as Decode exposing (Value)
port saveToClipboard : Value -> Cmd msg
@mfeineis
mfeineis / ElmCqrs.elm
Last active March 14, 2018 21:32
A gist for doing proper CQRS with a run-of-the-mill Elm program - see https://ellie-app.com/7GHTBPxy3a1/1
port module Main exposing (main)
import Html exposing (Html)
import Html.Events exposing (onClick)
import Http
import Json.Decode as Decode exposing (Decoder, Value)
import Json.Encode as Encode
port toElm : (Value -> msg) -> Sub msg
@mfeineis
mfeineis / ElmFxAndCmds.elm
Last active March 13, 2018 13:55
A gist for making the update function better testable by allowing it to return union types that are then interpreted https://ellie-app.com/SZCJ3rJ3a1/3
module ElmFxAndCmds exposing (main)
import Html exposing (Html)
import Html.Events exposing (onClick)
import Http
import Json.Decode as Decode exposing (Decoder, Value)
type alias Model =
{}
@mfeineis
mfeineis / FromReduxToElm.elm
Created March 11, 2018 01:48
A self-contained attempt at explaining The Elm Architecture (TEA) in terms of Redux - https://ellie-app.com/kKcXHF8fJa1/0
port module FromReduxToElm exposing (main)
import Html exposing (Html)
port sayHello : (String -> msg) -> Sub msg
type alias Model =
{ who : String
@mfeineis
mfeineis / ElmTurnResultIntoDecoder.elm
Created March 7, 2018 07:44
A snippet for making a `Json.Decoder` from a result
-- From https://robots.thoughtbot.com/5-common-json-decoders#1---decoding-union-types
fromResult : Result String a -> Decoder a
fromResult result =
case result of
Ok a -> JD.succeed a
Err errorMessage -> JD.fail errorMessage
parseDirection : String -> Result String Direction
@mfeineis
mfeineis / ElmWithReact.elm
Last active March 6, 2018 01:53
A minimal example for integrating Elm into a React 16 App (https://ellie-app.com/bCchkr7cYa1/2)
port module Main exposing (main)
import Html exposing (Html)
port fromElm : String -> Cmd msg
port toElm : (String -> msg) -> Sub msg
@mfeineis
mfeineis / ElmFsaPorts.elm
Last active March 6, 2018 01:53
This is a "minimal" example for integrating Elm with Flux-Standard-Actions of ReactJS fame (https://ellie-app.com/d6C53Vf3Pa1/0).
port module ElmFsaPorts exposing (main)
import Html exposing (Html, text)
import Json.Decode as Decode exposing (Decoder, Value)
import Json.Encode as Encode
port fromElm : Value -> Cmd msg
@mfeineis
mfeineis / elm-meetup-2018-02-28
Created February 28, 2018 22:44
Notes for the Elm Meetup Leipzig 2018-02-28
* autojump - bookmark console
* mosh - mobileshell
* sshuttle - easy vpn with python?
* ripgrep (rg) - better silversurfer (ag)
* https://github.com/asdf-vm/asdf
* https://github.com/junegunn/fzf
* https://github.com/abo-abo/swiper
Tasks