{-# LANGUAGE PatternSynonyms #-}
-- For HasCallStack compatibility
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module JSDOM.Generated.PositionCallback
       (newPositionCallback, newPositionCallbackSync,
        newPositionCallbackAsync, PositionCallback)
       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

-- | <https://developer.mozilla.org/en-US/docs/Web/API/PositionCallback Mozilla PositionCallback documentation> 
newPositionCallback ::
                    (MonadDOM m) => (Geoposition -> JSM ()) -> m PositionCallback
newPositionCallback :: forall (m :: * -> *).
MonadDOM m =>
(Geoposition -> JSM ()) -> m PositionCallback
newPositionCallback Geoposition -> JSM ()
callback
  = DOM PositionCallback -> m PositionCallback
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM
      (Callback (JSVal -> IO ()) -> PositionCallback
PositionCallback (Callback (JSVal -> IO ()) -> PositionCallback)
-> (Function -> Callback (JSVal -> IO ()))
-> Function
-> PositionCallback
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Function -> Callback (JSVal -> IO ())
forall a. Function -> Callback a
Callback (Function -> PositionCallback)
-> JSM Function -> DOM PositionCallback
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
         JSCallAsFunction -> JSM Function
function
           (\ JSVal
_ JSVal
_ [JSVal
position] ->
              JSVal -> JSM Geoposition
forall a. FromJSVal a => JSVal -> JSM a
fromJSValUnchecked JSVal
position JSM Geoposition -> (Geoposition -> JSM ()) -> JSM ()
forall a b. JSM a -> (a -> JSM b) -> JSM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ Geoposition
position' -> Geoposition -> JSM ()
callback Geoposition
position'))

-- | <https://developer.mozilla.org/en-US/docs/Web/API/PositionCallback Mozilla PositionCallback documentation> 
newPositionCallbackSync ::
                        (MonadDOM m) => (Geoposition -> JSM ()) -> m PositionCallback
newPositionCallbackSync :: forall (m :: * -> *).
MonadDOM m =>
(Geoposition -> JSM ()) -> m PositionCallback
newPositionCallbackSync Geoposition -> JSM ()
callback
  = DOM PositionCallback -> m PositionCallback
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM
      (Callback (JSVal -> IO ()) -> PositionCallback
PositionCallback (Callback (JSVal -> IO ()) -> PositionCallback)
-> (Function -> Callback (JSVal -> IO ()))
-> Function
-> PositionCallback
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Function -> Callback (JSVal -> IO ())
forall a. Function -> Callback a
Callback (Function -> PositionCallback)
-> JSM Function -> DOM PositionCallback
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
         JSCallAsFunction -> JSM Function
function
           (\ JSVal
_ JSVal
_ [JSVal
position] ->
              JSVal -> JSM Geoposition
forall a. FromJSVal a => JSVal -> JSM a
fromJSValUnchecked JSVal
position JSM Geoposition -> (Geoposition -> JSM ()) -> JSM ()
forall a b. JSM a -> (a -> JSM b) -> JSM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ Geoposition
position' -> Geoposition -> JSM ()
callback Geoposition
position'))

-- | <https://developer.mozilla.org/en-US/docs/Web/API/PositionCallback Mozilla PositionCallback documentation> 
newPositionCallbackAsync ::
                         (MonadDOM m) => (Geoposition -> JSM ()) -> m PositionCallback
newPositionCallbackAsync :: forall (m :: * -> *).
MonadDOM m =>
(Geoposition -> JSM ()) -> m PositionCallback
newPositionCallbackAsync Geoposition -> JSM ()
callback
  = DOM PositionCallback -> m PositionCallback
forall (m :: * -> *) a. MonadDOM m => DOM a -> m a
liftDOM
      (Callback (JSVal -> IO ()) -> PositionCallback
PositionCallback (Callback (JSVal -> IO ()) -> PositionCallback)
-> (Function -> Callback (JSVal -> IO ()))
-> Function
-> PositionCallback
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Function -> Callback (JSVal -> IO ())
forall a. Function -> Callback a
Callback (Function -> PositionCallback)
-> JSM Function -> DOM PositionCallback
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
         JSCallAsFunction -> JSM Function
asyncFunction
           (\ JSVal
_ JSVal
_ [JSVal
position] ->
              JSVal -> JSM Geoposition
forall a. FromJSVal a => JSVal -> JSM a
fromJSValUnchecked JSVal
position JSM Geoposition -> (Geoposition -> JSM ()) -> JSM ()
forall a b. JSM a -> (a -> JSM b) -> JSM b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ Geoposition
position' -> Geoposition -> JSM ()
callback Geoposition
position'))