-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathHistory.purs
More file actions
61 lines (48 loc) · 1.79 KB
/
History.purs
File metadata and controls
61 lines (48 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module Web.HTML.History
( History
, DocumentTitle(..)
, Delta(..)
, URL(..)
, back
, forward
, go
, pushState
, replaceState
, state
, length
, scrollRestoration
, setScrollRestoration
) where
import Prelude
import Data.Maybe (fromMaybe)
import Data.Newtype (class Newtype)
import Effect (Effect)
import Foreign (Foreign)
import Web.HTML.ScrollRestoration (ScrollRestoration(..), parse, print)
foreign import data History :: Type
-- DocumentTitle will set value of `document.title`
newtype DocumentTitle = DocumentTitle String
derive instance eqDocumentTitle :: Eq DocumentTitle
derive instance ordDocumentTitle :: Ord DocumentTitle
derive instance newtypeDocumentTitle :: Newtype DocumentTitle _
newtype Delta = Delta Int
derive instance eqDelta :: Eq Delta
derive instance ordDelta :: Ord Delta
derive instance newtypeDelta :: Newtype Delta _
newtype URL = URL String
derive instance eqURL :: Eq URL
derive instance ordURL :: Ord URL
derive instance newtypeURL :: Newtype URL _
foreign import back :: History -> Effect Unit
foreign import forward :: History -> Effect Unit
foreign import go :: Delta -> History -> Effect Unit
foreign import pushState :: Foreign -> DocumentTitle -> URL -> History -> Effect Unit
foreign import replaceState :: Foreign -> DocumentTitle -> URL -> History -> Effect Unit
foreign import state :: History -> Effect Foreign
foreign import length :: History -> Effect Int
foreign import _scrollRestoration :: History -> Effect String
foreign import _setScrollRestoration :: String -> History -> Effect Unit
scrollRestoration :: History -> Effect ScrollRestoration
scrollRestoration = map (fromMaybe Auto <<< parse) <<< _scrollRestoration
setScrollRestoration :: ScrollRestoration -> History -> Effect Unit
setScrollRestoration = _setScrollRestoration <<< print