Skip to content

Commit efa28b9

Browse files
authored
Merge pull request #32 from rnons/remove-property
If a property is also an attribute, use removeAttribute
2 parents 34c032a + 655bbda commit efa28b9

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/Halogen/VDom/DOM/Prop.purs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Prelude
1313

1414
import Data.Function.Uncurried as Fn
1515
import Data.Maybe (Maybe(..))
16-
import Data.Nullable (toNullable)
16+
import Data.Nullable (null, toNullable)
1717
import Data.Tuple (Tuple(..), fst, snd)
1818
import Effect (Effect)
1919
import Effect.Ref as Ref
@@ -194,9 +194,11 @@ unsafeGetProperty = Util.unsafeGetAny
194194

195195
removeProperty EFn.EffectFn2 String DOM.Element Unit
196196
removeProperty = EFn.mkEffectFn2 \key el →
197-
case typeOf (Fn.runFn2 Util.unsafeGetAny key el) of
198-
"string"EFn.runEffectFn3 Util.unsafeSetAny key "" el
199-
_ → case key of
200-
"rowSpan"EFn.runEffectFn3 Util.unsafeSetAny key 1 el
201-
"colSpan"EFn.runEffectFn3 Util.unsafeSetAny key 1 el
202-
_ → EFn.runEffectFn3 Util.unsafeSetAny key Util.jsUndefined el
197+
EFn.runEffectFn3 Util.hasAttribute null key el >>= if _
198+
then EFn.runEffectFn3 Util.removeAttribute null key el
199+
else case typeOf (Fn.runFn2 Util.unsafeGetAny key el) of
200+
"string"EFn.runEffectFn3 Util.unsafeSetAny key "" el
201+
_ → case key of
202+
"rowSpan"EFn.runEffectFn3 Util.unsafeSetAny key 1 el
203+
"colSpan"EFn.runEffectFn3 Util.unsafeSetAny key 1 el
204+
_ → EFn.runEffectFn3 Util.unsafeSetAny key Util.jsUndefined el

src/Halogen/VDom/Util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ exports.removeAttribute = function (ns, attr, el) {
149149
}
150150
};
151151

152+
exports.hasAttribute = function (ns, attr, el) {
153+
if (ns != null) {
154+
el.hasAttributeNS(ns, attr);
155+
} else {
156+
el.hasAttribute(attr);
157+
}
158+
};
159+
152160
exports.addEventListener = function (ev, listener, el) {
153161
el.addEventListener(ev, listener, false);
154162
};

src/Halogen/VDom/Util.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Halogen.VDom.Util
2424
, parentNode
2525
, setAttribute
2626
, removeAttribute
27+
, hasAttribute
2728
, addEventListener
2829
, removeEventListener
2930
, JsUndefined
@@ -157,6 +158,9 @@ foreign import setAttribute
157158
foreign import removeAttribute
158159
EFn.EffectFn3 (Nullable Namespace) String DOM.Element Unit
159160

161+
foreign import hasAttribute
162+
EFn.EffectFn3 (Nullable Namespace) String DOM.Element Boolean
163+
160164
foreign import addEventListener
161165
EFn.EffectFn3 String DOM.EventListener DOM.Element Unit
162166

0 commit comments

Comments
 (0)