Skip to content

Commit

Permalink
Update for PureScript 0.14 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin Wahl authored Mar 3, 2021
1 parent 150d92b commit 34963d5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
29 changes: 14 additions & 15 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@
"output"
],
"dependencies": {
"purescript-prelude": "^4.1.0",
"purescript-record": "^2.0.0",
"purescript-generics-rep": "^6.0.0",
"purescript-either": "^4.0.0",
"purescript-control": "^4.1.0",
"purescript-arrays": "^5.0.0",
"purescript-globals": "^4.0.0",
"purescript-strings": "^4.0.0",
"purescript-lazy": "^4.0.0",
"purescript-profunctor": "^4.0.0"
"purescript-prelude": "^5.0.0",
"purescript-record": "^3.0.0",
"purescript-either": "^5.0.0",
"purescript-control": "^5.0.0",
"purescript-arrays": "^6.0.0",
"purescript-strings": "^5.0.0",
"purescript-lazy": "^5.0.0",
"purescript-profunctor": "^5.0.0",
"purescript-js-uri": "https://github.com/purescript-contrib/purescript-js-uri.git#2.0.0"
},
"devDependencies": {
"purescript-psci-support": "^4.0.0",
"purescript-console": "^4.1.0",
"purescript-effect": "^2.0.0",
"purescript-assert": "^4.0.0",
"purescript-quickcheck": "^6.1.0"
"purescript-psci-support": "^5.0.0",
"purescript-console": "^5.0.0",
"purescript-effect": "^3.0.0",
"purescript-assert": "^5.0.0",
"purescript-quickcheck": "^7.0.0"
}
}
6 changes: 3 additions & 3 deletions src/Routing/Duplex.purs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Data.String (Pattern(..))
import Data.String as String
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
import Prim.Row as Row
import Prim.RowList (kind RowList, class RowToList, Cons, Nil)
import Prim.RowList (RowList, class RowToList, Cons, Nil)
import Record as Record
import Routing.Duplex.Parser (RouteParser)
import Routing.Duplex.Parser as Parser
Expand Down Expand Up @@ -328,7 +328,7 @@ prop sym (RouteDuplex f g) (RouteDuplex x y) =

infix 2 prop as :=

class RouteDuplexParams (r1 :: # Type) (r2 :: # Type) | r1 -> r2 where
class RouteDuplexParams (r1 :: Row Type) (r2 :: Row Type) | r1 -> r2 where
-- | Builds a `RouteDuplex` from a record of query parameter parsers/printers, where
-- | each property corresponds to a query parameter with the same name.
-- |
Expand All @@ -353,7 +353,7 @@ instance routeDuplexParams ::
record
# buildParams (RLProxy :: RLProxy rl) r

class RouteDuplexBuildParams (rl :: RowList) (r1 :: # Type) (r2 :: # Type) (r3 :: # Type) (r4 :: # Type) | rl -> r1 r2 r3 r4 where
class RouteDuplexBuildParams (rl :: RowList Type) (r1 :: Row Type) (r2 :: Row Type) (r3 :: Row Type) (r4 :: Row Type) | rl -> r1 r2 r3 r4 where
buildParams ::
RLProxy rl ->
{ | r1 } ->
Expand Down
2 changes: 1 addition & 1 deletion src/Routing/Duplex/Generic.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sum :: forall a rep r.
RouteDuplex' a
sum = dimap from to <<< gRouteDuplex

class GRouteDuplex rep (r :: # Type) | rep -> r where
class GRouteDuplex rep (r :: Row Type) | rep -> r where
gRouteDuplex :: { | r } -> RouteDuplex' rep

instance gRouteSum ::
Expand Down
14 changes: 8 additions & 6 deletions src/Routing/Duplex/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ import Data.Array.NonEmpty (NonEmptyArray)
import Data.Array.NonEmpty as NEA
import Data.Bifunctor (bimap, lmap)
import Data.Either (Either(..))
import Data.Foldable (foldl)
import Data.Foldable (foldl, lookup)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Int as Int
import Data.Lazy as Z
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe (Maybe(..), fromJust, maybe)
import Data.Show.Generic (genericShow)
import Data.String (Pattern(..), split)
import Data.String.CodeUnits as String
import Data.Tuple (Tuple(..))
import Data.Tuple as Tuple
import Global.Unsafe (unsafeDecodeURIComponent)
import JSURI (decodeURIComponent)
import Partial.Unsafe (unsafePartial)
import Routing.Duplex.Types (RouteParams, RouteState)

data RouteResult a
Expand Down Expand Up @@ -163,6 +163,8 @@ parsePath =
splitAt (flip Tuple "") "?"
>>> bimap splitSegments splitParams

unsafeDecodeURIComponent = unsafePartial fromJust <<< decodeURIComponent

splitSegments = splitNonEmpty (Pattern "/") >>> case _ of
["", ""] -> [""]
xs -> map unsafeDecodeURIComponent xs
Expand Down Expand Up @@ -200,7 +202,7 @@ take = Chomp \state ->

param :: String -> RouteParser String
param key = Chomp \state ->
case Tuple.lookup key state.params of
case lookup key state.params of
Just a -> Success state a
_ -> Fail $ MissingParam key

Expand Down
6 changes: 5 additions & 1 deletion src/Routing/Duplex/Printer.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import Prelude

import Data.Array as Array
import Data.Function (applyFlipped)
import Data.Maybe (fromJust)
import Data.Newtype (class Newtype, unwrap)
import Data.String (joinWith)
import Data.Tuple (Tuple(..), uncurry)
import Global.Unsafe (unsafeEncodeURIComponent)
import JSURI (encodeURIComponent)
import Partial.Unsafe (unsafePartial)
import Routing.Duplex.Types (RouteState, emptyRouteState)

newtype RoutePrinter = RoutePrinter (RouteState -> RouteState)
Expand Down Expand Up @@ -49,6 +51,8 @@ printPath :: RouteState -> String
printPath { segments, params, hash: hash' } =
printSegments segments <> printParams params <> printHash hash'
where
unsafeEncodeURIComponent = unsafePartial fromJust <<< encodeURIComponent

printSegments = case _ of
[""] -> "/"
xs -> joinWith "/" $ map unsafeEncodeURIComponent xs
Expand Down
2 changes: 1 addition & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Prelude hiding ((/))

import Data.Either (Either(..))
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Show.Generic (genericShow)
import Data.String.Gen (genAlphaString)
import Data.Symbol (SProxy(..))
import Effect (Effect)
Expand Down

0 comments on commit 34963d5

Please sign in to comment.