Skip to content

Commit 7114c7a

Browse files
committed
Updates for 0.12
1 parent 9436bbd commit 7114c7a

File tree

6 files changed

+124
-154
lines changed

6 files changed

+124
-154
lines changed

bower.json

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,26 @@
2424
"package.json"
2525
],
2626
"dependencies": {
27-
"purescript-dom": "^4.15.0",
28-
"purescript-eff": "^3.1.0",
29-
"purescript-either": "^3.0.0",
30-
"purescript-globals": "^3.0.0",
31-
"purescript-lists": "^4.0.1",
32-
"purescript-maps": "^3.0.0",
33-
"purescript-maybe": "^3.0.0",
34-
"purescript-prelude": "^3.0.0",
35-
"purescript-semirings": "^4.0.0",
36-
"purescript-tuples": "^4.0.0",
37-
"purescript-validation": "^3.0.0",
38-
"purescript-aff": "^4.0.0",
39-
"purescript-control": "^3.0.0",
40-
"purescript-console": "^3.0.0",
41-
"purescript-integers": "^3.0.0",
42-
"purescript-foldable-traversable": "^3.7.1"
27+
"purescript-web-html": "#compiler/0.12",
28+
"purescript-effect": "#compiler/0.12",
29+
"purescript-either": "#compiler/0.12",
30+
"purescript-globals": "#compiler/0.12",
31+
"purescript-lists": "#compiler/0.12",
32+
"purescript-maybe": "#compiler/0.12",
33+
"purescript-prelude": "#compiler/0.12",
34+
"purescript-semirings": "#compiler/0.12",
35+
"purescript-tuples": "#compiler/0.12",
36+
"purescript-validation": "#compiler/0.12",
37+
"purescript-aff": "#compiler/0.12",
38+
"purescript-control": "#compiler/0.12",
39+
"purescript-console": "#compiler/0.12",
40+
"purescript-integers": "#compiler/0.12",
41+
"purescript-foldable-traversable": "#compiler/0.12"
4342
},
4443
"devDependencies": {
45-
"purescript-console": "^3.0.0",
46-
"purescript-assert": "^3.1.0",
47-
"purescript-record": "^0.2.6",
48-
"purescript-generics-rep": "^5.4.0"
44+
"purescript-console": "#compiler/0.12",
45+
"purescript-assert": "#compiler/0.12",
46+
"purescript-record": "#compiler/0.12",
47+
"purescript-generics-rep": "#compiler/0.12"
4948
}
5049
}

