packages feed

jsaddle-dom-0.10.0.0: src/JSDOM/Generated/IdleRequestOptions.hs

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-- | Generated by dom-gen from requestidlecallback (webref). Do not edit.
module JSDOM.Generated.IdleRequestOptions
       (newIdleRequestOptions, setTimeout, getTimeout, getTimeoutUnsafe, getTimeoutUnchecked, IdleRequestOptions(..), gTypeIdleRequestOptions)
       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://w3c.github.io/requestidlecallback/#dom-idlerequestoptions IdleRequestOptions specification>
newIdleRequestOptions :: (MonadDOM m) => m IdleRequestOptions
newIdleRequestOptions = liftDOM ((((new (jsg "Object") () >>= \o -> P.return o)) >>= fromJSValUnchecked))

-- | <https://w3c.github.io/requestidlecallback/#dom-idlerequestoptions-timeout IdleRequestOptions.timeout specification>
setTimeout :: (MonadDOM m) => IdleRequestOptions -> Word -> m ()
setTimeout self val = liftDOM (void (self ^. jss "timeout" (toJSVal val)))

-- | <https://w3c.github.io/requestidlecallback/#dom-idlerequestoptions-timeout IdleRequestOptions.timeout specification>
getTimeout :: (MonadDOM m) => IdleRequestOptions -> m (Maybe Word)
getTimeout self = liftDOM (((self ^. js "timeout") >>= fromJSValUnchecked))

-- | <https://w3c.github.io/requestidlecallback/#dom-idlerequestoptions-timeout IdleRequestOptions.timeout specification>
getTimeoutUnsafe :: (MonadDOM m, HasCallStack) => IdleRequestOptions -> m Word
getTimeoutUnsafe self = liftDOM ((((self ^. js "timeout") >>= fromJSValUnchecked) >>= P.maybe (P.error "Nothing to return") P.return))

-- | <https://w3c.github.io/requestidlecallback/#dom-idlerequestoptions-timeout IdleRequestOptions.timeout specification>
getTimeoutUnchecked :: (MonadDOM m) => IdleRequestOptions -> m Word
getTimeoutUnchecked self = liftDOM ((P.round <$> ((self ^. js "timeout") >>= valToNumber)))