jsaddle-dom-0.10.0.0: src/JSDOM/Generated/EventSource.hs
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-- | Generated by dom-gen from html (webref). Do not edit.
module JSDOM.Generated.EventSource
(newEventSource, close, getUrl, getWithCredentials, getReadyState, pattern CONNECTING, pattern OPEN, pattern CLOSED, open, message, error, EventSource(..), gTypeEventSource)
where
import Prelude ((.), (==), (>>=), (<$>), (++), Bool(..), Maybe(..), IO, Int, Word, Double, Float)
import qualified Prelude as P
import Control.Monad (void)
import Control.Lens.Operators ((^.))
import Language.Javascript.JSaddle (JSM, JSVal, JSString, toJSVal, valToBool, valToNumber, js, jss, jsf, jsg, new, function, asyncFunction, jsUndefined, jsNull)
import JSDOM.Types
import qualified JSDOM.Types as Types
import JSDOM.EventTargetClosures (EventName, unsafeEventName, unsafeEventNameAsync)
import JSDOM.Generated.Enums
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/EventSource MDN EventSource. documentation>
newEventSource :: (MonadDOM m, ToJSString url) => url -> Maybe EventSourceInit -> m EventSource
newEventSource url eventSourceInitDict = liftDOM (((new (jsg "EventSource") [toJSVal url, P.maybe (P.return jsUndefined) toJSVal eventSourceInitDict]) >>= fromJSValUnchecked))
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/close MDN EventSource.close documentation>
close :: (MonadDOM m) => EventSource -> m ()
close self = liftDOM (void (self ^. jsf "close" ()))
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/url MDN EventSource.url documentation>
getUrl :: (MonadDOM m, FromJSString result) => EventSource -> m result
getUrl self = liftDOM (((self ^. js "url") >>= fromJSValUnchecked))
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials MDN EventSource.withCredentials documentation>
getWithCredentials :: (MonadDOM m) => EventSource -> m Bool
getWithCredentials self = liftDOM (((self ^. js "withCredentials") >>= valToBool))
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/readyState MDN EventSource.readyState documentation>
getReadyState :: (MonadDOM m) => EventSource -> m Word
getReadyState self = liftDOM ((P.round <$> ((self ^. js "readyState") >>= valToNumber)))
pattern CONNECTING = 0
pattern OPEN = 1
pattern CLOSED = 2
-- | <https://html.spec.whatwg.org/multipage/server-sent-events.html#handler-eventsource-onopen open event>
open :: EventName EventSource Event
open = unsafeEventNameAsync (toJSString "open")
-- | <https://html.spec.whatwg.org/multipage/server-sent-events.html#handler-eventsource-onmessage message event>
message :: EventName EventSource MessageEvent
message = unsafeEventNameAsync (toJSString "message")
-- | <https://html.spec.whatwg.org/multipage/server-sent-events.html#handler-eventsource-onerror error event>
error :: EventName EventSource Event
error = unsafeEventNameAsync (toJSString "error")