Skip to content

Commit d54e582

Browse files
author
Serhii Khoma
committed
1 parent bd7744e commit d54e582

File tree

6 files changed

+29
-59
lines changed

6 files changed

+29
-59
lines changed

packages.dhall

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ let overrides =
126126
upstream.web-dom // { repo = "https://github.com/srghma/purescript-web-dom.git", version = "patch-1" }
127127
}
128128

129-
let additions = {=}
129+
let additions =
130+
{ foreign-js-set =
131+
{ dependencies =
132+
[ "console", "effect", "psci-support" ]
133+
, repo =
134+
"https://github.com/srghma/purescript-foreign-js-set.git"
135+
, version =
136+
"master"
137+
}
138+
}
130139

131140
in upstream // overrides // additions

spago.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ You can edit this file as you like.
2222
, "strings"
2323
, "control"
2424
, "lazy"
25+
, "foreign-js-set"
2526
]
2627
, packages = ./packages.dhall
2728
, sources = [ "src/**/*.purs", "test/**/*.purs" ]

src/Halogen/VDom/DOM/Prop/Checkers.purs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import Effect.Uncurried as EFn
1212
import Halogen.VDom.Attributes (attributes, forEachE) as Attributes
1313
import Halogen.VDom.DOM.Prop.Types (Prop, PropValue)
1414
import Halogen.VDom.DOM.Prop.Util (unsafeGetProperty)
15-
import Halogen.VDom.Set as Set
15+
import Foreign.JsSet (JsSet)
16+
import Foreign.JsSet as JsSet
1617
import Halogen.VDom.Types (Namespace)
1718
import Halogen.VDom.Util as Util
1819
import Web.DOM.Element (Element) as DOM
@@ -39,16 +40,18 @@ checkPropExistsAndIsEqual propName expectedPropValue element = do
3940
throwException $ error $ "Expected element to have a prop " <> Util.quote propName <> " eq to " <> Util.quote (Util.anyToString expectedPropValue) <> ", but it was equal to " <> Util.quote (Util.anyToString propValue) <> " (check warning above for more information)"
4041

4142
-- | Inspired by https://github.com/facebook/react/blob/823dc581fea8814a904579e85a62da6d18258830/packages/react-dom/src/client/ReactDOMComponent.js#L1030
42-
mkExtraAttributeNames DOM.Element Effect (Set.Set String)
43+
mkExtraAttributeNames DOM.Element Effect (JsSet String)
4344
mkExtraAttributeNames el = do
4445
let
4546
namedNodeMap = Attributes.attributes el
46-
(set Set.Set String) ← Set.empty
47-
EFn.runEffectFn2 Attributes.forEachE namedNodeMap (EFn.mkEffectFn1 \attribute → EFn.runEffectFn2 Set.add attribute.name set)
47+
(set JsSet String) ← JsSet.empty
48+
EFn.runEffectFn2 Attributes.forEachE namedNodeMap (EFn.mkEffectFn1 \attribute → EFn.runEffectFn2 JsSet._add attribute.name set)
4849
pure set
4950

50-
checkExtraAttributeNamesIsEmpty forall a . Array (Prop a) -> Set.Set String -> DOM.Element -> Effect Unit
51-
checkExtraAttributeNamesIsEmpty propsToHydrate extraAttributeNames element =
52-
when (Set.size extraAttributeNames > 0) do
51+
checkExtraAttributeNamesIsEmpty forall a . Array (Prop a) -> JsSet String -> DOM.Element -> Effect Unit
52+
checkExtraAttributeNamesIsEmpty propsToHydrate extraAttributeNames element = do
53+
size <- EFn.runEffectFn1 JsSet._size extraAttributeNames
54+
when (size > 0) do
5355
EFn.runEffectFn2 Util.warnAny "Error info: " { extraAttributeNames, element, propsToHydrate }
54-
throwException $ error $ "Extra attributes from the server: " <> (Set.toArray extraAttributeNames # joinWith ", ") <> " (check warning above for more information)"
56+
extraAttributeNames' <- EFn.runEffectFn1 JsSet._toArray extraAttributeNames
57+
throwException $ error $ "Extra attributes from the server: " <> joinWith ", " extraAttributeNames' <> " (check warning above for more information)"

src/Halogen/VDom/DOM/Prop/Implementation.purs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import Foreign.Object as Object
1515
import Halogen.VDom.DOM.Prop.Checkers (checkAttributeExistsAndIsEqual, checkPropExistsAndIsEqual)
1616
import Halogen.VDom.DOM.Prop.Types (ElemRef(..), EmitterInputBuilder, EventListenerAndCurrentEmitterInputBuilder, Prop(..), PropValue)
1717
import Halogen.VDom.DOM.Prop.Util (removeProperty, setProperty, unsafeGetProperty)
18-
import Halogen.VDom.Set as Set
18+
import Foreign.JsSet (JsSet)
19+
import Foreign.JsSet as JsSet
1920
import Halogen.VDom.Util (STObject', anyToString, fullAttributeName, quote)
2021
import Halogen.VDom.Util as Util
2122
import Web.DOM.Element (Element) as DOM
@@ -24,24 +25,24 @@ import Web.Event.EventTarget (eventListener, EventListener) as DOM
2425
import Foreign (unsafeToForeign, typeOf)
2526
import Unsafe.Coerce (unsafeCoerce)
2627

27-
deleteRequiredElement :: EFn.EffectFn2 String (Set.Set String) Unit
28+
deleteRequiredElement :: EFn.EffectFn2 String (JsSet String) Unit
2829
deleteRequiredElement = EFn.mkEffectFn2 \element extraAttributeNames -> do
29-
let isPresent = Fn.runFn2 Set.has element extraAttributeNames
30+
isPresent <- EFn.runEffectFn2 JsSet._has element extraAttributeNames
3031
if isPresent
31-
then EFn.runEffectFn2 Set.delete element extraAttributeNames
32+
then EFn.runEffectFn2 JsSet._delete element extraAttributeNames
3233
else do
3334
EFn.runEffectFn2 Util.warnAny "Error info: " { element, extraAttributeNames }
3435
throwException $ error $ "Cannot delete element " <> quote element <> " that is not present in extraAttributeNames (check warning above for more information)"
3536

36-
checkPropExistsAndIsEqualAndDelete :: EFn.EffectFn5 (Set.Set String) String PropValue DOM.Element String Unit
37+
checkPropExistsAndIsEqualAndDelete :: EFn.EffectFn5 (JsSet String) String PropValue DOM.Element String Unit
3738
checkPropExistsAndIsEqualAndDelete = EFn.mkEffectFn5 \extraAttributeNames propName val el correspondingAttributeName -> do
3839
checkPropExistsAndIsEqual propName val el
3940
EFn.runEffectFn2 deleteRequiredElement correspondingAttributeName extraAttributeNames
4041

4142
hydrateApplyProp
4243
a
4344
. Fn.Fn4
44-
(Set.Set String)
45+
(JsSet String)
4546
DOM.Element
4647
(a Effect Unit)
4748
(STObject' (EventListenerAndCurrentEmitterInputBuilder a))

src/Halogen/VDom/Set.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Halogen/VDom/Set.purs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)