packages feed

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

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-- | Generated by dom-gen from dom (webref). Do not edit.
module JSDOM.Generated.NodeList
       (item, item_, itemUnsafe, itemUnchecked, getLength, NodeList(..), gTypeNodeList, IsNodeList, toNodeList)
       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/NodeList/item MDN NodeList.item documentation>
item :: (MonadDOM m, IsNodeList self) => self -> Word -> m (Maybe Node)
item self index = liftDOM ((((Types.toNodeList self) ^. jsf "item" [toJSVal index]) >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/NodeList/item MDN NodeList.item documentation>
item_ :: (MonadDOM m, IsNodeList self) => self -> Word -> m ()
item_ self index = liftDOM (void ((Types.toNodeList self) ^. jsf "item" [toJSVal index]))

-- | <https://developer.mozilla.org/docs/Web/API/NodeList/item MDN NodeList.item documentation>
itemUnsafe :: (MonadDOM m, IsNodeList self, HasCallStack) => self -> Word -> m Node
itemUnsafe self index = liftDOM (((((Types.toNodeList self) ^. jsf "item" [toJSVal index]) >>= fromJSValUnchecked) >>= P.maybe (P.error "Nothing to return") P.return))

-- | <https://developer.mozilla.org/docs/Web/API/NodeList/item MDN NodeList.item documentation>
itemUnchecked :: (MonadDOM m, IsNodeList self) => self -> Word -> m Node
itemUnchecked self index = liftDOM ((((Types.toNodeList self) ^. jsf "item" [toJSVal index]) >>= fromJSValUnchecked))

-- | <https://developer.mozilla.org/docs/Web/API/NodeList/length MDN NodeList.length documentation>
getLength :: (MonadDOM m, IsNodeList self) => self -> m Word
getLength self = liftDOM ((P.round <$> (((Types.toNodeList self) ^. js "length") >>= valToNumber)))