{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module JSDOM.Generated.Storage
(key, key_, keyUnsafe, keyUnchecked, getItem, getItem_,
getItemUnsafe, getItemUnchecked, setItem, removeItem, clear,
getLength, Storage(..), gTypeStorage)
where
import Prelude ((.), (==), (>>=), return, IO, Int, Float, Double, Bool(..), Maybe, maybe, fromIntegral, round, realToFrac, fmap, Show, Read, Eq, Ord, Maybe(..))
import qualified Prelude (error)
import Data.Typeable (Typeable)
import Data.Traversable (mapM)
import Language.Javascript.JSaddle (JSM(..), JSVal(..), JSString, strictEqual, toJSVal, valToStr, valToNumber, valToBool, js, jss, jsf, jsg, function, asyncFunction, new, array, jsUndefined, (!), (!!))
import Data.Int (Int64)
import Data.Word (Word, Word64)
import JSDOM.Types
import Control.Applicative ((<$>))
import Control.Monad (void)
import Control.Lens.Operators ((^.))
import JSDOM.EventTargetClosures (EventName, unsafeEventName, unsafeEventNameAsync)
import JSDOM.Enums
key ::
(MonadDOM m, FromJSString result) =>
Storage -> Word -> m (Maybe result)
key self index
= liftDOM
((self ^. jsf "key" [toJSVal index]) >>= fromMaybeJSString)
key_ :: (MonadDOM m) => Storage -> Word -> m ()
key_ self index
= liftDOM (void (self ^. jsf "key" [toJSVal index]))
keyUnsafe ::
(MonadDOM m, HasCallStack, FromJSString result) =>
Storage -> Word -> m result
keyUnsafe self index
= liftDOM
(((self ^. jsf "key" [toJSVal index]) >>= fromMaybeJSString) >>=
maybe (Prelude.error "Nothing to return") return)
keyUnchecked ::
(MonadDOM m, FromJSString result) => Storage -> Word -> m result
keyUnchecked self index
= liftDOM
((self ^. jsf "key" [toJSVal index]) >>= fromJSValUnchecked)
getItem ::
(MonadDOM m, ToJSString key, FromJSString result) =>
Storage -> key -> m (Maybe result)
getItem self key = liftDOM ((self ! key) >>= fromMaybeJSString)
getItem_ :: (MonadDOM m, ToJSString key) => Storage -> key -> m ()
getItem_ self key = liftDOM (void (self ! key))
getItemUnsafe ::
(MonadDOM m, ToJSString key, HasCallStack, FromJSString result) =>
Storage -> key -> m result
getItemUnsafe self key
= liftDOM
(((self ! key) >>= fromMaybeJSString) >>=
maybe (Prelude.error "Nothing to return") return)
getItemUnchecked ::
(MonadDOM m, ToJSString key, FromJSString result) =>
Storage -> key -> m result
getItemUnchecked self key
= liftDOM ((self ! key) >>= fromJSValUnchecked)
setItem ::
(MonadDOM m, ToJSString key, ToJSString data') =>
Storage -> key -> data' -> m ()
setItem self key data'
= liftDOM
(void (self ^. jsf "setItem" [toJSVal key, toJSVal data']))
removeItem ::
(MonadDOM m, ToJSString key) => Storage -> key -> m ()
removeItem self key
= liftDOM (void (self ^. jsf "removeItem" [toJSVal key]))
clear :: (MonadDOM m) => Storage -> m ()
clear self = liftDOM (void (self ^. jsf "clear" ()))
getLength :: (MonadDOM m) => Storage -> m Word
getLength self
= liftDOM (round <$> ((self ^. js "length") >>= valToNumber))