Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 05fff5a

Browse files
committed
Add DOM.HTML.History.
1 parent ee79e6e commit 05fff5a

File tree

5 files changed

+88
-5
lines changed

5 files changed

+88
-5
lines changed

src/DOM/HTML/History.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// module DOM.HTML.History
2+
3+
exports.history = function(window) {
4+
return function() {
5+
return window.history;
6+
};
7+
}
8+
exports.back = function(history) {
9+
return function() {
10+
return history.back();
11+
};
12+
};
13+
exports.forward = function(history) {
14+
return function() {
15+
return history.forward();
16+
};
17+
};
18+
exports.go = function(history) {
19+
return function(delta) {
20+
return function() {
21+
return history.go(delta);
22+
};
23+
};
24+
};
25+
exports.pushState = function(history) {
26+
return function(a) {
27+
return function(docTitle) {
28+
return function(url) {
29+
return function() {
30+
return history.pushState(a, docTitle, url);
31+
};
32+
};
33+
};
34+
};
35+
};
36+
exports.replaceState = function(history) {
37+
return function(a) {
38+
return function(docTitle) {
39+
return function(url) {
40+
return function() {
41+
return history.replaceState(a, docTitle, url);
42+
};
43+
};
44+
};
45+
};
46+
};
47+
exports.state = function(history) {
48+
return function() {
49+
return history.state;
50+
};
51+
};

src/DOM/HTML/History.purs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module DOM.HTML.History where
2+
3+
import Control.Monad.Eff (Eff)
4+
import DOM.HTML.Types (HISTORY, History, Window)
5+
import Prelude (Unit)
6+
7+
-- DocumentTitle will set value of `document.title`
8+
newtype DocumentTitle = DocumentTitle String
9+
newtype Delta = Delta Int
10+
newtype URL = URL String -- Unsure how to better type this.
11+
12+
foreign import back :: forall e. History -> Eff (history :: HISTORY | e) Unit
13+
foreign import forward :: forall e. History -> Eff (history :: HISTORY | e) Unit
14+
foreign import go :: forall e. History -> Delta -> Eff (history :: HISTORY | e) Unit
15+
foreign import pushState :: forall a e. History -> a -> DocumentTitle -> URL -> Eff (history :: HISTORY | e) Unit
16+
foreign import replaceState :: forall a e. History -> a -> DocumentTitle -> URL -> Eff (history :: HISTORY | e) Unit
17+
foreign import state :: forall a e. History -> Eff (history :: HISTORY | e) a

src/DOM/HTML/Types.purs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
module DOM.HTML.Types
33
( Navigator
44
, Location
5+
, History
56
, Window
67
, ALERT
7-
, PROMPT
88
, CONFIRM
9+
, HISTORY
10+
, PROMPT
911
, WINDOW
1012
, windowToEventTarget
1113
, HTMLDocument
@@ -227,8 +229,12 @@ foreign import data Location :: *
227229

228230
foreign import data Window :: *
229231

232+
foreign import data History :: *
233+
230234
foreign import data ALERT :: !
231235

236+
foreign import data HISTORY :: !
237+
232238
foreign import data PROMPT :: !
233239

234240
foreign import data CONFIRM :: !

src/DOM/HTML/Window.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ exports.location = function (window) {
1818
};
1919
};
2020

21+
exports.history = function(window) {
22+
return function() {
23+
return window.history;
24+
};
25+
}
26+
2127
exports.innerWidth = function (window) {
2228
return function () {
2329
return window.innerWidth;

src/DOM/HTML/Window.purs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module DOM.HTML.Window
22
( document
33
, navigator
44
, location
5+
, history
56
, innerWidth
67
, innerHeight
78
, alert
@@ -23,19 +24,21 @@ module DOM.HTML.Window
2324
, scrollY
2425
) where
2526

26-
import Prelude (Unit, (<$>))
27-
import Data.Maybe (Maybe)
28-
import Data.Nullable (Nullable, toMaybe)
2927
import Control.Monad.Eff (Eff)
3028
import DOM (DOM)
31-
import DOM.HTML.Types (Window, Location, Navigator, HTMLDocument, ALERT, CONFIRM, PROMPT, WINDOW)
29+
import DOM.HTML.Types (ALERT, CONFIRM, HISTORY, HTMLDocument, History, Location, Navigator, PROMPT, WINDOW, Window)
30+
import Data.Maybe (Maybe)
31+
import Data.Nullable (Nullable, toMaybe)
32+
import Prelude (Unit, (<$>))
3233

3334
foreign import document :: forall eff. Window -> Eff (dom :: DOM | eff) HTMLDocument
3435

3536
foreign import navigator :: forall eff. Window -> Eff (dom :: DOM | eff) Navigator
3637

3738
foreign import location :: forall eff. Window -> Eff (dom :: DOM | eff) Location
3839

40+
foreign import history :: forall e. Window -> Eff (history :: HISTORY | e) History
41+
3942
foreign import innerWidth :: forall eff. Window -> Eff (dom :: DOM | eff) Int
4043

4144
foreign import innerHeight :: forall eff. Window -> Eff (dom :: DOM | eff) Int

0 commit comments

Comments
 (0)