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

Commit bfa8bf2

Browse files
authored
Merge pull request #75 from chexxor/add-history
Add DOM.HTML.History.
2 parents 872a115 + fe38329 commit bfa8bf2

File tree

5 files changed

+94
-5
lines changed

5 files changed

+94
-5
lines changed

src/DOM/HTML/History.js

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

src/DOM/HTML/History.purs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module DOM.HTML.History where
2+
3+
import Control.Monad.Eff (Eff)
4+
import DOM.HTML.Types (HISTORY, History)
5+
import Data.Foreign (Foreign)
6+
import Data.Newtype (class Newtype)
7+
import Prelude (class Eq, class Ord, Unit)
8+
9+
-- DocumentTitle will set value of `document.title`
10+
newtype DocumentTitle = DocumentTitle String
11+
derive instance eqDocumentTitle :: Eq DocumentTitle
12+
derive instance ordDocumentTitle :: Ord DocumentTitle
13+
derive instance newtypeDocumentTitle :: Newtype DocumentTitle _
14+
newtype Delta = Delta Int
15+
derive instance eqDelta :: Eq Delta
16+
derive instance ordDelta :: Ord Delta
17+
derive instance newtypeDelta :: Newtype Delta _
18+
newtype URL = URL String
19+
derive instance eqURL :: Eq URL
20+
derive instance ordURL :: Ord URL
21+
derive instance newtypeURL :: Newtype URL _
22+
23+
foreign import back :: forall e. History -> Eff (history :: HISTORY | e) Unit
24+
foreign import forward :: forall e. History -> Eff (history :: HISTORY | e) Unit
25+
foreign import go :: forall e. Delta -> History -> Eff (history :: HISTORY | e) Unit
26+
foreign import pushState :: forall e. Foreign -> DocumentTitle -> URL -> History -> Eff (history :: HISTORY | e) Unit
27+
foreign import replaceState :: forall e. Foreign -> DocumentTitle -> URL -> History -> Eff (history :: HISTORY | e) Unit
28+
foreign import state :: forall e. History -> Eff (history :: HISTORY | e) Foreign

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)