Skip to content

Commit

Permalink
Merge pull request #32 from rnons/remove-property
Browse files Browse the repository at this point in the history
If a property is also an attribute, use removeAttribute
  • Loading branch information
garyb authored Feb 2, 2020
2 parents 34c032a + 655bbda commit efa28b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Halogen/VDom/DOM/Prop.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Prelude

import Data.Function.Uncurried as Fn
import Data.Maybe (Maybe(..))
import Data.Nullable (toNullable)
import Data.Nullable (null, toNullable)
import Data.Tuple (Tuple(..), fst, snd)
import Effect (Effect)
import Effect.Ref as Ref
Expand Down Expand Up @@ -194,9 +194,11 @@ unsafeGetProperty = Util.unsafeGetAny

removeProperty EFn.EffectFn2 String DOM.Element Unit
removeProperty = EFn.mkEffectFn2 \key el →
case typeOf (Fn.runFn2 Util.unsafeGetAny key el) of
"string"EFn.runEffectFn3 Util.unsafeSetAny key "" el
_ → case key of
"rowSpan"EFn.runEffectFn3 Util.unsafeSetAny key 1 el
"colSpan"EFn.runEffectFn3 Util.unsafeSetAny key 1 el
_ → EFn.runEffectFn3 Util.unsafeSetAny key Util.jsUndefined el
EFn.runEffectFn3 Util.hasAttribute null key el >>= if _
then EFn.runEffectFn3 Util.removeAttribute null key el
else case typeOf (Fn.runFn2 Util.unsafeGetAny key el) of
"string"EFn.runEffectFn3 Util.unsafeSetAny key "" el
_ → case key of
"rowSpan"EFn.runEffectFn3 Util.unsafeSetAny key 1 el
"colSpan"EFn.runEffectFn3 Util.unsafeSetAny key 1 el
_ → EFn.runEffectFn3 Util.unsafeSetAny key Util.jsUndefined el
8 changes: 8 additions & 0 deletions src/Halogen/VDom/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ exports.removeAttribute = function (ns, attr, el) {
}
};

exports.hasAttribute = function (ns, attr, el) {
if (ns != null) {
el.hasAttributeNS(ns, attr);
} else {
el.hasAttribute(attr);
}
};

exports.addEventListener = function (ev, listener, el) {
el.addEventListener(ev, listener, false);
};
Expand Down
4 changes: 4 additions & 0 deletions src/Halogen/VDom/Util.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Halogen.VDom.Util
, parentNode
, setAttribute
, removeAttribute
, hasAttribute
, addEventListener
, removeEventListener
, JsUndefined
Expand Down Expand Up @@ -157,6 +158,9 @@ foreign import setAttribute
foreign import removeAttribute
EFn.EffectFn3 (Nullable Namespace) String DOM.Element Unit

foreign import hasAttribute
EFn.EffectFn3 (Nullable Namespace) String DOM.Element Boolean

foreign import addEventListener
EFn.EffectFn3 String DOM.EventListener DOM.Element Unit

Expand Down

0 comments on commit efa28b9

Please sign in to comment.