Skip to content

Commit cf4f6d0

Browse files
author
Curtis Schlak
committed
Add the map method to map ScrollState msg values.
1 parent 20c9a95 commit cf4f6d0

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/)
88
and this project adheres to
99
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
1010

11+
## 3.1.0
12+
13+
### Added
14+
15+
- The `map` method for `ScrollState msg` values
16+
1117
## 3.0.0
1218

1319
### Added

elm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "curtissimo/elm-inertial-scroll-detection",
44
"summary": "An event-driven state machine to detect inertial scrolling.",
55
"license": "BSD-3-Clause",
6-
"version": "3.0.0",
6+
"version": "3.1.0",
77
"exposed-modules": [
88
"Curtissimo.IntertialScrollDetector"
99
],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curtissimo/elm-inertial-scroll-detection",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"description": "An event-driven state machine to detect inertial scrolling.",
55
"devDependencies": {
66
"elm-doc-preview": "^6.0.1",

src/Curtissimo/IntertialScrollDetector.elm

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Curtissimo.IntertialScrollDetector exposing
22
( onInertialScroll, init, update
33
, InertialDirection(..), inertialX, inertialY, stickyX, stickyY, scrollLeft, scrollTop
4+
, map
45
, Msg, ScrollState
56
)
67

@@ -22,6 +23,11 @@ This is the directed state diagram for the inertial scroll detector.
2223
@docs InertialDirection, inertialX, inertialY, stickyX, stickyY, scrollLeft, scrollTop
2324
2425
26+
# Mapping
27+
28+
@docs map
29+
30+
2531
# Opaque types
2632
2733
@docs Msg, ScrollState
@@ -228,6 +234,93 @@ init left top toContentMsg =
228234
}
229235

230236

237+
{-| Map a [`ScrollState`](#ScrollState) from one msg type
238+
to another.
239+
-}
240+
map : (msg1 -> msg2) -> ScrollState msg1 -> ScrollState msg2
241+
map toMsg state =
242+
case state of
243+
InertialStarted data ->
244+
let
245+
horizontal =
246+
data.horizontal
247+
248+
vertical =
249+
data.vertical
250+
in
251+
InertialStarted
252+
{ count = data.count
253+
, horizontal = horizontal
254+
, vertical = vertical
255+
, timestamp = data.timestamp
256+
, toContentMsg = data.toContentMsg >> toMsg
257+
}
258+
259+
Inertial data ->
260+
let
261+
horizontal =
262+
data.horizontal
263+
264+
vertical =
265+
data.vertical
266+
in
267+
Inertial
268+
{ count = data.count
269+
, horizontal = horizontal
270+
, vertical = vertical
271+
, timestamp = data.timestamp
272+
, toContentMsg = data.toContentMsg >> toMsg
273+
}
274+
275+
Monitoring data ->
276+
let
277+
horizontal =
278+
data.horizontal
279+
280+
vertical =
281+
data.vertical
282+
in
283+
Monitoring
284+
{ count = data.count
285+
, horizontal = horizontal
286+
, vertical = vertical
287+
, timestamp = data.timestamp
288+
, toContentMsg = data.toContentMsg >> toMsg
289+
}
290+
291+
Moved data ->
292+
let
293+
horizontal =
294+
data.horizontal
295+
296+
vertical =
297+
data.vertical
298+
in
299+
Moved
300+
{ count = data.count
301+
, horizontal = horizontal
302+
, vertical = vertical
303+
, timestamp = data.timestamp
304+
, toContentMsg = data.toContentMsg >> toMsg
305+
}
306+
307+
Touched data ->
308+
let
309+
horizontal =
310+
data.horizontal
311+
312+
vertical =
313+
data.vertical
314+
in
315+
Touched
316+
{ count = data.count
317+
, horizontal = horizontal
318+
, vertical = vertical
319+
, timestamp = data.timestamp
320+
, toContentMsg = data.toContentMsg >> toMsg
321+
}
322+
323+
231324
{-| Adds the following passive event listeners to the scrollable area.
232325
233326
- `scroll` to monitor for scroll events after touch-end

0 commit comments

Comments
 (0)