File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77Breaking changes:
88
99New features:
10+ - Added ` length ` , ` scrollRestoration ` and ` setScrollRestoration ` for ` History ` (#87 by @acple )
1011
1112Bugfixes:
1213
Original file line number Diff line number Diff line change @@ -47,3 +47,23 @@ export function state(history) {
4747 return history . state ;
4848 } ;
4949}
50+
51+ export function length ( history ) {
52+ return function ( ) {
53+ return history . length ;
54+ } ;
55+ }
56+
57+ export function _scrollRestoration ( history ) {
58+ return function ( ) {
59+ return history . scrollRestoration ;
60+ } ;
61+ }
62+
63+ export function _setScrollRestoration ( scrollRestoration ) {
64+ return function ( history ) {
65+ return function ( ) {
66+ history . scrollRestoration = scrollRestoration ;
67+ } ;
68+ } ;
69+ }
Original file line number Diff line number Diff line change 1- module Web.HTML.History where
2-
1+ module Web.HTML.History
2+ ( History
3+ , DocumentTitle (..)
4+ , Delta (..)
5+ , URL (..)
6+ , back
7+ , forward
8+ , go
9+ , pushState
10+ , replaceState
11+ , state
12+ , length
13+ , scrollRestoration
14+ , setScrollRestoration
15+ ) where
16+
17+ import Prelude
18+
19+ import Data.Maybe (fromMaybe )
320import Data.Newtype (class Newtype )
421import Effect (Effect )
522import Foreign (Foreign )
6- import Prelude ( class Eq , class Ord , Unit )
23+ import Web.HTML.ScrollRestoration ( ScrollRestoration (..), parse , print )
724
825foreign import data History :: Type
926
@@ -32,3 +49,13 @@ foreign import go :: Delta -> History -> Effect Unit
3249foreign import pushState :: Foreign -> DocumentTitle -> URL -> History -> Effect Unit
3350foreign import replaceState :: Foreign -> DocumentTitle -> URL -> History -> Effect Unit
3451foreign import state :: History -> Effect Foreign
52+ foreign import length :: History -> Effect Int
53+
54+ foreign import _scrollRestoration :: History -> Effect String
55+ foreign import _setScrollRestoration :: String -> History -> Effect Unit
56+
57+ scrollRestoration :: History -> Effect ScrollRestoration
58+ scrollRestoration = map (fromMaybe Auto <<< parse) <<< _scrollRestoration
59+
60+ setScrollRestoration :: ScrollRestoration -> History -> Effect Unit
61+ setScrollRestoration = _setScrollRestoration <<< print
Original file line number Diff line number Diff line change 1+ module Web.HTML.ScrollRestoration where
2+
3+ import Prelude
4+
5+ import Data.Maybe (Maybe (..))
6+
7+ data ScrollRestoration
8+ = Auto
9+ | Manual
10+
11+ derive instance eqScrollRestoration :: Eq ScrollRestoration
12+ derive instance ordScrollRestoration :: Ord ScrollRestoration
13+
14+ instance showScrollRestoration :: Show ScrollRestoration where
15+ show = case _ of
16+ Auto -> " Auto"
17+ Manual -> " Manual"
18+
19+ parse :: String -> Maybe ScrollRestoration
20+ parse = case _ of
21+ " auto" -> Just Auto
22+ " manual" -> Just Manual
23+ _ -> Nothing
24+
25+ print :: ScrollRestoration -> String
26+ print = case _ of
27+ Auto -> " auto"
28+ Manual -> " manual"
You can’t perform that action at this time.
0 commit comments