|
1 | 1 | module Halogen.VDom.DOM.Prop.Implementation where
|
2 | 2 |
|
3 |
| -import Halogen.VDom.DOM.Prop.Types (ElemRef(..), EmitterInputBuilder, EventListenerAndCurrentEmitterInputBuilder, Prop(..), PropValue) |
| 3 | +import Halogen.VDom.DOM.Prop.Types (ElemRef(..), EmitterInputBuilder, EventListenerAndCurrentEmitterInputBuilder, Prop(..)) |
| 4 | +import Halogen.VDom.DOM.Prop.Checkers (checkAttributeExistsAndIsEqual, checkPropExistsAndIsEqual) |
4 | 5 | import Halogen.VDom.DOM.Prop.Utils (removeProperty, setProperty, unsafeGetProperty)
|
5 |
| -import Prelude (Unit, bind, discard, pure, unit, ($), (<#>), (<>), (==)) |
| 6 | +import Prelude (Unit, bind, discard, pure, unit, (==)) |
6 | 7 |
|
7 | 8 | import Data.Function.Uncurried as Fn
|
8 | 9 | import Data.Maybe (Maybe(..))
|
9 |
| -import Data.Nullable (toMaybe, toNullable) |
| 10 | +import Data.Nullable (toNullable) |
10 | 11 | import Data.Tuple (Tuple(..), fst, snd)
|
11 | 12 | import Effect (Effect)
|
12 | 13 | import Effect.Ref as Ref
|
13 | 14 | import Effect.Uncurried as EFn
|
14 | 15 | import Foreign.Object as Object
|
15 |
| -import Halogen.VDom.Types (ElemName(..), Namespace) |
16 |
| -import Halogen.VDom.Util (STObject', anyToString, fullAttributeName, quote) |
| 16 | +import Halogen.VDom.Types (ElemName(..)) |
| 17 | +import Halogen.VDom.Util (STObject', fullAttributeName) |
17 | 18 | import Halogen.VDom.Util as Util
|
18 | 19 | import Web.DOM.Element (Element) as DOM
|
19 | 20 | import Web.Event.Event (EventType(..), Event) as DOM
|
20 | 21 | import Web.Event.EventTarget (eventListener, EventListener) as DOM
|
21 | 22 | import Data.String.Common (toLower)
|
22 |
| -import Effect.Exception (error, throwException) |
23 | 23 | import Halogen.VDom.Set as Set
|
24 | 24 |
|
25 |
| -checkAttributeExistsAndIsEqual ∷ Maybe Namespace → String → String → DOM.Element → Effect Unit |
26 |
| -checkAttributeExistsAndIsEqual maybeNamespace attributeName expectedElementValue element = do |
27 |
| - elementValue ← (EFn.runEffectFn3 Util.getAttribute (toNullable maybeNamespace) attributeName element) <#> toMaybe |
28 |
| - case elementValue of |
29 |
| - Nothing → throwException $ error $ "Expected element to have an attribute " <> quote (fullAttributeName maybeNamespace (ElemName attributeName)) <> " eq to " <> quote expectedElementValue <> ", but it is missing" |
30 |
| - Just elementValue' → |
31 |
| - if elementValue' == expectedElementValue |
32 |
| - then pure unit |
33 |
| - else throwException $ error $ "Expected element to have an attribute " <> quote (fullAttributeName maybeNamespace (ElemName attributeName)) <> " eq to " <> quote expectedElementValue <> ", but it was equal to " <> quote elementValue' |
34 |
| - |
35 |
| -checkPropExistsAndIsEqual ∷ String → PropValue → DOM.Element → Effect Unit |
36 |
| -checkPropExistsAndIsEqual propName expectedPropValue el = do |
37 |
| - let propValue = Fn.runFn2 unsafeGetProperty propName el |
38 |
| - if Fn.runFn2 Util.refEq propValue expectedPropValue |
39 |
| - then pure unit |
40 |
| - else do |
41 |
| - throwException $ error $ "Expected element to have a prop " <> quote propName <> " eq to " <> quote (anyToString expectedPropValue) <> ", but it was equal to " <> quote (anyToString propValue) |
42 |
| - |
43 | 25 | hydrateApplyProp
|
44 | 26 | ∷ ∀ a
|
45 | 27 | . Fn.Fn4
|
|
0 commit comments