From bc4356a40c614106d12da1e302934f2ecfa4182e Mon Sep 17 00:00:00 2001 From: rightfold Date: Wed, 7 Jun 2017 17:32:13 +0200 Subject: [PATCH 1/2] Return value of the correct constructor from _readEventTarget --- src/DOM/Event/Types.purs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/DOM/Event/Types.purs b/src/DOM/Event/Types.purs index e001213..95ad807 100644 --- a/src/DOM/Event/Types.purs +++ b/src/DOM/Event/Types.purs @@ -39,9 +39,10 @@ module DOM.Event.Types ) where import Prelude +import Data.Bifunctor (lmap) import Data.Either (Either(..)) -import Data.Foreign (F, Foreign, unsafeReadTagged) -import Data.Newtype (class Newtype) +import Data.Foreign (F, Foreign, ForeignError(ForeignError), unsafeReadTagged) +import Data.Newtype (class Newtype, wrap) import Unsafe.Coerce as U -- | Basic type for all DOM events. @@ -58,13 +59,15 @@ derive newtype instance ordEventType :: Ord EventType foreign import data EventTarget :: Type readEventTarget :: Foreign -> F EventTarget -readEventTarget = _readEventTarget Left Right +readEventTarget = + wrap <<< wrap <<< lmap (pure <<< ForeignError) <<< + _readEventTarget Left Right foreign import _readEventTarget :: (forall a b. a -> Either a b) -> (forall a b. b -> Either a b) -> Foreign - -> F EventTarget + -> Either String EventTarget foreign import data CustomEvent :: Type From 2f5ddeb5d406dbcefeea4899b6b1fe3cb34bac7f Mon Sep 17 00:00:00 2001 From: rightfold Date: Wed, 7 Jun 2017 17:47:59 +0200 Subject: [PATCH 2/2] Make _readEventTarget actually work --- src/DOM/Event/Types.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DOM/Event/Types.js b/src/DOM/Event/Types.js index 2a3a450..0a19b6e 100644 --- a/src/DOM/Event/Types.js +++ b/src/DOM/Event/Types.js @@ -4,7 +4,7 @@ exports._readEventTarget = function (left) { return function (right) { return function (foreign) { - return foreign instanceof EventTarget ? left("Value is not an EventTarget") : right(foreign); + return foreign instanceof EventTarget ? right(foreign) : left("Value is not an EventTarget"); }; }; };