Skip to content

Instantly share code, notes, and snippets.

@lorenzo
Last active February 28, 2016 13:46
Show Gist options
  • Save lorenzo/1c7ab68988f659f4e84a to your computer and use it in GitHub Desktop.
Save lorenzo/1c7ab68988f659f4e84a to your computer and use it in GitHub Desktop.
port autoScroll : Signal ()
port autoScroll = Signal.map (always ()) scrollMailbox.signal
scrollMailbox : Signal.Mailbox Action
scrollMailbox = Signal.mailbox FromEffect
{- configuration for the start app -}
config : StartApp.Config Model Action
config =
{ init = (initialModel, initialEffect)
, update = update
, view = view
, inputs = [ {- Some more signals here -}, scrollMailbox.signal] {- Added the last one -}
}
update action model =
case action of
NewMessages items ->
(
{ model | items = items }
, Signal.send scrollMailbox.address NoOp |> kickOff {- kickoff converts the taks to an effect of the right type -}
)
<script>
chat.ports.autoScroll.subscribe(function (event) {
var div = document.getElementsByClassName('chat-history')[0];
div.scrollTop = div.scrollHeight
});
<script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment