| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Shpadoinkle.Console
Description
This module exposes the browser's native console logging and debugging features, including underutilized features such as time measurement, table displays, and assertions.
Synopsis
- class LogJS (c :: Type -> Constraint) where
- class Assert (c :: Type -> Constraint) where
- class LogJS c => Trapper c where
- trapper :: c a => JSContextRef -> a -> a
- askJSM :: MonadJSM m => m JSContextRef
- log :: forall c a. LogJS c => c a => a -> JSM ()
- debug :: forall c a. LogJS c => c a => a -> JSM ()
- info :: forall c a. LogJS c => c a => a -> JSM ()
- warn :: forall c a. LogJS c => c a => a -> JSM ()
- table :: ToJSON a => [a] -> JSM ()
- newtype TimeLabel = TimeLabel {
- unTimeLabel :: Text
- time :: TimeLabel -> JSM ()
- timeEnd :: TimeLabel -> JSM ()
Classes
class LogJS (c :: Type -> Constraint) where Source #
LogJS is the base class for logging to the browser console.
Browser consoles contain rich tooling for exploring JavaScript objects,
DOM nodes, and much more. To take advantage of these native features, we
need to choose how we are going to log. The LogJS class is intended to
be used in conjunction with TypeApplications.
data Person = Person { first :: String, last :: String, age :: Int } deriving (Generic, ToJSON)
main = logJS @ToJSON "log" $ Person "bob" "saget" 45
is effectively equivalent to:
console.log({first: "bob", last: "saget", age: 45})
in that the console will render with nice expand/collapse object exploration features.
Instances
| LogJS Show Source # | Logs against |
| LogJS ToJSON Source # | Logs against |
| LogJS ToJSVal Source # | Logs against |
class Assert (c :: Type -> Constraint) where Source #
Assert is a class for assertion programming. It behaves the same as LogJS but calls
console.assert instead of
other console methods. This will only have an effect if the Bool provided to assert is False.
class LogJS c => Trapper c where Source #
Trapper is a class intended for continuous logging of your application and the catching of helpless animals.
Usage is along the lines of trace where the effect of logging is implicit.
To make this work in both GHC and GHCjs contexts, you do need to
pass the JSContextRef in manually (askJSM re-exported here for convenience).
main :: IO () main = runJSorWarp 8080 $ do ctx <- askJSM simple runParDiff initial (view . trapper @ToJSON ctx) getBody
Minimal complete definition
Nothing
Methods
trapper :: c a => JSContextRef -> a -> a Source #
Instances
| Trapper Show Source # | |
Defined in Shpadoinkle.Console Methods trapper :: Show a => JSContextRef -> a -> a Source # | |
| Trapper ToJSON Source # | |
Defined in Shpadoinkle.Console Methods trapper :: ToJSON a => JSContextRef -> a -> a Source # | |
| Trapper ToJSVal Source # | |
Defined in Shpadoinkle.Console Methods trapper :: ToJSVal a => JSContextRef -> a -> a Source # | |
askJSM :: MonadJSM m => m JSContextRef #
Gets the JavaScript context from the monad
Native methods
Log levels
debug :: forall c a. LogJS c => c a => a -> JSM () Source #
Log with the "debug" log level using console.debug
info :: forall c a. LogJS c => c a => a -> JSM () Source #
Log with the "info" log level using console.info
warn :: forall c a. LogJS c => c a => a -> JSM () Source #
Log with the "warn" log level using console.warn
Fancy display
table :: ToJSON a => [a] -> JSM () Source #
Log a list of JSON objects to the console where it will rendered as a table using console.table
Time Measurement
A unique label for a timer. This is used to tie calls to console.time to console.timeEnd
Constructors
| TimeLabel | |
Fields
| |
Instances
| Eq TimeLabel Source # | |
| Ord TimeLabel Source # | |
| Show TimeLabel Source # | |
| IsString TimeLabel Source # | |
Defined in Shpadoinkle.Console Methods fromString :: String -> TimeLabel # | |