Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #104 from rightfold/_readEventTarget
Browse files Browse the repository at this point in the history
Return value of the correct constructor from _readEventTarget
  • Loading branch information
garyb authored Jun 8, 2017
2 parents fd260ed + 2f5ddeb commit 32a8e55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/DOM/Event/Types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
};
};
11 changes: 7 additions & 4 deletions src/DOM/Event/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit 32a8e55

Please sign in to comment.