# Elm-Scroll - An Effect Manager for Scroll Events

**URL:** <https://discourse.elm-lang.org/t/elm-scroll-an-effect-manager-for-scroll-events/1032>\
**Category:** Request Feedback\
**Created:** [March 27, 2018, 5:28pm UTC](https://discourse.elm-lang.org/t/elm-scroll-an-effect-manager-for-scroll-events/1032 "2018-03-27T17:28:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ilias](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/ilias/32/6_2.png) [@ilias](https://discourse.elm-lang.org/u/ilias)\
**Post date:** [March 27, 2018, 6:05pm UTC](https://discourse.elm-lang.org/t/elm-scroll-an-effect-manager-for-scroll-events/1032/2 "2018-03-27T18:05:53Z")

</div>

The good news is that you quite likely won’t need an effect manager, native _or_ ports to do this sort of thing in the next release. The bad news is that I wouldn’t advise using an effect manager to deal with this in the meantime.

So the way I’d recommend doing this sort of thing _right now_ would be using a port. Here’s an example for dealing with `wheel` events: [https://ellie-app.com/qqp6pVJRQa1/0](https://ellie-app.com/qqp6pVJRQa1/0)

The thing is that the next release will basically have a pair of functions `onWindow` and `onDocument`, to subscribe to events on the `window` and the `document`. So in that world, I could very easily adapt the code in the above Ellie:

```elm
subscriptions : model -> Sub Msg
subscriptions _ =
  onDocument "wheel" (Decode.map Wheel wheelDecoder)

```

* * *

Overall, this seems like it provides the nicer path:

- ✔️ possible right now
- ✔️ easy to adapt in the future
- ✔️ no need for native/kernel/effect managers/…

In fact, in a world where `onDocument` and `onWindow` are available, a package like the one described here could be released, and the entire implementation (adapted from your code 😉 ) would be this:

```auto
scroll : (Position -> msg) -> Sub msg
scroll tagger =
    onDocument "scroll" (Json.map tagger position)

position : Json.Decoder Position
position =
    Json.map2 Position
        (Json.at ["target", "defaultView", "scrollX"] Json.int)
        (Json.at ["target", "defaultView", "scrollY"] Json.int)

```

---

_[View the full topic](https://discourse.elm-lang.org/t/elm-scroll-an-effect-manager-for-scroll-events/1032)._
