Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. port module Spelling exposing (..)
  2.  
  3. import Html exposing (..)
  4. import Html.Attributes exposing (..)
  5. import Html.Events exposing (..)
  6. import String
  7.  
  8.  
  9. main =
  10. program
  11. { init = init
  12. , view = view
  13. , update = update
  14. , subscriptions = subscriptions
  15. }
  16.  
  17.  
  18.  
  19. -- MODEL
  20.  
  21.  
  22. type alias Model =
  23. { word : String
  24. , suggestions : List String
  25. }
  26.  
  27.  
  28. init : ( Model, Cmd Msg )
  29. init =
  30. ( Model "" [], Cmd.none )
  31.  
  32.  
  33.  
  34. -- UPDATE
  35.  
  36.  
  37. type Msg
  38. = Change String
  39. | Check
  40. | Suggest (List String)
  41.  
  42.  
  43. port check : String -> Cmd msg
  44.  
  45.  
  46. update : Msg -> Model -> ( Model, Cmd Msg )
  47. update msg model =
  48. case msg of
  49. Change newWord ->
  50. ( Model newWord [], Cmd.none )
  51.  
  52. Check ->
  53. ( model, check model.word )
  54.  
  55. Suggest newSuggestions ->
  56. ( Model model.word newSuggestions, Cmd.none )
  57.  
  58.  
  59.  
  60. -- SUBSCRIPTIONS
  61.  
  62.  
  63. port suggestions : (List String -> msg) -> Sub msg
  64.  
  65.  
  66. subscriptions : Model -> Sub Msg
  67. subscriptions model =
  68. suggestions Suggest
  69.  
  70.  
  71.  
  72. -- VIEW
  73.  
  74.  
  75. view : Model -> Html Msg
  76. view model =
  77. div []
  78. [ input [ onInput Change ] []
  79. , button [ onClick Check ] [ text "Check" ]
  80. , div [] [ text (String.join ", " model.suggestions) ]
  81. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement