-
-
Save groteck/e4cc180ac182436f31f1d709466df768 to your computer and use it in GitHub Desktop.
Remove unused import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
elm-make Spelling.elm --output=spelling.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="spelling"></div> | |
<script src="spelling.js"></script> | |
<script> | |
var app = Elm.Spelling.fullscreen(); | |
app.ports.check.subscribe(function(word) { | |
var suggestions = spellCheck(word); | |
app.ports.suggestions.send(suggestions); | |
}); | |
fruits = [] | |
function spellCheck(word) { | |
// You can check on the js console if fruits was updated by elm | |
// typing fruits | |
fruits.push(word); | |
return fruits; | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
port module Spelling exposing (..) | |
import Html exposing (..) | |
import Html.Events exposing (..) | |
import String | |
main = | |
program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = subscriptions | |
} | |
-- MODEL | |
type alias Model = | |
{ word : String | |
, suggestions : List String | |
} | |
init : ( Model, Cmd Msg ) | |
init = | |
( Model "" [], Cmd.none ) | |
-- UPDATE | |
type Msg | |
= Change String | |
| Check | |
| Suggest (List String) | |
port check : String -> Cmd msg | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
Change newWord -> | |
( Model newWord [], Cmd.none ) | |
Check -> | |
( model, check model.word ) | |
Suggest newSuggestions -> | |
( Model model.word newSuggestions, Cmd.none ) | |
-- SUBSCRIPTIONS | |
port suggestions : (List String -> msg) -> Sub msg | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
suggestions Suggest | |
-- VIEW | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ input [ onInput Change ] [] | |
, button [ onClick Check ] [ text "Check" ] | |
, div [] [ text (String.join ", " model.suggestions) ] | |
] |
If you compile with --warn
you get this message:
-- unused import ---------------------------------------------- src\elm\Main.elm
Module `Html.Attributes` is unused.
4| import Html.Attributes exposing (..)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Best to remove it. Don't save code quality for later!
Kudos for the port ๐
I came along that error and am still new i Elm i its a nice language for Front end and am enjoying it
Detected errors in 1 module.
-- PORT ERROR ----------------------------------------------------- spelling.elm Port suggestions
has an invalid type. 76| port suggestions : (List String -> msg) -> Sub Msg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You are saying it should be: (List String -> msg) -> Platform.Sub.Sub Spelling.Msg
@Kennedy-s You need to change:
port suggestions : (List String -> msg) -> Sub Msg
to
port suggestions : (List String -> msg) -> Sub msg
@fdbeirao thanks ๐ fixed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for porting (no pun intended) to 0.18!