Skip to content

Commit

Permalink
Replace unsafeCoerce with coerce for classes, d and path (JordanMarti…
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieBallingall authored Aug 7, 2021
1 parent a57fe63 commit ff5b3e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ You can edit this file as you like.
, "newtype"
, "prelude"
, "psci-support"
, "safe-coerce"
, "strings"
, "typelevel-prelude"
, "unsafe-coerce"
Expand Down
17 changes: 5 additions & 12 deletions src/Halogen/Svg/Attributes.purs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ import Halogen.Svg.Attributes.Orient (Orient(..), printOrient)
import Halogen.Svg.Attributes.TextAnchor (TextAnchor(..), printTextAnchor)
import Halogen.Svg.Attributes.Transform (Transform(..), printTransform)
import Halogen.Svg.Core as Core
import Safe.Coerce (coerce)
import Unsafe.Coerce (unsafeCoerce)
import Halogen.Svg.Attributes.Path (
PathCommand,
CommandPositionReference(..),
CommandArcChoice(..),
CommandSweepChoice(..),
toArrayString,
m, l, h, v, c, s, q, t, a, z
)

Expand All @@ -117,10 +119,7 @@ class_ :: forall r i . H.ClassName -> IProp (class :: String | r) i
class_ = attr (H.AttrName "class") <<< un H.ClassName

classes :: forall r i . Array H.ClassName -> IProp (class :: String | r) i
classes = attr (H.AttrName "class") <<< joinWith " " <<< unwrapNewtype
where
unwrapNewtype :: Array H.ClassName -> Array String
unwrapNewtype = unsafeCoerce
classes = attr (H.AttrName "class") <<< joinWith " " <<< coerce

cx :: forall r i. Number -> IProp (cx :: Number | r) i
cx = attr (H.AttrName "cx") <<< show
Expand All @@ -129,10 +128,7 @@ cy :: forall r i. Number -> IProp (cy :: Number | r) i
cy = attr (H.AttrName "cy") <<< show

d :: forall r i . Array PathCommand -> IProp (d :: String | r) i
d = attr (H.AttrName "d") <<< joinWith " " <<< unwrapNewtype
where
unwrapNewtype :: Array PathCommand -> Array String
unwrapNewtype = unsafeCoerce
d = attr (H.AttrName "d") <<< joinWith " " <<< toArrayString

dominant_baseline :: forall r i . Baseline -> IProp (transform :: String | r) i
dominant_baseline = attr (H.AttrName "dominant-baseline") <<< printBaseline
Expand Down Expand Up @@ -206,10 +202,7 @@ orient = attr (H.AttrName "orient") <<< printOrient

-- TODO copied from `d`; adapt where needed
path :: forall r i . Array PathCommand -> IProp (path :: String | r) i
path = attr (H.AttrName "path") <<< joinWith " " <<< unwrapNewtype
where
unwrapNewtype :: Array PathCommand -> Array String
unwrapNewtype = unsafeCoerce
path = attr (H.AttrName "path") <<< joinWith " " <<< toArrayString

preserveAspectRatio :: forall r i. Maybe {x_ :: Align, y_ :: Align} ->
MeetOrSlice -> IProp (preserveAspectRatio :: String | r) i
Expand Down
5 changes: 5 additions & 0 deletions src/Halogen/Svg/Attributes/Path.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module Halogen.Svg.Attributes.Path
, CommandPositionReference(..)
, CommandArcChoice(..)
, CommandSweepChoice(..)
, toArrayString
, m, l, h, v, c, s, q, t, a, z
) where

import Prelude
import Data.String (toUpper)
import Halogen.Svg.Attributes.Utils (printArray)
import Safe.Coerce (coerce)

newtype PathCommand = PathCommand String

Expand All @@ -20,6 +22,9 @@ instance showPathCommand :: Show PathCommand where
printPathCommand :: PathCommand -> String
printPathCommand (PathCommand s_) = s_

toArrayString :: Array PathCommand -> Array String
toArrayString = coerce

data CommandPositionReference = Rel | Abs

derive instance eqCommandPositionReference :: Eq CommandPositionReference
Expand Down

0 comments on commit ff5b3e0

Please sign in to comment.