src/Routing.purs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
module Routing
2-
( RoutingEffects
3-
, match
2+
( match
43
, matchWith
54
) where
65

76
import Prelude
87

9-
import Control.Monad.Eff.Ref (REF)
108
import Data.Either (Either)
11-
import DOM (DOM)
129
import Global (decodeURIComponent)
1310
import Routing.Match (Match, runMatch)
1411
import Routing.Parser (parse)
1512

16-
type RoutingEffects eff =
17-
( dom :: DOM
18-
, ref :: REF
19-
| eff
20-
)
21-
2213
-- | Runs a `Match` parser.
2314
match :: forall a. Match a -> String -> Either String a
2415
match = matchWith decodeURIComponent

src/Routing/Hash.purs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,78 +11,73 @@ module Routing.Hash
1111

1212
import Prelude
1313

14-
import Control.Monad.Eff (Eff)
15-
import Control.Monad.Eff.Ref (newRef, readRef, writeRef)
16-
import DOM (DOM)
17-
import DOM.Event.EventTarget (addEventListener, eventListener, removeEventListener)
18-
import DOM.HTML (window)
19-
import DOM.HTML.Event.EventTypes (hashchange)
20-
import DOM.HTML.Location as L
21-
import DOM.HTML.Types (windowToEventTarget)
22-
import DOM.HTML.Window (location)
14+
import Effect (Effect)
15+
import Effect.Ref as Ref
16+
import Web.Event.EventTarget (addEventListener, eventListener, removeEventListener)
17+
import Web.HTML (window)
18+
import Web.HTML.Location as L
19+
import Web.HTML.Window as Window
20+
import Web.HTML.Window.EventTypes as WET
2321
import Data.Foldable (class Foldable, indexl)
2422
import Data.Maybe (Maybe(..), fromMaybe, maybe)
2523
import Data.String (Pattern(..), stripPrefix)
26-
import Routing (RoutingEffects, match, matchWith)
24+
import Routing (match, matchWith)
2725
import Routing.Match (Match)
2826

2927
-- | Gets the global location hash.
30-
getHash :: forall eff. Eff (dom :: DOM | eff) String
31-
getHash = window >>= location >>= L.hash >>> map (stripPrefix (Pattern "#") >>> fromMaybe "")
28+
getHash :: Effect String
29+
getHash = window >>= Window.location >>= L.hash >>> map (stripPrefix (Pattern "#") >>> fromMaybe "")
3230

3331
-- | Sets the global location hash.
34-
setHash :: forall eff. String -> Eff (dom :: DOM | eff) Unit
35-
setHash h = window >>= location >>= L.setHash h
32+
setHash :: String -> Effect Unit
33+
setHash h = window >>= Window.location >>= L.setHash h
3634

3735
-- | Modifies the global location hash.
38-
modifyHash :: forall eff. (String -> String) -> Eff (dom :: DOM | eff) Unit
36+
modifyHash :: (String -> String) -> Effect Unit
3937
modifyHash fn = (fn <$> getHash) >>= setHash
4038

4139
-- | Folds effectfully over hash changes given a callback and an initial hash.
4240
-- | The provided String is the hash portion of the `Location` with the '#'
4341
-- | prefix stripped. Returns an effect which will remove the listener.
4442
foldHashes
45-
:: forall eff a
46-
. (a -> String -> Eff (RoutingEffects eff) a)
47-
-> (String -> Eff (RoutingEffects eff) a)
48-
-> Eff (RoutingEffects eff) (Eff (RoutingEffects eff) Unit)
43+
:: forall a
44+
. (a -> String -> Effect a)
45+
-> (String -> Effect a)
46+
-> Effect (Effect Unit)
4947
foldHashes cb init = do
50-
ref <- newRef =<< init =<< getHash
51-
win <- windowToEventTarget <$> window
52-
let listener = eventListener \_ -> writeRef ref =<< join (cb <$> readRef ref <*> getHash)
53-
addEventListener hashchange listener false win
54-
pure $ removeEventListener hashchange listener false win
48+
ref <- Ref.new =<< init =<< getHash
49+
win <- Window.toEventTarget <$> window
50+
listener <- eventListener \_ -> flip Ref.write ref =<< join (cb <$> Ref.read ref <*> getHash)
51+
addEventListener WET.hashchange listener false win
52+
pure $ removeEventListener WET.hashchange listener false win
5553

5654
-- | Runs the callback on every hash change providing the previous hash and the
5755
-- | latest hash. The provided String is the hash portion of the `Location` with
5856
-- | the '#' prefix stripped. Returns an effect which will remove the listener.
59-
hashes
60-
:: forall eff
61-
. (Maybe String -> String -> Eff (RoutingEffects eff) Unit)
62-
-> Eff (RoutingEffects eff) (Eff (RoutingEffects eff) Unit)
57+
hashes :: (Maybe String -> String -> Effect Unit) -> Effect (Effect Unit)
6358
hashes = matchesWith Just
6459

6560
-- | Runs the callback on every hash change using a given `Match` parser to
6661
-- | extract a route from the hash. If a hash fails to parse, it is ignored.
6762
-- | To avoid dropping hashes, provide a fallback alternative in your parser.
6863
-- | Returns an effect which will remove the listener.
6964
matches
70-
:: forall eff a
65+
:: forall a
7166
. Match a
72-
-> (Maybe a -> a -> Eff (RoutingEffects eff) Unit)
73-
-> Eff (RoutingEffects eff) (Eff (RoutingEffects eff) Unit)
67+
-> (Maybe a -> a -> Effect Unit)
68+
-> Effect (Effect Unit)
7469
matches = matchesWith <<< match
7570

7671
-- | Runs the callback on every hash change using a given custom parser to
7772
-- | extract a route from the hash. If a hash fails to parse, it is ignored.
7873
-- | To avoid dropping hashes, provide a fallback alternative in your parser.
7974
-- | Returns an effect which will remove the listener.
8075
matchesWith
81-
:: forall eff f a
76+
:: forall f a
8277
. Foldable f
8378
=> (String -> f a)
84-
-> (Maybe a -> a -> Eff (RoutingEffects eff) Unit)
85-
-> Eff (RoutingEffects eff) (Eff (RoutingEffects eff) Unit)
79+
-> (Maybe a -> a -> Effect Unit)
80+
-> Effect (Effect Unit)
8681
matchesWith parser cb = foldHashes go (go Nothing)
8782
where
8883
go a =

src/Routing/Match.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ instance matchApply :: Apply Match where
120120
apply (Match r2a2b) (Match r2a) =
121121
Match $ (\r -> unV (processFnErr r) processFnRes (r2a2b r))
122122
where processFnErr r err =
123-
invalid $ err * unV id (const one) (r2a r)
123+
invalid $ err * unV identity (const one) (r2a r)
124124
processFnRes (Tuple rs a2b) =
125125
unV invalid (\(Tuple rss a) -> pure $ Tuple rss (a2b a)) (r2a rs)
126126

src/Routing/Match/Error.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data MatchError
1313
| ExpectedNumber
1414
-- expected integer literal
1515
| ExpectedInt
16-
-- expected string literal (found query probably or eol)
16+
-- expected string literal (found query probably or eol)
1717
| ExpectedString
1818
-- expected query found path part or eol
1919
| ExpectedQuery
@@ -22,7 +22,7 @@ data MatchError
2222
-- there is no such key in query
2323
| KeyNotFound String
2424
-- custom fail
25-
| Fail String
25+
| Fail String
2626

2727
showMatchError :: MatchError -> String
2828
showMatchError err =

0 commit comments

Comments
 (0)