Skip to content

Instantly share code, notes, and snippets.

@thotmx
Last active September 9, 2017 15:12
Show Gist options
  • Select an option

  • Save thotmx/f0b0a1b5b97ccb4d8f301d482a366fb8 to your computer and use it in GitHub Desktop.

Select an option

Save thotmx/f0b0a1b5b97ccb4d8f301d482a366fb8 to your computer and use it in GitHub Desktop.

Revisions

  1. thotmx revised this gist Sep 9, 2017. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    import Html exposing (..)
    import Html.Attributes exposing(placeholder)
    import Html.Events exposing(onInput, onClick)
    import Random exposing (..)
    import Random.String
    import Random.Char

    type alias Model = {
    content : String
    @@ -13,16 +16,25 @@ initialModel = { content = "Hola" }

    -- UPDATE

    type Msg = Update String | Reset
    type Msg = Update String | Reset

    update : Msg -> Model -> (Model, Cmd Msg)
    update msg model =
    case msg of
    Reset ->
    ( { model | content = "Hola" } , Cmd.none )
    ( { model | content = "" } , generateRandomString)
    Update newString ->
    ( { model | content = newString }, Cmd.none)

    -- COMMANDS

    generateRandomString : Cmd Msg
    generateRandomString =
    Random.generate Update (Random.String.string 5 Random.Char.english)




    -- VIEW
    view model = div [] [
    input [ placeholder "Escribe algo", onInput Update ] []
  2. thotmx revised this gist Sep 9, 2017. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -8,20 +8,20 @@ type alias Model = {

    -- MODEL

    model : Model
    model = { content = "Hola" }
    initialModel : Model
    initialModel = { content = "Hola" }

    -- UPDATE

    type Msg = Update String | Reset

    update : Msg -> Model -> Model
    update : Msg -> Model -> (Model, Cmd Msg)
    update msg model =
    case msg of
    Reset ->
    { model | content = "Hola" }
    ( { model | content = "Hola" } , Cmd.none )
    Update newString ->
    { model | content = newString }
    ( { model | content = newString }, Cmd.none)

    -- VIEW
    view model = div [] [
    @@ -31,8 +31,9 @@ view model = div [] [
    ]

    -- MAIN
    main = beginnerProgram {
    model = model
    main = program {
    init = ( initialModel, Cmd.none)
    , update = update
    , view = view
    , subscriptions = ( \_ -> Sub.none )
    }
  3. thotmx revised this gist Sep 9, 2017. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    import Html exposing (..)
    import Html.Attributes exposing(placeholder)
    import Html.Events exposing(onInput)
    import Html.Events exposing(onInput, onClick)

    type alias Model = {
    content : String
    @@ -13,18 +13,21 @@ model = { content = "Hola" }

    -- UPDATE

    type Msg = Update String
    type Msg = Update String | Reset

    update : Msg -> Model -> Model
    update msg model =
    case msg of
    Reset ->
    { model | content = "Hola" }
    Update newString ->
    { model | content = newString }

    -- VIEW
    view model = div [] [
    input [ placeholder "Escribe algo", onInput Update ] []
    , h1 [] [ text model.content ]
    , button [onClick Reset] [ text "Reset" ]
    ]

    -- MAIN
  4. thotmx revised this gist Sep 9, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -23,11 +23,12 @@ update msg model =

    -- VIEW
    view model = div [] [
    input [ placeholder "Escribe algo", onInput (\inputString -> Update ("..." ++ inputString ++ "...")) ] []
    input [ placeholder "Escribe algo", onInput Update ] []
    , h1 [] [ text model.content ]
    ]

    main = Html.beginnerProgram {
    -- MAIN
    main = beginnerProgram {
    model = model
    , update = update
    , view = view
  5. thotmx revised this gist Sep 9, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ update msg model =

    -- VIEW
    view model = div [] [
    input [ placeholder "Escribe algo", onInput (\inputString -> Update inputString) ] []
    input [ placeholder "Escribe algo", onInput (\inputString -> Update ("..." ++ inputString ++ "...")) ] []
    , h1 [] [ text model.content ]
    ]

  6. thotmx revised this gist Sep 9, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -27,4 +27,8 @@ view model = div [] [
    , h1 [] [ text model.content ]
    ]

    main = view model
    main = Html.beginnerProgram {
    model = model
    , update = update
    , view = view
    }
  7. thotmx revised this gist Sep 9, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    import Html exposing (..)
    import Html.Attributes exposing(placeholder)
    import Html.Events exposing(onInput)

    type alias Model = {
    content : String
    @@ -22,7 +23,7 @@ update msg model =

    -- VIEW
    view model = div [] [
    input [ placeholder "Escribe algo"] []
    input [ placeholder "Escribe algo", onInput (\inputString -> Update inputString) ] []
    , h1 [] [ text model.content ]
    ]

  8. thotmx revised this gist Sep 9, 2017. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,12 @@ model = { content = "Hola" }

    type Msg = Update String

    update : Msg -> Model -> Model
    update msg model =
    case msg of
    Update newString ->
    { model | content = newString }

    -- VIEW
    view model = div [] [
    input [ placeholder "Escribe algo"] []
  9. thotmx revised this gist Sep 9, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,8 @@ model = { content = "Hola" }

    -- UPDATE

    type Msg = Update String

    -- VIEW
    view model = div [] [
    input [ placeholder "Escribe algo"] []
  10. thotmx revised this gist Sep 9, 2017. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,14 @@ type alias Model = {
    content : String
    }

    -- MODEL

    model : Model
    model = { content = "Hola" }

    -- UPDATE

    -- VIEW
    view model = div [] [
    input [ placeholder "Escribe algo"] []
    , h1 [] [ text model.content ]
  11. thotmx revised this gist Sep 9, 2017. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,16 @@
    import Html exposing (..)
    import Html.Attributes exposing(placeholder)

    model = "Hola"
    type alias Model = {
    content : String
    }

    model : Model
    model = { content = "Hola" }

    view model = div [] [
    input [ placeholder "Escribe algo"] []
    , h1 [] [ text model ]
    , h1 [] [ text model.content ]
    ]

    main = view model
  12. thotmx revised this gist Sep 9, 2017. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,11 @@
    import Html exposing (..)
    import Html.Attributes exposing(placeholder)

    view = div [] [
    input [ placeholder "Hey"] []
    model = "Hola"

    view model = div [] [
    input [ placeholder "Escribe algo"] []
    , h1 [] [ text model ]
    ]

    main = view
    main = view model
  13. thotmx revised this gist Sep 8, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    import Html exposing (..)
    import Html.Attributes exposing(placeholder)

    view = Html.text "Hello world"
    view = div [] [
    input [ placeholder "Hey"] []
    ]

    main = view
  14. thotmx revised this gist Sep 8, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    import Html exposing (..)

    main = Html.text "Hello world"
    view = Html.text "Hello world"

    main = view
  15. thotmx created this gist Sep 8, 2017.
    3 changes: 3 additions & 0 deletions oaxacarb.elm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    import Html exposing (..)

    main = Html.text "Hello world"