Skip to content

Commit 4be92cc

Browse files
committed
Merge pull request #9 from cryogenian/aff
Added Aff interface
2 parents c8435d1 + b06dcfd commit 4be92cc

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

MODULES.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ matches' :: forall e a. (String -> String) -> Match a -> (Maybe a -> a -> Eff e
3333
```
3434

3535

36+
#### `matchesAff'`
37+
38+
``` purescript
39+
matchesAff' :: forall e a. (String -> String) -> Match a -> Aff e (Tuple (Maybe a) a)
40+
```
41+
42+
43+
#### `matchesAff`
44+
45+
``` purescript
46+
matchesAff :: forall e a. Match a -> Aff e (Tuple (Maybe a) a)
47+
```
48+
49+
3650
#### `matchHash`
3751

3852
``` purescript
@@ -201,6 +215,23 @@ type Route = List RoutePart
201215

202216

203217

218+
## Module Routing.Hash.Aff
219+
220+
#### `modifyHash`
221+
222+
``` purescript
223+
modifyHash :: forall e. (String -> String) -> Aff (dom :: DOM | e) Unit
224+
```
225+
226+
227+
#### `setHash`
228+
229+
``` purescript
230+
setHash :: forall e. String -> Aff (dom :: DOM | e) Unit
231+
```
232+
233+
234+
204235
## Module Routing.Match.Class
205236

206237
#### `MatchClass`

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"purescript-semirings": "~0.1.1",
2929
"purescript-lists": "~0.6.0",
3030
"purescript-globals": "~0.1.6",
31-
"purescript-dom": "~0.1.2"
31+
"purescript-dom": "~0.1.2",
32+
"purescript-aff": "~0.10.0"
3233
},
3334
"devDependencies": {
3435
"purescript-timers": "~0.0.8",

src/Routing.purs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ module Routing (
44
matches,
55
matches',
66
matchHash,
7-
matchHash'
7+
matchHash',
8+
matchesAff,
9+
matchesAff'
810
) where
911

1012
import Control.Monad.Eff
13+
import Control.Monad.Aff
1114
import Data.Maybe
1215
import Data.Either
16+
import Data.Tuple
1317
import qualified Data.String.Regex as R
1418

1519
import Routing.Parser
@@ -49,8 +53,18 @@ matches' :: forall e a. (String -> String) ->
4953
matches' decoder routing cb = hashes $ \old new ->
5054
let mr = matchHash' decoder routing
5155
fst = either (const Nothing) Just $ mr old
52-
in either (const $ pure unit) (cb fst) $ mr new
56+
in either (const $ pure unit) (cb fst) $ mr new
5357

58+
matchesAff' :: forall e a. (String -> String) ->
59+
Match a -> Aff e (Tuple (Maybe a) a)
60+
matchesAff' decoder routing =
61+
makeAff \_ k -> do
62+
matches' decoder routing \old new ->
63+
k $ Tuple old new
64+
65+
matchesAff :: forall e a. Match a -> Aff e (Tuple (Maybe a) a)
66+
matchesAff = matchesAff' decodeURIComponent
67+
5468

5569
matchHash :: forall a. Match a -> String -> Either String a
5670
matchHash = matchHash' decodeURIComponent

src/Routing/Hash/Aff.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Routing.Hash.Aff where
2+
3+
import DOM
4+
import Control.Monad.Aff
5+
import Control.Monad.Eff.Class
6+
import qualified Routing.Hash as R
7+
8+
modifyHash :: forall e. (String -> String) -> Aff (dom :: DOM|e) Unit
9+
modifyHash func = liftEff $ R.modifyHash func
10+
11+
setHash :: forall e. String -> Aff (dom :: DOM|e) Unit
12+
setHash hash = liftEff $ R.setHash hash
13+

0 commit comments

Comments
 (0)