diff --git a/src/Halogen/VDom/DOM/Prop/Checkers.purs b/src/Halogen/VDom/DOM/Prop/Checkers.purs index 7ab1815..9c6f9d2 100644 --- a/src/Halogen/VDom/DOM/Prop/Checkers.purs +++ b/src/Halogen/VDom/DOM/Prop/Checkers.purs @@ -12,7 +12,8 @@ import Effect.Uncurried as EFn import Halogen.VDom.Attributes (attributes, forEachE) as Attributes import Halogen.VDom.DOM.Prop.Types (Prop, PropValue) import Halogen.VDom.DOM.Prop.Util (unsafeGetProperty) -import Halogen.VDom.Set as Set +import Halogen.VDom.JsSet (JsSet) +import Halogen.VDom.JsSet as JsSet import Halogen.VDom.Types (Namespace) import Halogen.VDom.Util as Util import Web.DOM.Element (Element) as DOM @@ -39,16 +40,18 @@ checkPropExistsAndIsEqual propName expectedPropValue element = do 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)" -- | Inspired by https://github.com/facebook/react/blob/823dc581fea8814a904579e85a62da6d18258830/packages/react-dom/src/client/ReactDOMComponent.js#L1030 -mkExtraAttributeNames ∷ DOM.Element → Effect (Set.Set String) +mkExtraAttributeNames ∷ DOM.Element → Effect (JsSet String) mkExtraAttributeNames el = do let namedNodeMap = Attributes.attributes el - (set ∷ Set.Set String) ← Set.empty - EFn.runEffectFn2 Attributes.forEachE namedNodeMap (EFn.mkEffectFn1 \attribute → EFn.runEffectFn2 Set.add attribute.name set) + (set ∷ JsSet String) ← JsSet.empty + EFn.runEffectFn2 Attributes.forEachE namedNodeMap (EFn.mkEffectFn1 \attribute → EFn.runEffectFn2 JsSet._add attribute.name set) pure set -checkExtraAttributeNamesIsEmpty ∷ forall a . Array (Prop a) -> Set.Set String -> DOM.Element -> Effect Unit -checkExtraAttributeNamesIsEmpty propsToHydrate extraAttributeNames element = - when (Set.size extraAttributeNames > 0) do +checkExtraAttributeNamesIsEmpty ∷ forall a . Array (Prop a) -> JsSet String -> DOM.Element -> Effect Unit +checkExtraAttributeNamesIsEmpty propsToHydrate extraAttributeNames element = do + size <- EFn.runEffectFn1 JsSet._size extraAttributeNames + when (size > 0) do EFn.runEffectFn2 Util.warnAny "Error info: " { extraAttributeNames, element, propsToHydrate } - throwException $ error $ "Extra attributes from the server: " <> (Set.toArray extraAttributeNames # joinWith ", ") <> " (check warning above for more information)" + extraAttributeNames' <- EFn.runEffectFn1 JsSet._toArray extraAttributeNames + throwException $ error $ "Extra attributes from the server: " <> joinWith ", " extraAttributeNames' <> " (check warning above for more information)" diff --git a/src/Halogen/VDom/DOM/Prop/Implementation.purs b/src/Halogen/VDom/DOM/Prop/Implementation.purs index 5a8f471..d6efa28 100644 --- a/src/Halogen/VDom/DOM/Prop/Implementation.purs +++ b/src/Halogen/VDom/DOM/Prop/Implementation.purs @@ -15,7 +15,8 @@ import Foreign.Object as Object import Halogen.VDom.DOM.Prop.Checkers (checkAttributeExistsAndIsEqual, checkPropExistsAndIsEqual) import Halogen.VDom.DOM.Prop.Types (ElemRef(..), EmitterInputBuilder, EventListenerAndCurrentEmitterInputBuilder, Prop(..), PropValue) import Halogen.VDom.DOM.Prop.Util (removeProperty, setProperty, unsafeGetProperty) -import Halogen.VDom.Set as Set +import Halogen.VDom.JsSet (JsSet) +import Halogen.VDom.JsSet as JsSet import Halogen.VDom.Util (STObject', anyToString, fullAttributeName, quote) import Halogen.VDom.Util as Util import Web.DOM.Element (Element) as DOM @@ -24,16 +25,16 @@ import Web.Event.EventTarget (eventListener, EventListener) as DOM import Foreign (unsafeToForeign, typeOf) import Unsafe.Coerce (unsafeCoerce) -deleteRequiredElement :: EFn.EffectFn2 String (Set.Set String) Unit +deleteRequiredElement :: EFn.EffectFn2 String (JsSet String) Unit deleteRequiredElement = EFn.mkEffectFn2 \element extraAttributeNames -> do - let isPresent = Fn.runFn2 Set.has element extraAttributeNames + isPresent <- EFn.runEffectFn2 JsSet._has element extraAttributeNames if isPresent - then EFn.runEffectFn2 Set.delete element extraAttributeNames + then EFn.runEffectFn2 JsSet._delete element extraAttributeNames else do EFn.runEffectFn2 Util.warnAny "Error info: " { element, extraAttributeNames } throwException $ error $ "Cannot delete element " <> quote element <> " that is not present in extraAttributeNames (check warning above for more information)" -checkPropExistsAndIsEqualAndDelete :: EFn.EffectFn5 (Set.Set String) String PropValue DOM.Element String Unit +checkPropExistsAndIsEqualAndDelete :: EFn.EffectFn5 (JsSet String) String PropValue DOM.Element String Unit checkPropExistsAndIsEqualAndDelete = EFn.mkEffectFn5 \extraAttributeNames propName val el correspondingAttributeName -> do checkPropExistsAndIsEqual propName val el EFn.runEffectFn2 deleteRequiredElement correspondingAttributeName extraAttributeNames @@ -41,7 +42,7 @@ checkPropExistsAndIsEqualAndDelete = EFn.mkEffectFn5 \extraAttributeNames propNa hydrateApplyProp ∷ ∀ a . Fn.Fn4 - (Set.Set String) + (JsSet String) DOM.Element (a → Effect Unit) (STObject' (EventListenerAndCurrentEmitterInputBuilder a)) diff --git a/src/Halogen/VDom/JsSet.js b/src/Halogen/VDom/JsSet.js new file mode 100644 index 0000000..322c3bc --- /dev/null +++ b/src/Halogen/VDom/JsSet.js @@ -0,0 +1,23 @@ +exports.empty = function() { + return new Set() +} + +exports._delete = function(value, set) { + set.delete(value) +} + +exports._add = function(value, set) { + set.add(value) +} + +exports._size = function(set) { + return set.size +} + +exports._has = function(value, set) { + return set.has(value) +} + +exports._toArray = function(set) { + return Array.from(set) +} diff --git a/src/Halogen/VDom/JsSet.purs b/src/Halogen/VDom/JsSet.purs new file mode 100644 index 0000000..f0bbfde --- /dev/null +++ b/src/Halogen/VDom/JsSet.purs @@ -0,0 +1,20 @@ +module Halogen.VDom.JsSet where + +import Prelude + +import Effect (Effect) +import Effect.Uncurried (EffectFn1, EffectFn2) as EFn + +data JsSet a + +foreign import empty ∷ ∀ a . Effect (JsSet a) + +foreign import _delete ∷ ∀ a . EFn.EffectFn2 a (JsSet a) Unit + +foreign import _add ∷ ∀ a . EFn.EffectFn2 a (JsSet a) Unit + +foreign import _size ∷ ∀ a . EFn.EffectFn1 (JsSet a) Int + +foreign import _has ∷ ∀ a . EFn.EffectFn2 a (JsSet a) Boolean + +foreign import _toArray ∷ ∀ a . EFn.EffectFn1 (JsSet a) (Array a) diff --git a/src/Halogen/VDom/Set.js b/src/Halogen/VDom/Set.js deleted file mode 100644 index 61fec63..0000000 --- a/src/Halogen/VDom/Set.js +++ /dev/null @@ -1,23 +0,0 @@ -exports.empty = function() { - return new Set() -} - -exports.delete = function(value, set) { - set.delete(value) -} - -exports.add = function(value, set) { - set.add(value) -} - -exports.size = function(set) { - return set.size -} - -exports.has = function(value, set) { - return set.has(value) -} - -exports.toArray = function(set) { - return Array.from(set) -} diff --git a/src/Halogen/VDom/Set.purs b/src/Halogen/VDom/Set.purs deleted file mode 100644 index 41b5dff..0000000 --- a/src/Halogen/VDom/Set.purs +++ /dev/null @@ -1,21 +0,0 @@ -module Halogen.VDom.Set where - -import Prelude (Unit) - -import Effect (Effect) -import Effect.Uncurried (EffectFn2) as EFn -import Data.Function.Uncurried as Fn - -data Set proxy - -foreign import empty ∷ ∀ a . Effect (Set a) - -foreign import delete ∷ ∀ a . EFn.EffectFn2 a (Set a) Unit - -foreign import add ∷ ∀ a . EFn.EffectFn2 a (Set a) Unit - -foreign import size ∷ ∀ a . Set a → Int - -foreign import has ∷ ∀ a . Fn.Fn2 a (Set a) Boolean - -foreign import toArray ∷ ∀ a . Set a → Array a