diff --git a/src/DOM/CSS/Event/Types.purs b/src/DOM/CSS/Event/Types.purs new file mode 100644 index 0000000..317e59d --- /dev/null +++ b/src/DOM/CSS/Event/Types.purs @@ -0,0 +1,21 @@ +module DOM.CSS.Event.Types + ( TransitionEvent + , transitionEventToEvent + , readTransitionEvent + ) where + +import Data.Foreign (Foreign, F, unsafeReadTagged) +import Data.Foreign.Class (class IsForeign) +import DOM.Event.Types (Event) +import Unsafe.Coerce as U + +foreign import data TransitionEvent :: * + +transitionEventToEvent :: TransitionEvent -> Event +transitionEventToEvent = U.unsafeCoerce + +readTransitionEvent :: Foreign -> F TransitionEvent +readTransitionEvent = unsafeReadTagged "TransitionEvent" + +instance isForeignTransitionEvent :: IsForeign TransitionEvent where + read = readTransitionEvent diff --git a/src/DOM/Event/Event.purs b/src/DOM/Event/Event.purs index 4e3dca4..710db94 100644 --- a/src/DOM/Event/Event.purs +++ b/src/DOM/Event/Event.purs @@ -1,16 +1,6 @@ module DOM.Event.Event - ( bubbles - , cancelable - , currentTarget - , defaultPrevented - , eventPhase - , eventPhaseIndex - , target - , timeStamp - , type_ - , preventDefault - , stopImmediatePropagation - , stopPropagation + ( module DOM.Event.Event + , module T ) where import Prelude @@ -20,6 +10,7 @@ import Data.Maybe (fromJust) import DOM (DOM) import DOM.Event.EventPhase (EventPhase) import DOM.Event.Types (Event, EventType) +import DOM.Event.Types (Event) as T import DOM.Node.Types (Node) -- | The event type. @@ -41,11 +32,17 @@ foreign import eventPhaseIndex :: Event -> Int -- | Prevents the event from bubbling up to futher event listeners. Other event -- | listeners on the current target will still fire. -foreign import stopPropagation :: forall eff. Event -> Eff (dom :: DOM | eff) Unit +foreign import stopPropagation + :: forall eff + . Event + -> Eff (dom :: DOM | eff) Unit -- | Prevents all other listeners for the event from being called. This includes -- | event listeners added to the current target after the current listener. -foreign import stopImmediatePropagation :: forall eff. Event -> Eff (dom :: DOM | eff) Unit +foreign import stopImmediatePropagation + :: forall eff + . Event + -> Eff (dom :: DOM | eff) Unit -- | Indicates whether the event will bubble up through the DOM or not. foreign import bubbles :: Event -> Boolean @@ -54,7 +51,10 @@ foreign import bubbles :: Event -> Boolean foreign import cancelable :: Event -> Boolean -- | Cancels the event if it can be cancelled. -foreign import preventDefault :: forall eff. Event -> Eff (dom :: DOM | eff) Unit +foreign import preventDefault + :: forall eff + . Event + -> Eff (dom :: DOM | eff) Unit -- | Indicates whether `preventDefault` was called on the event. foreign import defaultPrevented :: Event -> Boolean diff --git a/src/DOM/Event/EventPhase.purs b/src/DOM/Event/EventPhase.purs index a3b2f43..3f79292 100644 --- a/src/DOM/Event/EventPhase.purs +++ b/src/DOM/Event/EventPhase.purs @@ -1,4 +1,4 @@ -module DOM.Event.EventPhase (EventPhase(..)) where +module DOM.Event.EventPhase where import Prelude import Data.Enum (class Enum, class BoundedEnum, Cardinality(..), defaultSucc, defaultPred) @@ -11,9 +11,7 @@ data EventPhase | Bubbling derive instance eqEventPhase :: Eq EventPhase - -instance ordEventPhase :: Ord EventPhase where - compare x y = compare (fromEnumEventPhase x) (fromEnumEventPhase y) +derive instance ordEventPhase :: Ord EventPhase instance boundedEventPhase :: Bounded EventPhase where bottom = None @@ -29,14 +27,18 @@ instance boundedEnumEventPhase :: BoundedEnum EventPhase where fromEnum = fromEnumEventPhase toEnumEventPhase :: Int -> Maybe EventPhase -toEnumEventPhase 0 = Just None -toEnumEventPhase 1 = Just Capturing -toEnumEventPhase 2 = Just AtTarget -toEnumEventPhase 3 = Just Bubbling -toEnumEventPhase _ = Nothing +toEnumEventPhase = + case _ of + 0 -> Just None + 1 -> Just Capturing + 2 -> Just AtTarget + 3 -> Just Bubbling + _ -> Nothing fromEnumEventPhase :: EventPhase -> Int -fromEnumEventPhase None = 0 -fromEnumEventPhase Capturing = 1 -fromEnumEventPhase AtTarget = 2 -fromEnumEventPhase Bubbling = 3 +fromEnumEventPhase = + case _ of + None -> 0 + Capturing -> 1 + AtTarget -> 2 + Bubbling -> 3 diff --git a/src/DOM/Event/EventTarget.purs b/src/DOM/Event/EventTarget.purs index 8859759..db1dea1 100644 --- a/src/DOM/Event/EventTarget.purs +++ b/src/DOM/Event/EventTarget.purs @@ -11,15 +11,34 @@ import DOM.Event.Types (EventTarget, Event, EventType) foreign import data EventListener :: # ! -> * -- | Creates an EventListener from a normal PureScript Eff function. -foreign import eventListener :: forall eff a. (Event -> Eff eff a) -> EventListener eff +foreign import eventListener + :: forall eff a + . (Event -> Eff eff a) + -> EventListener eff -- | Adds a listener to an event target. The boolean argument indicates whether -- | the listener should be added for the "capture" phase. -foreign import addEventListener :: forall eff. EventType -> EventListener (dom :: DOM | eff) -> Boolean -> EventTarget -> Eff (dom :: DOM | eff) Unit +foreign import addEventListener + :: forall eff + . EventType + -> EventListener (dom :: DOM | eff) + -> Boolean + -> EventTarget + -> Eff (dom :: DOM | eff) Unit -- | Removes a listener to an event target. The boolean argument indicates -- | whether the listener should be removed for the "capture" phase. -foreign import removeEventListener :: forall eff. EventType -> EventListener (dom :: DOM | eff) -> Boolean -> EventTarget -> Eff (dom :: DOM | eff) Unit +foreign import removeEventListener + :: forall eff + . EventType + -> EventListener (dom :: DOM | eff) + -> Boolean + -> EventTarget + -> Eff (dom :: DOM | eff) Unit -- | Dispatches an event from an event target. -foreign import dispatchEvent :: forall eff. Event -> EventTarget -> Eff (dom :: DOM, err :: EXCEPTION | eff) Boolean +foreign import dispatchEvent + :: forall eff + . Event + -> EventTarget + -> Eff (dom :: DOM, err :: EXCEPTION | eff) Boolean diff --git a/src/DOM/Event/Types.js b/src/DOM/Event/Types.js index 519ce73..2a3a450 100644 --- a/src/DOM/Event/Types.js +++ b/src/DOM/Event/Types.js @@ -4,9 +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 ? left("Value is not an EventTarget") : right(foreign); }; }; }; diff --git a/src/DOM/Event/Types.purs b/src/DOM/Event/Types.purs index 3f1a471..24ddf39 100644 --- a/src/DOM/Event/Types.purs +++ b/src/DOM/Event/Types.purs @@ -3,158 +3,41 @@ module DOM.Event.Types , EventType(..) , EventTarget , readEventTarget - , AnimationEvent - , animationEventToEvent - , readAnimationEvent - , AudioProcessingEvent - , audioProcessingEventToEvent - , readAudioProcessingEvent - , BeforeInputEvent - , beforeInputEventToEvent - , readBeforeInputEvent - , BeforeUnloadEvent - , beforeUnloadEventToEvent - , readBeforeUnloadEvent - , BlobEvent - , blobEventToEvent - , readBlobEvent - , ClipboardEvent - , clipboardEventToEvent - , readClipboardEvent - , CloseEvent - , closeEventToEvent - , readCloseEvent - , CompositionEvent - , compositionEventToEvent - , readCompositionEvent - , CSSFontFaceLoadEvent - , cssFontFaceLoadEventToEvent - , readCSSFontFaceLoadEvent , CustomEvent , customEventToEvent , readCustomEvent - , DeviceLightEvent - , deviceLightEventToEvent - , readDeviceLightEvent - , DeviceMotionEvent - , deviceMotionEventToEvent - , readDeviceMotionEvent - , DeviceOrientationEvent - , deviceOrientationEventToEvent - , readDeviceOrientationEvent - , DeviceProximityEvent - , deviceProximityEventToEvent - , readDeviceProximityEvent - , DOMTransactionEvent - , domTransactionEventToEvent - , readDOMTransactionEvent - , DragEvent - , dragEventToEvent - , readDragEvent - , EditingBeforeInputEvent - , editingBeforeInputEventToEvent - , readEditingBeforeInputEvent - , ErrorEvent - , errorEventToEvent - , readErrorEvent - , FetchEvent - , fetchEventToEvent - , readFetchEvent + , UIEvent + , uiEventToEvent + , readUIEvent , FocusEvent , focusEventToEvent , readFocusEvent - , GamepadEvent - , gamepadEventToEvent - , readGamepadEvent - , HashChangeEvent - , hashChangeEventToEvent - , readHashChangeEvent - , IDBVersionChangeEvent - , idbVersionChangeEventToEvent - , readIDBVersionChangeEvent + , MouseEvent + , mouseEventToEvent + , readMouseEvent + , WheelEvent + , wheelEventToEvent + , readWheelEvent + , TouchEvent + , touchEventToEvent + , readTouchEvent , InputEvent , inputEventToEvent , readInputEvent , KeyboardEvent , keyboardEventToEvent , readKeyboardEvent - , MediaStreamEvent - , mediaStreamEventToEvent - , readMediaStreamEvent - , MessageEvent - , messageEventToEvent - , readMessageEvent - , MouseEvent - , mouseEventToEvent - , readMouseEvent - , MutationEvent - , mutationEventToEvent - , readMutationEvent - , OfflineAudioCompletionEvent - , offlineAudioCompletionEventToEvent - , readOfflineAudioCompletionEvent - , PageTransitionEvent - , pageTransitionEventToEvent - , readPageTransitionEvent - , PointerEvent - , pointerEventToEvent - , readPointerEvent - , PopStateEvent - , popStateEventToEvent - , readPopStateEvent + , CompositionEvent + , compositionEventToEvent + , readCompositionEvent , ProgressEvent , progressEventToEvent , readProgressEvent - , RelatedEvent - , relatedEventToEvent - , readRelatedEvent - , RTCDataChannelEvent - , rtcDataChannelEventToEvent - , readRTCDataChannelEvent - , RTCIdentityErrorEvent - , rtcIdentityErrorEventToEvent - , readRTCIdentityErrorEvent - , RTCIdentityEvent - , rtcIdentityEventToEvent - , readRTCIdentityEvent - , RTCPeerConnectionIceEvent - , rtcPeerConnectionIceEventToEvent - , readRTCPeerConnectionIceEvent - , SensorEvent - , sensorEventToEvent - , readSensorEvent - , StorageEvent - , storageEventToEvent - , readStorageEvent - , SVGEvent - , svgEventToEvent - , readSVGEvent - , SVGZoomEvent - , svgZoomEventToEvent - , readSVGZoomEvent - , TimeEvent - , timeEventToEvent - , readTimeEvent - , TouchEvent - , touchEventToEvent - , readTouchEvent - , TransitionEvent - , transitionEventToEvent - , readTransitionEvent - , UIEvent - , uiEventToEvent - , readUIEvent - , UserProximityEvent - , userProximityEventToEvent - , readUserProximityEvent - , WheelEvent - , wheelEventToEvent - , readWheelEvent ) where import Prelude import Data.Either (Either(..)) -import Data.Foreign (Foreign, F, unsafeReadTagged) +import Data.Foreign (F, Foreign, unsafeReadTagged) import Data.Foreign.Class (class IsForeign) import Unsafe.Coerce as U @@ -165,7 +48,6 @@ foreign import data Event :: * newtype EventType = EventType String derive instance eqEventType :: Eq EventType - derive instance ordEventType :: Ord EventType -- | A DOM item that can emit events. @@ -174,121 +56,19 @@ foreign import data EventTarget :: * readEventTarget :: Foreign -> F EventTarget readEventTarget = _readEventTarget Left Right -foreign import _readEventTarget :: - (forall a b. a -> Either a b) -> - (forall a b. b -> Either a b) -> - Foreign -> - F EventTarget +foreign import _readEventTarget + :: (forall a b. a -> Either a b) + -> (forall a b. b -> Either a b) + -> Foreign + -> F EventTarget instance isForeignEventTarget :: IsForeign EventTarget where read = readEventTarget -unsafeToEvent :: forall e. e -> Event -unsafeToEvent = U.unsafeCoerce - -foreign import data AnimationEvent :: * - -animationEventToEvent :: AnimationEvent -> Event -animationEventToEvent = unsafeToEvent - -readAnimationEvent :: Foreign -> F AnimationEvent -readAnimationEvent = unsafeReadTagged "AnimationEvent" - -instance isForeignAnimationEvent :: IsForeign AnimationEvent where - read = readAnimationEvent - -foreign import data AudioProcessingEvent :: * - -audioProcessingEventToEvent :: AudioProcessingEvent -> Event -audioProcessingEventToEvent = unsafeToEvent - -readAudioProcessingEvent :: Foreign -> F AudioProcessingEvent -readAudioProcessingEvent = unsafeReadTagged "AudioProcessingEvent" - -instance isForeignAudioProcessingEvent :: IsForeign AudioProcessingEvent where - read = readAudioProcessingEvent - -foreign import data BeforeInputEvent :: * - -beforeInputEventToEvent :: BeforeInputEvent -> Event -beforeInputEventToEvent = unsafeToEvent - -readBeforeInputEvent :: Foreign -> F BeforeInputEvent -readBeforeInputEvent = unsafeReadTagged "BeforeInputEvent" - -instance isForeignBeforeInputEvent :: IsForeign BeforeInputEvent where - read = readBeforeInputEvent - -foreign import data BeforeUnloadEvent :: * - -beforeUnloadEventToEvent :: BeforeUnloadEvent -> Event -beforeUnloadEventToEvent = unsafeToEvent - -readBeforeUnloadEvent :: Foreign -> F BeforeUnloadEvent -readBeforeUnloadEvent = unsafeReadTagged "BeforeUnloadEvent" - -instance isForeignBeforeUnloadEvent :: IsForeign BeforeUnloadEvent where - read = readBeforeUnloadEvent - -foreign import data BlobEvent :: * - -blobEventToEvent :: BlobEvent -> Event -blobEventToEvent = unsafeToEvent - -readBlobEvent :: Foreign -> F BlobEvent -readBlobEvent = unsafeReadTagged "BlobEvent" - -instance isForeignBlobEvent :: IsForeign BlobEvent where - read = readBlobEvent - -foreign import data ClipboardEvent :: * - -clipboardEventToEvent :: ClipboardEvent -> Event -clipboardEventToEvent = unsafeToEvent - -readClipboardEvent :: Foreign -> F ClipboardEvent -readClipboardEvent = unsafeReadTagged "ClipboardEvent" - -instance isForeignClipboardEvent :: IsForeign ClipboardEvent where - read = readClipboardEvent - -foreign import data CloseEvent :: * - -closeEventToEvent :: CloseEvent -> Event -closeEventToEvent = unsafeToEvent - -readCloseEvent :: Foreign -> F CloseEvent -readCloseEvent = unsafeReadTagged "CloseEvent" - -instance isForeignCloseEvent :: IsForeign CloseEvent where - read = readCloseEvent - -foreign import data CompositionEvent :: * - -compositionEventToEvent :: CompositionEvent -> Event -compositionEventToEvent = unsafeToEvent - -readCompositionEvent :: Foreign -> F CompositionEvent -readCompositionEvent = unsafeReadTagged "CompositionEvent" - -instance isForeignCompositionEvent :: IsForeign CompositionEvent where - read = readCompositionEvent - -foreign import data CSSFontFaceLoadEvent :: * - -cssFontFaceLoadEventToEvent :: CSSFontFaceLoadEvent -> Event -cssFontFaceLoadEventToEvent = unsafeToEvent - -readCSSFontFaceLoadEvent :: Foreign -> F CSSFontFaceLoadEvent -readCSSFontFaceLoadEvent = unsafeReadTagged "CSSFontFaceLoadEvent" - -instance isForeignCSSFontFaceLoadEvent :: IsForeign CSSFontFaceLoadEvent where - read = readCSSFontFaceLoadEvent - foreign import data CustomEvent :: * customEventToEvent :: CustomEvent -> Event -customEventToEvent = unsafeToEvent +customEventToEvent = U.unsafeCoerce readCustomEvent :: Foreign -> F CustomEvent readCustomEvent = unsafeReadTagged "CustomEvent" @@ -296,109 +76,21 @@ readCustomEvent = unsafeReadTagged "CustomEvent" instance isForeignCustomEvent :: IsForeign CustomEvent where read = readCustomEvent -foreign import data DeviceLightEvent :: * - -deviceLightEventToEvent :: DeviceLightEvent -> Event -deviceLightEventToEvent = unsafeToEvent - -readDeviceLightEvent :: Foreign -> F DeviceLightEvent -readDeviceLightEvent = unsafeReadTagged "DeviceLightEvent" - -instance isForeignDeviceLightEvent :: IsForeign DeviceLightEvent where - read = readDeviceLightEvent - -foreign import data DeviceMotionEvent :: * - -deviceMotionEventToEvent :: DeviceMotionEvent -> Event -deviceMotionEventToEvent = unsafeToEvent - -readDeviceMotionEvent :: Foreign -> F DeviceMotionEvent -readDeviceMotionEvent = unsafeReadTagged "DeviceMotionEvent" - -instance isForeignDeviceMotionEvent :: IsForeign DeviceMotionEvent where - read = readDeviceMotionEvent - -foreign import data DeviceOrientationEvent :: * - -deviceOrientationEventToEvent :: DeviceOrientationEvent -> Event -deviceOrientationEventToEvent = unsafeToEvent - -readDeviceOrientationEvent :: Foreign -> F DeviceOrientationEvent -readDeviceOrientationEvent = unsafeReadTagged "DeviceOrientationEvent" - -instance isForeignDeviceOrientationEvent :: IsForeign DeviceOrientationEvent where - read = readDeviceOrientationEvent - -foreign import data DeviceProximityEvent :: * - -deviceProximityEventToEvent :: DeviceProximityEvent -> Event -deviceProximityEventToEvent = unsafeToEvent - -readDeviceProximityEvent :: Foreign -> F DeviceProximityEvent -readDeviceProximityEvent = unsafeReadTagged "DeviceProximityEvent" - -instance isForeignDeviceProximityEvent :: IsForeign DeviceProximityEvent where - read = readDeviceProximityEvent - -foreign import data DOMTransactionEvent :: * - -domTransactionEventToEvent :: DOMTransactionEvent -> Event -domTransactionEventToEvent = unsafeToEvent - -readDOMTransactionEvent :: Foreign -> F DOMTransactionEvent -readDOMTransactionEvent = unsafeReadTagged "DOMTransactionEvent" - -instance isForeignDOMTransactionEvent :: IsForeign DOMTransactionEvent where - read = readDOMTransactionEvent - -foreign import data DragEvent :: * - -dragEventToEvent :: DragEvent -> Event -dragEventToEvent = unsafeToEvent - -readDragEvent :: Foreign -> F DragEvent -readDragEvent = unsafeReadTagged "DragEvent" - -instance isForeignDragEvent :: IsForeign DragEvent where - read = readDragEvent - -foreign import data EditingBeforeInputEvent :: * - -editingBeforeInputEventToEvent :: EditingBeforeInputEvent -> Event -editingBeforeInputEventToEvent = unsafeToEvent - -readEditingBeforeInputEvent :: Foreign -> F EditingBeforeInputEvent -readEditingBeforeInputEvent = unsafeReadTagged "EditingBeforeInputEvent" - -instance isForeignEditingBeforeInputEvent :: IsForeign EditingBeforeInputEvent where - read = readEditingBeforeInputEvent - -foreign import data ErrorEvent :: * - -errorEventToEvent :: ErrorEvent -> Event -errorEventToEvent = unsafeToEvent - -readErrorEvent :: Foreign -> F ErrorEvent -readErrorEvent = unsafeReadTagged "ErrorEvent" - -instance isForeignErrorEvent :: IsForeign ErrorEvent where - read = readErrorEvent - -foreign import data FetchEvent :: * +foreign import data UIEvent :: * -fetchEventToEvent :: FetchEvent -> Event -fetchEventToEvent = unsafeToEvent +uiEventToEvent :: UIEvent -> Event +uiEventToEvent = U.unsafeCoerce -readFetchEvent :: Foreign -> F FetchEvent -readFetchEvent = unsafeReadTagged "FetchEvent" +readUIEvent :: Foreign -> F UIEvent +readUIEvent = unsafeReadTagged "UIEvent" -instance isForeignFetchEvent :: IsForeign FetchEvent where - read = readFetchEvent +instance isForeignUIEvent :: IsForeign UIEvent where + read = readUIEvent foreign import data FocusEvent :: * focusEventToEvent :: FocusEvent -> Event -focusEventToEvent = unsafeToEvent +focusEventToEvent = U.unsafeCoerce readFocusEvent :: Foreign -> F FocusEvent readFocusEvent = unsafeReadTagged "FocusEvent" @@ -406,43 +98,43 @@ readFocusEvent = unsafeReadTagged "FocusEvent" instance isForeignFocusEvent :: IsForeign FocusEvent where read = readFocusEvent -foreign import data GamepadEvent :: * +foreign import data MouseEvent :: * -gamepadEventToEvent :: GamepadEvent -> Event -gamepadEventToEvent = unsafeToEvent +mouseEventToEvent :: MouseEvent -> Event +mouseEventToEvent = U.unsafeCoerce -readGamepadEvent :: Foreign -> F GamepadEvent -readGamepadEvent = unsafeReadTagged "GamepadEvent" +readMouseEvent :: Foreign -> F MouseEvent +readMouseEvent = unsafeReadTagged "MouseEvent" -instance isForeignGamepadEvent :: IsForeign GamepadEvent where - read = readGamepadEvent +instance isForeignMouseEvent :: IsForeign MouseEvent where + read = readMouseEvent -foreign import data HashChangeEvent :: * +foreign import data WheelEvent :: * -hashChangeEventToEvent :: HashChangeEvent -> Event -hashChangeEventToEvent = unsafeToEvent +wheelEventToEvent :: WheelEvent -> Event +wheelEventToEvent = U.unsafeCoerce -readHashChangeEvent :: Foreign -> F HashChangeEvent -readHashChangeEvent = unsafeReadTagged "HashChangeEvent" +readWheelEvent :: Foreign -> F WheelEvent +readWheelEvent = unsafeReadTagged "WheelEvent" -instance isForeignHashChangeEvent :: IsForeign HashChangeEvent where - read = readHashChangeEvent +instance isForeignWheelEvent :: IsForeign WheelEvent where + read = readWheelEvent -foreign import data IDBVersionChangeEvent :: * +foreign import data TouchEvent :: * -idbVersionChangeEventToEvent :: IDBVersionChangeEvent -> Event -idbVersionChangeEventToEvent = unsafeToEvent +touchEventToEvent :: TouchEvent -> Event +touchEventToEvent = U.unsafeCoerce -readIDBVersionChangeEvent :: Foreign -> F IDBVersionChangeEvent -readIDBVersionChangeEvent = unsafeReadTagged "IDBVersionChangeEvent" +readTouchEvent :: Foreign -> F TouchEvent +readTouchEvent = unsafeReadTagged "TouchEvent" -instance isForeignIDBVersionChangeEvent :: IsForeign IDBVersionChangeEvent where - read = readIDBVersionChangeEvent +instance isForeignTouchEvent :: IsForeign TouchEvent where + read = readTouchEvent foreign import data InputEvent :: * inputEventToEvent :: InputEvent -> Event -inputEventToEvent = unsafeToEvent +inputEventToEvent = U.unsafeCoerce readInputEvent :: Foreign -> F InputEvent readInputEvent = unsafeReadTagged "InputEvent" @@ -453,7 +145,7 @@ instance isForeignInputEvent :: IsForeign InputEvent where foreign import data KeyboardEvent :: * keyboardEventToEvent :: KeyboardEvent -> Event -keyboardEventToEvent = unsafeToEvent +keyboardEventToEvent = U.unsafeCoerce readKeyboardEvent :: Foreign -> F KeyboardEvent readKeyboardEvent = unsafeReadTagged "KeyboardEvent" @@ -461,266 +153,24 @@ readKeyboardEvent = unsafeReadTagged "KeyboardEvent" instance isForeignKeyboardEvent :: IsForeign KeyboardEvent where read = readKeyboardEvent -foreign import data MediaStreamEvent :: * - -mediaStreamEventToEvent :: MediaStreamEvent -> Event -mediaStreamEventToEvent = unsafeToEvent - -readMediaStreamEvent :: Foreign -> F MediaStreamEvent -readMediaStreamEvent = unsafeReadTagged "MediaStreamEvent" - -instance isForeignMediaStreamEvent :: IsForeign MediaStreamEvent where - read = readMediaStreamEvent - -foreign import data MessageEvent :: * - -messageEventToEvent :: MessageEvent -> Event -messageEventToEvent = unsafeToEvent - -readMessageEvent :: Foreign -> F MessageEvent -readMessageEvent = unsafeReadTagged "MessageEvent" - -instance isForeignMessageEvent :: IsForeign MessageEvent where - read = readMessageEvent - -foreign import data MouseEvent :: * - -mouseEventToEvent :: MouseEvent -> Event -mouseEventToEvent = unsafeToEvent - -readMouseEvent :: Foreign -> F MouseEvent -readMouseEvent = unsafeReadTagged "MouseEvent" - -instance isForeignMouseEvent :: IsForeign MouseEvent where - read = readMouseEvent - -foreign import data MutationEvent :: * - -mutationEventToEvent :: MutationEvent -> Event -mutationEventToEvent = unsafeToEvent - -readMutationEvent :: Foreign -> F MutationEvent -readMutationEvent = unsafeReadTagged "MutationEvent" - -instance isForeignMutationEvent :: IsForeign MutationEvent where - read = readMutationEvent - -foreign import data OfflineAudioCompletionEvent :: * - -offlineAudioCompletionEventToEvent :: OfflineAudioCompletionEvent -> Event -offlineAudioCompletionEventToEvent = unsafeToEvent - -readOfflineAudioCompletionEvent :: Foreign -> F OfflineAudioCompletionEvent -readOfflineAudioCompletionEvent = unsafeReadTagged "OfflineAudioCompletionEvent" - -instance isForeignOfflineAudioCompletionEvent :: IsForeign OfflineAudioCompletionEvent where - read = readOfflineAudioCompletionEvent - -foreign import data PageTransitionEvent :: * - -pageTransitionEventToEvent :: PageTransitionEvent -> Event -pageTransitionEventToEvent = unsafeToEvent - -readPageTransitionEvent :: Foreign -> F PageTransitionEvent -readPageTransitionEvent = unsafeReadTagged "PageTransitionEvent" - -instance isForeignPageTransitionEvent :: IsForeign PageTransitionEvent where - read = readPageTransitionEvent - -foreign import data PointerEvent :: * - -pointerEventToEvent :: PointerEvent -> Event -pointerEventToEvent = unsafeToEvent - -readPointerEvent :: Foreign -> F PointerEvent -readPointerEvent = unsafeReadTagged "PointerEvent" - -instance isForeignPointerEvent :: IsForeign PointerEvent where - read = readPointerEvent - -foreign import data PopStateEvent :: * +foreign import data CompositionEvent :: * -popStateEventToEvent :: PopStateEvent -> Event -popStateEventToEvent = unsafeToEvent +compositionEventToEvent :: CompositionEvent -> Event +compositionEventToEvent = U.unsafeCoerce -readPopStateEvent :: Foreign -> F PopStateEvent -readPopStateEvent = unsafeReadTagged "PopStateEvent" +readCompositionEvent :: Foreign -> F CompositionEvent +readCompositionEvent = unsafeReadTagged "CompositionEvent" -instance isForeignPopStateEvent :: IsForeign PopStateEvent where - read = readPopStateEvent +instance isForeignCompositionEvent :: IsForeign CompositionEvent where + read = readCompositionEvent foreign import data ProgressEvent :: * progressEventToEvent :: ProgressEvent -> Event -progressEventToEvent = unsafeToEvent +progressEventToEvent = U.unsafeCoerce readProgressEvent :: Foreign -> F ProgressEvent readProgressEvent = unsafeReadTagged "ProgressEvent" instance isForeignProgressEvent :: IsForeign ProgressEvent where read = readProgressEvent - -foreign import data RelatedEvent :: * - -relatedEventToEvent :: RelatedEvent -> Event -relatedEventToEvent = unsafeToEvent - -readRelatedEvent :: Foreign -> F RelatedEvent -readRelatedEvent = unsafeReadTagged "RelatedEvent" - -instance isForeignRelatedEvent :: IsForeign RelatedEvent where - read = readRelatedEvent - -foreign import data RTCDataChannelEvent :: * - -rtcDataChannelEventToEvent :: RTCDataChannelEvent -> Event -rtcDataChannelEventToEvent = unsafeToEvent - -readRTCDataChannelEvent :: Foreign -> F RTCDataChannelEvent -readRTCDataChannelEvent = unsafeReadTagged "RTCDataChannelEvent" - -instance isForeignRTCDataChannelEvent :: IsForeign RTCDataChannelEvent where - read = readRTCDataChannelEvent - -foreign import data RTCIdentityErrorEvent :: * - -rtcIdentityErrorEventToEvent :: RTCIdentityErrorEvent -> Event -rtcIdentityErrorEventToEvent = unsafeToEvent - -readRTCIdentityErrorEvent :: Foreign -> F RTCIdentityErrorEvent -readRTCIdentityErrorEvent = unsafeReadTagged "RTCIdentityErrorEvent" - -instance isForeignRTCIdentityErrorEvent :: IsForeign RTCIdentityErrorEvent where - read = readRTCIdentityErrorEvent - -foreign import data RTCIdentityEvent :: * - -rtcIdentityEventToEvent :: RTCIdentityEvent -> Event -rtcIdentityEventToEvent = unsafeToEvent - -readRTCIdentityEvent :: Foreign -> F RTCIdentityEvent -readRTCIdentityEvent = unsafeReadTagged "RTCIdentityEvent" - -instance isForeignRTCIdentityEvent :: IsForeign RTCIdentityEvent where - read = readRTCIdentityEvent - -foreign import data RTCPeerConnectionIceEvent :: * - -rtcPeerConnectionIceEventToEvent :: RTCPeerConnectionIceEvent -> Event -rtcPeerConnectionIceEventToEvent = unsafeToEvent - -readRTCPeerConnectionIceEvent :: Foreign -> F RTCPeerConnectionIceEvent -readRTCPeerConnectionIceEvent = unsafeReadTagged "RTCPeerConnectionIceEvent" - -instance isForeignRTCPeerConnectionIceEvent :: IsForeign RTCPeerConnectionIceEvent where - read = readRTCPeerConnectionIceEvent - -foreign import data SensorEvent :: * - -sensorEventToEvent :: SensorEvent -> Event -sensorEventToEvent = unsafeToEvent - -readSensorEvent :: Foreign -> F SensorEvent -readSensorEvent = unsafeReadTagged "SensorEvent" - -instance isForeignSensorEvent :: IsForeign SensorEvent where - read = readSensorEvent - -foreign import data StorageEvent :: * - -storageEventToEvent :: StorageEvent -> Event -storageEventToEvent = unsafeToEvent - -readStorageEvent :: Foreign -> F StorageEvent -readStorageEvent = unsafeReadTagged "StorageEvent" - -instance isForeignStorageEvent :: IsForeign StorageEvent where - read = readStorageEvent - -foreign import data SVGEvent :: * - -svgEventToEvent :: SVGEvent -> Event -svgEventToEvent = unsafeToEvent - -readSVGEvent :: Foreign -> F SVGEvent -readSVGEvent = unsafeReadTagged "SVGEvent" - -instance isForeignSVGEvent :: IsForeign SVGEvent where - read = readSVGEvent - -foreign import data SVGZoomEvent :: * - -svgZoomEventToEvent :: SVGZoomEvent -> Event -svgZoomEventToEvent = unsafeToEvent - -readSVGZoomEvent :: Foreign -> F SVGZoomEvent -readSVGZoomEvent = unsafeReadTagged "SVGZoomEvent" - -instance isForeignSVGZoomEvent :: IsForeign SVGZoomEvent where - read = readSVGZoomEvent - -foreign import data TimeEvent :: * - -timeEventToEvent :: TimeEvent -> Event -timeEventToEvent = unsafeToEvent - -readTimeEvent :: Foreign -> F TimeEvent -readTimeEvent = unsafeReadTagged "TimeEvent" - -instance isForeignTimeEvent :: IsForeign TimeEvent where - read = readTimeEvent - -foreign import data TouchEvent :: * - -touchEventToEvent :: TouchEvent -> Event -touchEventToEvent = unsafeToEvent - -readTouchEvent :: Foreign -> F TouchEvent -readTouchEvent = unsafeReadTagged "TouchEvent" - -instance isForeignTouchEvent :: IsForeign TouchEvent where - read = readTouchEvent - -foreign import data TransitionEvent :: * - -transitionEventToEvent :: TransitionEvent -> Event -transitionEventToEvent = unsafeToEvent - -readTransitionEvent :: Foreign -> F TransitionEvent -readTransitionEvent = unsafeReadTagged "TransitionEvent" - -instance isForeignTransitionEvent :: IsForeign TransitionEvent where - read = readTransitionEvent - -foreign import data UIEvent :: * - -uiEventToEvent :: UIEvent -> Event -uiEventToEvent = unsafeToEvent - -readUIEvent :: Foreign -> F UIEvent -readUIEvent = unsafeReadTagged "UIEvent" - -instance isForeignUIEvent :: IsForeign UIEvent where - read = readUIEvent - -foreign import data UserProximityEvent :: * - -userProximityEventToEvent :: UserProximityEvent -> Event -userProximityEventToEvent = unsafeToEvent - -readUserProximityEvent :: Foreign -> F UserProximityEvent -readUserProximityEvent = unsafeReadTagged "UserProximityEvent" - -instance isForeignUserProximityEvent :: IsForeign UserProximityEvent where - read = readUserProximityEvent - -foreign import data WheelEvent :: * - -wheelEventToEvent :: WheelEvent -> Event -wheelEventToEvent = unsafeToEvent - -readWheelEvent :: Foreign -> F WheelEvent -readWheelEvent = unsafeReadTagged "WheelEvent" - -instance isForeignWheelEvent :: IsForeign WheelEvent where - read = readWheelEvent diff --git a/src/DOM/File/File.purs b/src/DOM/File/File.purs index 147fb93..29757da 100644 --- a/src/DOM/File/File.purs +++ b/src/DOM/File/File.purs @@ -1,6 +1,4 @@ -module DOM.File.File - ( name - ) where +module DOM.File.File where import Prelude import DOM.File.Blob as Blob diff --git a/src/DOM/File/FileList.purs b/src/DOM/File/FileList.purs index 3c53c6e..fba3aac 100644 --- a/src/DOM/File/FileList.purs +++ b/src/DOM/File/FileList.purs @@ -1,7 +1,4 @@ -module DOM.File.FileList - ( item - , length - ) where +module DOM.File.FileList where import Data.Nullable (Nullable) import DOM.File.Types (FileList, File) diff --git a/src/DOM/Event/DragEvent/DataTransfer.js b/src/DOM/HTML/Event/DragEvent/DataTransfer.js similarity index 100% rename from src/DOM/Event/DragEvent/DataTransfer.js rename to src/DOM/HTML/Event/DragEvent/DataTransfer.js diff --git a/src/DOM/Event/DragEvent/DataTransfer.purs b/src/DOM/HTML/Event/DragEvent/DataTransfer.purs similarity index 83% rename from src/DOM/Event/DragEvent/DataTransfer.purs rename to src/DOM/HTML/Event/DragEvent/DataTransfer.purs index da6802c..033330e 100644 --- a/src/DOM/Event/DragEvent/DataTransfer.purs +++ b/src/DOM/HTML/Event/DragEvent/DataTransfer.purs @@ -1,4 +1,4 @@ -module DOM.Event.DragEvent.DataTransfer where +module DOM.HTML.Event.DragEvent.DataTransfer where import DOM.File.Types (FileList) diff --git a/src/DOM/Event/ErrorEvent.js b/src/DOM/HTML/Event/ErrorEvent.js similarity index 71% rename from src/DOM/Event/ErrorEvent.js rename to src/DOM/HTML/Event/ErrorEvent.js index 88338c8..d5bfcba 100644 --- a/src/DOM/Event/ErrorEvent.js +++ b/src/DOM/HTML/Event/ErrorEvent.js @@ -3,17 +3,17 @@ // module DOM.Event.ErrorEvent exports.message = function (e) { - e.message; + return e.message; }; exports.fileName = function (e) { - e.filename; + return e.filename; }; exports.lineNo = function (e) { - e.lineno; + return e.lineno; }; exports.colNo = function (e) { - e.colno; + return e.colno; }; diff --git a/src/DOM/Event/ErrorEvent.purs b/src/DOM/HTML/Event/ErrorEvent.purs similarity index 60% rename from src/DOM/Event/ErrorEvent.purs rename to src/DOM/HTML/Event/ErrorEvent.purs index 1c8c821..5d97a04 100644 --- a/src/DOM/Event/ErrorEvent.purs +++ b/src/DOM/HTML/Event/ErrorEvent.purs @@ -1,11 +1,6 @@ -module DOM.Event.ErrorEvent - ( message - , fileName - , lineNo - , colNo - ) where +module DOM.HTML.Event.ErrorEvent where -import DOM.Event.Types (ErrorEvent) +import DOM.HTML.Event.Types (ErrorEvent) foreign import message :: ErrorEvent -> String foreign import fileName :: ErrorEvent -> String diff --git a/src/DOM/Event/EventTypes.purs b/src/DOM/HTML/Event/EventTypes.purs similarity index 81% rename from src/DOM/Event/EventTypes.purs rename to src/DOM/HTML/Event/EventTypes.purs index 446de78..4e69057 100644 --- a/src/DOM/Event/EventTypes.purs +++ b/src/DOM/HTML/Event/EventTypes.purs @@ -1,4 +1,4 @@ -module DOM.Event.EventTypes where +module DOM.HTML.Event.EventTypes where import DOM.Event.Types (EventType(..)) @@ -14,24 +14,12 @@ animationiteration = EventType "animationiteration" animationstart :: EventType animationstart = EventType "animationstart" -audioprocess :: EventType -audioprocess = EventType "audioprocess" - -beforeprint :: EventType -beforeprint = EventType "beforeprint" - beforeunload :: EventType beforeunload = EventType "beforeunload" blur :: EventType blur = EventType "blur" -canplay :: EventType -canplay = EventType "canplay" - -canplaythrough :: EventType -canplaythrough = EventType "canplaythrough" - change :: EventType change = EventType "change" @@ -53,12 +41,6 @@ compositionupdate = EventType "compositionupdate" contextmenu :: EventType contextmenu = EventType "contextmenu" -copy :: EventType -copy = EventType "copy" - -cut :: EventType -cut = EventType "cut" - dblclick :: EventType dblclick = EventType "dblclick" @@ -83,36 +65,18 @@ dragstart = EventType "dragstart" drop :: EventType drop = EventType "drop" -durationchange :: EventType -durationchange = EventType "durationchange" - -emptied :: EventType -emptied = EventType "emptied" - -ended :: EventType -ended = EventType "ended" - error :: EventType error = EventType "error" focus :: EventType focus = EventType "focus" -fullscreenchange :: EventType -fullscreenchange = EventType "fullscreenchange" - -fullscreenerror :: EventType -fullscreenerror = EventType "fullscreenerror" - hashchange :: EventType hashchange = EventType "hashchange" input :: EventType input = EventType "input" -invalid :: EventType -invalid = EventType "invalid" - keydown :: EventType keydown = EventType "keydown" @@ -170,9 +134,6 @@ pagehide = EventType "pagehide" pageshow :: EventType pageshow = EventType "pageshow" -paste :: EventType -paste = EventType "paste" - pause :: EventType pause = EventType "pause" @@ -257,11 +218,5 @@ unload = EventType "unload" visibilitychange :: EventType visibilitychange = EventType "visibilitychange" -volumechange :: EventType -volumechange = EventType "volumechange" - -waiting :: EventType -waiting = EventType "waiting" - wheel :: EventType wheel = EventType "wheel" diff --git a/src/DOM/HTML/Event/Types.purs b/src/DOM/HTML/Event/Types.purs new file mode 100644 index 0000000..51b95f3 --- /dev/null +++ b/src/DOM/HTML/Event/Types.purs @@ -0,0 +1,49 @@ +module DOM.HTML.Event.Types + ( DragEvent + , dragEventToEvent + , readDragEvent + , ErrorEvent + , errorEventToEvent + , readErrorEvent + , HashChangeEvent + , hashChangeEventToEvent + , readHashChangeEvent + ) where + +import Data.Foreign (Foreign, F, unsafeReadTagged) +import Data.Foreign.Class (class IsForeign) +import DOM.Event.Types (Event) +import Unsafe.Coerce as U + +foreign import data DragEvent :: * + +dragEventToEvent :: DragEvent -> Event +dragEventToEvent = U.unsafeCoerce + +readDragEvent :: Foreign -> F DragEvent +readDragEvent = unsafeReadTagged "DragEvent" + +instance isForeignDragEvent :: IsForeign DragEvent where + read = readDragEvent + +foreign import data ErrorEvent :: * + +errorEventToEvent :: ErrorEvent -> Event +errorEventToEvent = U.unsafeCoerce + +readErrorEvent :: Foreign -> F ErrorEvent +readErrorEvent = unsafeReadTagged "ErrorEvent" + +instance isForeignErrorEvent :: IsForeign ErrorEvent where + read = readErrorEvent + +foreign import data HashChangeEvent :: * + +hashChangeEventToEvent :: HashChangeEvent -> Event +hashChangeEventToEvent = U.unsafeCoerce + +readHashChangeEvent :: Foreign -> F HashChangeEvent +readHashChangeEvent = unsafeReadTagged "HashChangeEvent" + +instance isForeignHashChangeEvent :: IsForeign HashChangeEvent where + read = readHashChangeEvent diff --git a/src/DOM/HTML/HTMLMediaElement/CanPlayType.purs b/src/DOM/HTML/HTMLMediaElement/CanPlayType.purs index 7ef9e4b..8187394 100644 --- a/src/DOM/HTML/HTMLMediaElement/CanPlayType.purs +++ b/src/DOM/HTML/HTMLMediaElement/CanPlayType.purs @@ -13,11 +13,8 @@ newtype CanPlayType = CanPlayType String runCanPlayType :: CanPlayType -> String runCanPlayType (CanPlayType t) = t -instance eqCanPlayType :: Eq CanPlayType where - eq (CanPlayType x) (CanPlayType y) = x == y - -instance ordCanPlayType :: Ord CanPlayType where - compare (CanPlayType x) (CanPlayType y) = compare x y +derive instance eqCanPlayType :: Eq CanPlayType +derive instance ordCanPlayType :: Ord CanPlayType instance showCanPlayType :: Show CanPlayType where show (CanPlayType t) = "(CanPlayType " <> show t <> ")" diff --git a/src/DOM/HTML/HTMLMediaElement/NetworkState.purs b/src/DOM/HTML/HTMLMediaElement/NetworkState.purs index f32340c..ad13b2a 100644 --- a/src/DOM/HTML/HTMLMediaElement/NetworkState.purs +++ b/src/DOM/HTML/HTMLMediaElement/NetworkState.purs @@ -11,9 +11,7 @@ data NetworkState | NETWORK_NO_SOURCE derive instance eqNetworkState :: Eq NetworkState - -instance ordNetworkState :: Ord NetworkState where - compare x y = compare (fromEnumNetworkState x) (fromEnumNetworkState y) +derive instance ordNetworkState :: Ord NetworkState instance boundedNetworkState :: Bounded NetworkState where bottom = NETWORK_EMPTY @@ -35,14 +33,18 @@ instance showNetworkState :: Show NetworkState where show NETWORK_NO_SOURCE = "NETWORK_NO_SOURCE" toEnumNetworkState :: Int -> Maybe NetworkState -toEnumNetworkState 0 = Just NETWORK_EMPTY -toEnumNetworkState 1 = Just NETWORK_IDLE -toEnumNetworkState 2 = Just NETWORK_LOADING -toEnumNetworkState 3 = Just NETWORK_NO_SOURCE -toEnumNetworkState _ = Nothing +toEnumNetworkState = + case _ of + 0 -> Just NETWORK_EMPTY + 1 -> Just NETWORK_IDLE + 2 -> Just NETWORK_LOADING + 3 -> Just NETWORK_NO_SOURCE + _ -> Nothing fromEnumNetworkState :: NetworkState -> Int -fromEnumNetworkState NETWORK_EMPTY = 0 -fromEnumNetworkState NETWORK_IDLE = 1 -fromEnumNetworkState NETWORK_LOADING = 2 -fromEnumNetworkState NETWORK_NO_SOURCE = 3 +fromEnumNetworkState = + case _ of + NETWORK_EMPTY -> 0 + NETWORK_IDLE -> 1 + NETWORK_LOADING -> 2 + NETWORK_NO_SOURCE -> 3 diff --git a/src/DOM/HTML/HTMLMediaElement/ReadyState.purs b/src/DOM/HTML/HTMLMediaElement/ReadyState.purs index 1544095..3910e3e 100644 --- a/src/DOM/HTML/HTMLMediaElement/ReadyState.purs +++ b/src/DOM/HTML/HTMLMediaElement/ReadyState.purs @@ -12,9 +12,7 @@ data ReadyState | HAVE_ENOUGH_DATA derive instance eqReadyState :: Eq ReadyState - -instance ordReadyState :: Ord ReadyState where - compare x y = compare (fromEnumReadyState x) (fromEnumReadyState y) +derive instance ordReadyState :: Ord ReadyState instance boundedReadyState :: Bounded ReadyState where bottom = HAVE_NOTHING @@ -37,16 +35,20 @@ instance showReadyState :: Show ReadyState where show HAVE_ENOUGH_DATA = "HAVE_ENOUGH_DATA" toEnumReadyState :: Int -> Maybe ReadyState -toEnumReadyState 0 = Just HAVE_NOTHING -toEnumReadyState 1 = Just HAVE_METADATA -toEnumReadyState 2 = Just HAVE_CURRENT_DATA -toEnumReadyState 3 = Just HAVE_FUTURE_DATA -toEnumReadyState 4 = Just HAVE_ENOUGH_DATA -toEnumReadyState _ = Nothing +toEnumReadyState = + case _ of + 0 -> Just HAVE_NOTHING + 1 -> Just HAVE_METADATA + 2 -> Just HAVE_CURRENT_DATA + 3 -> Just HAVE_FUTURE_DATA + 4 -> Just HAVE_ENOUGH_DATA + _ -> Nothing fromEnumReadyState :: ReadyState -> Int -fromEnumReadyState HAVE_NOTHING = 0 -fromEnumReadyState HAVE_METADATA = 1 -fromEnumReadyState HAVE_CURRENT_DATA = 2 -fromEnumReadyState HAVE_FUTURE_DATA = 3 -fromEnumReadyState HAVE_ENOUGH_DATA = 4 +fromEnumReadyState = + case _ of + HAVE_NOTHING -> 0 + HAVE_METADATA -> 1 + HAVE_CURRENT_DATA -> 2 + HAVE_FUTURE_DATA -> 3 + HAVE_ENOUGH_DATA -> 4 diff --git a/src/DOM/HTML/HTMLTrackElement/ReadyState.purs b/src/DOM/HTML/HTMLTrackElement/ReadyState.purs index 94e6ed5..e5a9835 100644 --- a/src/DOM/HTML/HTMLTrackElement/ReadyState.purs +++ b/src/DOM/HTML/HTMLTrackElement/ReadyState.purs @@ -1,4 +1,4 @@ -module DOM.HTML.HTMLTrackElement.ReadyState (ReadyState(..)) where +module DOM.HTML.HTMLTrackElement.ReadyState where import Prelude import Data.Maybe (Maybe(..)) @@ -11,9 +11,7 @@ data ReadyState | ERROR derive instance eqReadyState :: Eq ReadyState - -instance ordReadyState :: Ord ReadyState where - compare x y = compare (fromEnumReadyState x) (fromEnumReadyState y) +derive instance ordReadyState :: Ord ReadyState instance boundedReadyState :: Bounded ReadyState where bottom = NONE @@ -35,14 +33,18 @@ instance showReadyState :: Show ReadyState where show ERROR = "ERROR" toEnumReadyState :: Int -> Maybe ReadyState -toEnumReadyState 0 = Just NONE -toEnumReadyState 1 = Just LOADING -toEnumReadyState 2 = Just LOADED -toEnumReadyState 3 = Just ERROR -toEnumReadyState _ = Nothing +toEnumReadyState = + case _ of + 0 -> Just NONE + 1 -> Just LOADING + 2 -> Just LOADED + 3 -> Just ERROR + _ -> Nothing fromEnumReadyState :: ReadyState -> Int -fromEnumReadyState NONE = 0 -fromEnumReadyState LOADING = 1 -fromEnumReadyState LOADED = 2 -fromEnumReadyState ERROR = 3 +fromEnumReadyState = + case _ of + NONE -> 0 + LOADING -> 1 + LOADED -> 2 + ERROR -> 3 diff --git a/src/DOM/Event/CloseEvent.js b/src/DOM/Websocket/Event/CloseEvent.js similarity index 64% rename from src/DOM/Event/CloseEvent.js rename to src/DOM/Websocket/Event/CloseEvent.js index 5144a4f..88734db 100644 --- a/src/DOM/Event/CloseEvent.js +++ b/src/DOM/Websocket/Event/CloseEvent.js @@ -1,15 +1,13 @@ "use strict"; -// module DOM.Event.CloseEvent - exports.code = function (e) { - e.code; + return e.code; }; exports.reason = function (e) { - e.reason; + return e.reason; }; exports.wasClean = function (e) { - e.wasClean; + return e.wasClean; }; diff --git a/src/DOM/Event/CloseEvent.purs b/src/DOM/Websocket/Event/CloseEvent.purs similarity index 50% rename from src/DOM/Event/CloseEvent.purs rename to src/DOM/Websocket/Event/CloseEvent.purs index b29fa49..2d01773 100644 --- a/src/DOM/Event/CloseEvent.purs +++ b/src/DOM/Websocket/Event/CloseEvent.purs @@ -1,12 +1,6 @@ -module DOM.Event.CloseEvent - ( code - , reason - , wasClean - ) where - -import Data.Maybe.Unsafe as U -import DOM.Event.Types (CloseEvent) +module DOM.Websocket.Event.CloseEvent where +import DOM.Websocket.Event.Types (CloseEvent) foreign import code :: CloseEvent -> Int foreign import reason :: CloseEvent -> String diff --git a/src/DOM/Websocket/Event/Types.purs b/src/DOM/Websocket/Event/Types.purs new file mode 100644 index 0000000..4e0b8b3 --- /dev/null +++ b/src/DOM/Websocket/Event/Types.purs @@ -0,0 +1,17 @@ +module DOM.Websocket.Event.Types where + +import Data.Foreign (Foreign, F, unsafeReadTagged) +import Data.Foreign.Class (class IsForeign) +import DOM.Event.Types (Event) +import Unsafe.Coerce as U + +foreign import data CloseEvent :: * + +closeEventToEvent :: CloseEvent -> Event +closeEventToEvent = U.unsafeCoerce + +readCloseEvent :: Foreign -> F CloseEvent +readCloseEvent = unsafeReadTagged "CloseEvent" + +instance isForeignCloseEvent :: IsForeign CloseEvent where + read = readCloseEvent