Last active
February 10, 2016 11:13
-
-
Save freakingawesome/32e2d271afc1b5f6879d to your computer and use it in GitHub Desktop.
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
import Html exposing (..) | |
import Html.Events exposing (..) | |
import StartApp | |
import Effects exposing (Never) | |
import Task | |
import Keyboard | |
import Char | |
import String | |
import Time | |
import Signal.Time exposing (settledAfter) | |
app = | |
StartApp.start | |
{ init = init | |
, view = view | |
, update = update | |
, inputs = [ ] | |
} | |
main = | |
app.html | |
port tasks : Signal (Task.Task Never ()) | |
port tasks = | |
app.tasks | |
type alias Model = | |
{ message : String } | |
init = | |
({ message = "Subscribe to the `request` port in javascript to see this in action!" }, Effects.none) | |
view address model = | |
div [] | |
[ div [] [ text model.message ] | |
, input | |
[ on "input" targetValue (Signal.message address << SendRequest) ] | |
[ ] | |
] | |
type Action | |
= NoOp | |
| SendRequest String | |
update action model = | |
case action of | |
NoOp -> | |
(model, Effects.none) | |
SendRequest str -> | |
let | |
sendTask = | |
Signal.send requestPalette.address str | |
`Task.andThen` (\_ -> Task.succeed NoOp) | |
in | |
(model, sendTask |> Effects.task) | |
requestPalette : | |
{ address : Signal.Address String | |
, signal : Signal String | |
} | |
requestPalette = Signal.mailbox "" | |
requestPaletteFilter : Signal String | |
requestPaletteFilter = | |
Signal.filter (String.isEmpty >> not) "" requestPalette.signal | |
|> settledAfter (300 * Time.millisecond) | |
port request : Signal String | |
port request = requestPaletteFilter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment