miso-1.9.0.0: A tasty Haskell front-end web framework

Copyright(C) 2016-2025 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso

Contents

Description

 
Synopsis

Miso

Combinators

miso :: Eq model => (URI -> App effect model action a) -> JSM () Source #

Runs an isomorphic miso application. Assumes the pre-rendered DOM is already present. Note: Uses mountPoint as the Component name. Always mounts to body. Copies page into the virtual DOM.

startApp :: Eq model => App effect model action a -> JSM () Source #

Runs a miso application Initializes application at mountPoint (defaults to body when Nothing)

Sink

sink :: MisoString -> App effect model action a -> Sink action Source #

The sink function gives access to an App Sink. This is use for third-party integration, or for long-running IO operations. Use at your own risk.

If the Component or is not mounted, it does not exist in the global component map, and will therefore be a no-op. This is a backdoor function, caveat emptor.

It is recommended to use the mail or notify functions by default when message passing with App and Component

Sampling

sample :: Component effect model action a -> JSM model Source #

Read-only access to another Component's model. This function is safe to use when a child Component wishes access a parent Components model state. Under this circumstance the parent will always be mounted and available.

Otherwise, if a sibling or parent Component's model state is attempted to be accessed. Then we throw a NotMountedException, in the case the Component being accessed is not available.

Message Passing

notify :: Component effect model action a -> action -> JSM () Source #

Like mail but lifted to work with the Transition interface. This function is used to send messages to Components on other parts of the application

Types

data App effect model action a Source #

Application entry point

Constructors

App 

Fields

  • model :: model

    initial model

  • update :: action -> effect model action a

    Function to update model, optionally providing effects. See the Transition monad for succinctly expressing model transitions.

  • view :: model -> View action

    Function to draw View

  • subs :: [Sub action]

    List of subscriptions to run during application lifetime

  • events :: Map MisoString Bool

    List of delegated events that the body element will listen for. You can start with defaultEvents and modify as needed.

  • initialAction :: Maybe action

    Initial action that is run after the application has loaded, optional since *1.9*

  • mountPoint :: Maybe MisoString

    Id of the root element for DOM diff. If Nothing is provided, the entire document body is used as a mount point.

  • logLevel :: LogLevel

    Debugging for prerendering and event delegation

  • translate :: effect model action a -> Effect model action a

    natural transformation to allow others to use their own custom Monad stack.

Instances
ToView (App effect model action a) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (App effect model action a) :: Type Source #

Methods

toView :: App effect model action a -> View (ToViewAction (App effect model action a)) Source #

type ToViewAction (App effect model action a) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (App effect model action a) = action

data View action Source #

Core type for constructing a virtual DOM in Haskell

Instances
Functor View Source # 
Instance details

Defined in Miso.Types

Methods

fmap :: (a -> b) -> View a -> View b Source #

(<$) :: a -> View b -> View a Source #

IsString (View a) Source #

IsString instance

Instance details

Defined in Miso.Types

Methods

fromString :: String -> View a Source #

ToView (View action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (View action) :: Type Source #

Methods

toView :: View action -> View (ToViewAction (View action)) Source #

ToHtml [View a] Source #

Render a [View] to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: [View a] -> ByteString Source #

ToHtml (View a) Source #

Render a View to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: View a -> ByteString Source #

HasRouter (View a) Source #

View

Instance details

Defined in Miso.Router

Associated Types

type RouteT (View a) a :: Type Source #

Methods

mkRouter :: Proxy (View a) -> Proxy a0 -> RouteT (View a) a0 -> Router a0 Source #

HasLink (View a :: Type) Source #

For constructing type-safe links

Instance details

Defined in Miso.Types

Associated Types

type MkLink (View a) a :: Type Source #

Methods

toLink :: (Link -> a0) -> Proxy (View a) -> Link -> MkLink (View a) a0 Source #

type ToViewAction (View action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action
type RouteT (View a) x Source # 
Instance details

Defined in Miso.Router

type RouteT (View a) x = x
type MkLink (View a :: Type) b Source # 
Instance details

Defined in Miso.Types

type MkLink (View a :: Type) b = b

newtype Key Source #

A unique key for a dom node.

This key is only used to speed up diffing the children of a DOM node, the actual content is not important. The keys of the children of a given DOM node must be unique. Failure to satisfy this invariant gives undefined behavior at runtime.

Constructors

Key MisoString 
Instances
ToJSVal Key Source #

ToJSVal instance for Key

Instance details

Defined in Miso.Types

ToKey Key Source #

Identity instance

Instance details

Defined in Miso.Types

Methods

toKey :: Key -> Key Source #

data Attribute action Source #

Attribute of a vnode in a View.

The Sink callback can be used to dispatch actions which are fed back to the update function. This is especially useful for event handlers like the onclick attribute. The second argument represents the vnode the attribute is attached to.

Instances
Functor Attribute Source # 
Instance details

Defined in Miso.Types

Methods

fmap :: (a -> b) -> Attribute a -> Attribute b Source #

(<$) :: a -> Attribute b -> Attribute a Source #

data NS Source #

Namespace of DOM elements.

Constructors

HTML

HTML Namespace

SVG

SVG Namespace

MATHML

MATHML Namespace

Instances
Eq NS Source # 
Instance details

Defined in Miso.Types

Methods

(==) :: NS -> NS -> Bool Source #

(/=) :: NS -> NS -> Bool Source #

Show NS Source # 
Instance details

Defined in Miso.Types

ToJSVal NS Source # 
Instance details

Defined in Miso.Types

data LogLevel Source #

Optional Logging for debugging miso internals (useful to see if prerendering is successful)

Constructors

Off 
DebugPrerender

Will warn if the structure or properties of the DOM vs. Virtual DOM differ during prerendering.

DebugEvents

Will warn if an event cannot be routed to the Haskell event handler that raised it. Also will warn if an event handler is being used, yet it's not being listened for by the event delegator mount point.

DebugAll

Logs on all of the above

Instances
Eq LogLevel Source # 
Instance details

Defined in Miso.Types

Show LogLevel Source # 
Instance details

Defined in Miso.Types

data Component effect model action a Source #

Used with component to parameterize App by name

Constructors

Component 

Fields

Instances
ToView (Component effect model action a) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (Component effect model action a) :: Type Source #

Methods

toView :: Component effect model action a -> View (ToViewAction (Component effect model action a)) Source #

ToHtml (Component effect model action a) Source #

Render a Component to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: Component effect model action a -> ByteString Source #

type ToViewAction (Component effect model action a) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (Component effect model action a) = action

data SomeComponent Source #

Existential wrapper used to allow the nesting of Component in App

Constructors

Eq model => SomeComponent (Component effect model action a) 

Classes

class ToView a where Source #

Convenience class for using View

Associated Types

type ToViewAction a :: Type Source #

Methods

toView :: a -> View (ToViewAction a) Source #

Instances
ToView (View action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (View action) :: Type Source #

Methods

toView :: View action -> View (ToViewAction (View action)) Source #

ToView (Component effect model action a) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (Component effect model action a) :: Type Source #

Methods

toView :: Component effect model action a -> View (ToViewAction (Component effect model action a)) Source #

ToView (App effect model action a) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (App effect model action a) :: Type Source #

Methods

toView :: App effect model action a -> View (ToViewAction (App effect model action a)) Source #

class ToKey key where Source #

Convert custom key types to Key.

Instances of this class do not have to guarantee uniqueness of the generated keys, it is up to the user to do so. toKey must be an injective function.

Methods

toKey :: key -> Key Source #

Converts any key into Key

Instances
ToKey Double Source #

Convert Double to Key

Instance details

Defined in Miso.Types

Methods

toKey :: Double -> Key Source #

ToKey Float Source #

Convert Float to Key

Instance details

Defined in Miso.Types

Methods

toKey :: Float -> Key Source #

ToKey Int Source #

Convert Int to Key

Instance details

Defined in Miso.Types

Methods

toKey :: Int -> Key Source #

ToKey Word Source #

Convert Word to Key

Instance details

Defined in Miso.Types

Methods

toKey :: Word -> Key Source #

ToKey String Source #

Convert String to Key

Instance details

Defined in Miso.Types

Methods

toKey :: String -> Key Source #

ToKey Text Source #

Convert T.Text to Key

Instance details

Defined in Miso.Types

Methods

toKey :: Text -> Key Source #

ToKey JSString Source #

Convert MisoString to Key

Instance details

Defined in Miso.Types

Methods

toKey :: JSString -> Key Source #

ToKey Key Source #

Identity instance

Instance details

Defined in Miso.Types

Methods

toKey :: Key -> Key Source #

Functions

defaultApp :: model -> (action -> Effect model action a) -> (model -> View action) -> App Effect model action a Source #

Smart constructor for App with sane defaults.

component :: MisoString -> App effect model action a -> Component effect model action a Source #

Smart constructor for parameterizing App by name Needed when calling embed and embedWith

embed :: Eq model => Component effect model action a -> [Attribute b] -> View b Source #

Used in the view function to embed Components in App

embedKeyed :: Eq model => Component effect model action a -> Key -> [Attribute b] -> View b Source #

Used in the view function to embed Components in App, with Key

getMountPoint :: Maybe MisoString -> MisoString Source #

Convenience for extracting mount point

Effect

Effect

Types

data Effect model action a Source #

A monad for succinctly expressing model transitions in the update function.

Effect is a state monad so it abstracts over manually passing the model around. It's also a writer monad where the accumulator is a list of scheduled IO actions. Multiple actions can be scheduled using Control.Monad.Writer.Class.tell from the mtl library and a single action can be scheduled using scheduleIO.

An Effect represents the results of an update action.

It consists of the updated model and a list of subscriptions. Each Sub is run in a new thread so there is no risk of accidentally blocking the application.

Tip: use the Effect monad in combination with the stateful lens operators (all operators ending in "="). The following example assumes the lenses field1, counter and field2 are in scope and that the LambdaCase language extension is enabled:

myApp = App
  { update = \case
      MyAction1 -> do
        field1 .= value1
        counter += 1
      MyAction2 -> do
        field2 %= f
        scheduleIO $ do
          putStrLn "Hello"
          putStrLn "World!"
  , ...
  }
Instances
MonadState model (Effect model action) Source # 
Instance details

Defined in Miso.Effect

Methods

get :: Effect model action model Source #

put :: model -> Effect model action () Source #

state :: (model -> (a, model)) -> Effect model action a Source #

MonadWriter [Sub action] (Effect model action) Source # 
Instance details

Defined in Miso.Effect

Methods

writer :: (a, [Sub action]) -> Effect model action a Source #

tell :: [Sub action] -> Effect model action () Source #

listen :: Effect model action a -> Effect model action (a, [Sub action]) Source #

pass :: Effect model action (a, [Sub action] -> [Sub action]) -> Effect model action a Source #

Monad (Effect model action) Source # 
Instance details

Defined in Miso.Effect

Methods

(>>=) :: Effect model action a -> (a -> Effect model action b) -> Effect model action b Source #

(>>) :: Effect model action a -> Effect model action b -> Effect model action b Source #

return :: a -> Effect model action a Source #

fail :: String -> Effect model action a Source #

Functor (Effect model action) Source # 
Instance details

Defined in Miso.Effect

Methods

fmap :: (a -> b) -> Effect model action a -> Effect model action b Source #

(<$) :: a -> Effect model action b -> Effect model action a Source #

MonadFail (Effect model action) Source #

MonadFail instance for Effect

Instance details

Defined in Miso.Effect

Methods

fail :: String -> Effect model action a Source #

Applicative (Effect model action) Source # 
Instance details

Defined in Miso.Effect

Methods

pure :: a -> Effect model action a Source #

(<*>) :: Effect model action (a -> b) -> Effect model action a -> Effect model action b Source #

liftA2 :: (a -> b -> c) -> Effect model action a -> Effect model action b -> Effect model action c Source #

(*>) :: Effect model action a -> Effect model action b -> Effect model action b Source #

(<*) :: Effect model action a -> Effect model action b -> Effect model action a Source #

type Sub action = Sink action -> JSM () Source #

Type synonym for constructing event subscriptions.

The Sink callback is used to dispatch actions which are then fed back to the update function.

type Sink action = action -> JSM () Source #

Function to asynchronously dispatch actions to the update function.

Combinators

effectSub :: model -> Sub action -> Effect model action () Source #

Like <# but schedules a subscription which is an IO computation which has access to a Sink which can be used to asynchronously dispatch actions to the update function.

A use-case is scheduling an IO computation which creates a 3rd-party JS widget which has an associated callback. The callback can then call the sink to turn events into actions. To do this without accessing a sink requires going via a Subscription which introduces a leaky-abstraction.

scheduleIO :: JSM action -> Effect model action () Source #

Schedule a single IO action for later execution.

Note that multiple IO action can be scheduled using Control.Monad.Writer.Class.tell from the mtl library.

scheduleIO_ :: JSM () -> Effect model action () Source #

Like scheduleIO but doesn't cause an action to be dispatched to the update function.

This is handy for scheduling IO computations where you don't care about their results or when they complete.

scheduleIOFor_ :: Foldable f => JSM (f action) -> Effect model action () Source #

Like 'scheduleIO_ but generalized to any instance of Foldable

This is handy for scheduling IO computations that return a Maybe value

scheduleSub :: Sub action -> Effect model action () Source #

Like scheduleIO but schedules a subscription which is an IO computation that has access to a Sink which can be used to asynchronously dispatch actions to the update function.

A use-case is scheduling an IO computation which creates a 3rd-party JS widget which has an associated callback. The callback can then call the sink to turn events into actions. To do this without accessing a sink requires going via a Subscription which introduces a leaky-abstraction.

mapSub :: (a -> b) -> Sub a -> Sub b Source #

Turn a subscription that consumes actions of type a into a subscription that consumes actions of type b using the supplied function of type a -> b.

noEff :: model -> Effect model action () Source #

Smart constructor for an Effect with no actions.

(<#) :: model -> JSM action -> Effect model action () infixl 0 Source #

Smart constructor for an Effect with exactly one action.

(#>) :: JSM action -> model -> Effect model action () infixr 0 Source #

Effect smart constructor, flipped

batchEff :: model -> [JSM action] -> Effect model action () Source #

Smart constructor for an Effect with multiple actions.

io :: JSM () -> Effect model action () Source #

A shorter synonym for scheduleIO_

update :: Action -> Effect Model Action ()
update = \case
  HelloWorld -> io (consoleLog "Hello World")

This is handy for scheduling IO computations where you don't care about their results or when they complete.

Since: 1.9.0.0

issue :: action -> Effect model action () Source #

A synonym for tell, specialized to Effect

update :: Action -> Effect Model Action ()
update = \case
  Click -> issue HelloWorld

Used to issue new action

Since: 1.9.0.0

Internal

runEffect :: model -> Effect model action a -> (model, [Sub action]) Source #

Internal function used to unwrap an Effect

Event

Types

data Decoder a Source #

Decoder data type for parsing events

Constructors

Decoder 

Fields

data DecodeTarget Source #

Data type representing path (consisting of field names) within event object where a decoder should be applied.

Constructors

DecodeTarget [MisoString]

Specify single path within Event object, where a decoder should be applied.

DecodeTargets [[MisoString]]

Specify multiple paths withing Event object, where decoding should be attempted. The first path where decoding suceeds is the one taken.

Combinators

at :: [MisoString] -> (Value -> Parser a) -> Decoder a Source #

Smart constructor for building a Decoder.

Decoders

emptyDecoder :: Decoder () Source #

Empty decoder for use with events like "click" that do not return any meaningful values

keycodeDecoder :: Decoder KeyCode Source #

Retrieves either "keyCode", "which" or "charCode" field in Decoder

keyInfoDecoder :: Decoder KeyInfo Source #

Retrieves either "keyCode", "which" or "charCode" field in Decoder, along with shift, ctrl, meta and alt.

checkedDecoder :: Decoder Checked Source #

Retrieves "checked" field in Decoder

valueDecoder :: Decoder MisoString Source #

Retrieves "value" field in Decoder

pointerDecoder :: Decoder PointerEvent Source #

Pointer decoder for use with events like "onpointerover"

Types

type Events = Map MisoString Bool Source #

Convenience type for Events

KeyboardEvent

data KeyInfo Source #

Type useful for both KeyCode and additional key press information.

Constructors

KeyInfo 
Instances
Eq KeyInfo Source # 
Instance details

Defined in Miso.Event.Types

Show KeyInfo Source # 
Instance details

Defined in Miso.Event.Types

CheckedEvent

newtype Checked Source #

Type used for Checkbox events.

Constructors

Checked Bool 

PointerEvent

data PointerEvent Source #

Type used for Pointer events. https://w3c.github.io/pointerevents

Constructors

PointerEvent 

Fields

DropEvent

newtype AllowDrop Source #

Related to using drop-related events

Constructors

AllowDrop Bool 

Options

data Options Source #

Options for handling event propagation.

Constructors

Options 
Instances
Eq Options Source # 
Instance details

Defined in Miso.Event.Types

Show Options Source # 
Instance details

Defined in Miso.Event.Types

Generic Options Source # 
Instance details

Defined in Miso.Event.Types

Associated Types

type Rep Options :: Type -> Type Source #

ToJSVal Options Source # 
Instance details

Defined in Miso.Event.Types

type Rep Options Source # 
Instance details

Defined in Miso.Event.Types

type Rep Options = D1 (MetaData "Options" "Miso.Event.Types" "miso-1.9.0.0-ZJqKd2LHjaBpN766aHKPE" False) (C1 (MetaCons "Options" PrefixI True) (S1 (MetaSel (Just "preventDefault") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool) :*: S1 (MetaSel (Just "stopPropagation") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool)))

defaultOptions :: Options Source #

Default value for Options.

defaultOptions = Options { preventDefault = False, stopPropagation = False }

Events

defaultEvents :: Map MisoString Bool Source #

Default delegated events

Html

Elements

Smart constructors

nodeHtml :: MisoString -> [Attribute action] -> [View action] -> View action Source #

Used to construct Node in View

nodeHtmlKeyed :: MisoString -> Key -> [Attribute action] -> [View action] -> View action Source #

Construct a node with a Key

Combinators

liKeyed_ :: Key -> [Attribute action] -> [View action] -> View action Source #

Contains Key, inteded to be used for child replacement patch

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li

script_ :: [Attribute action] -> MisoString -> View action Source #

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script

This takes the raw text to be put in the script tag.

That means that if any part of the text is not trusted there's a potential JavaScript injection. Read more at https://owasp.org/www-community/attacks/xss/

You can also easily shoot yourself in the foot with something like:

script_ [] "</script>"

style_ :: Map MisoString MisoString -> Attribute action Source #

style_ attrs is an attribute that will set the style attribute of the associated DOM node to attrs.

style attributes not contained in attrs will be deleted.

import qualified Data.Map as M
div_ [ style_  $ M.singleton "background" "red" ] [ ]

https://developer.mozilla.org/en-US/docs/Web/CSS

style :: [Attribute action] -> MisoString -> View action Source #

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style

This takes the raw text to be put in the style tag.

That means that if any part of the text is not trusted there's a potential CSS injection. Read more at https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/11-Client_Side_Testing/05-Testing_for_CSS_Injection

You can also easily shoot yourself in the foot with something like:

style_ [] "</style>"

form :: [Attribute action] -> [View action] -> View action Source #

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form

For usage in a real-world application with the onSubmit event.

view :: Model -> View action
view model = form [ onSubmit NoOp ] [ input [ type_ "submit" ] ]

Note: onSubmit will use preventDefault = True. This will keep the form from submitting to the server.

trKeyed_ :: Key -> [Attribute action] -> [View action] -> View action Source #

Contains Key, inteded to be used for child replacement patch

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr

Attributes

Smart constructors

textProp :: MisoString -> MisoString -> Attribute action Source #

Set field to Text value

stringProp :: MisoString -> String -> Attribute action Source #

Set field to String value

boolProp :: MisoString -> Bool -> Attribute action Source #

Set field to Bool value

intProp :: MisoString -> Int -> Attribute action Source #

Set field to Int value

integerProp :: MisoString -> Int -> Attribute action Source #

Set field to Integer value

doubleProp :: MisoString -> Double -> Attribute action Source #

Set field to Double value

Combinators

classList_ :: [(MisoString, Bool)] -> Attribute action Source #

Define multiple classes conditionally

div_ [ classList_ [ ("empty", null items) ] [ ]

styleInline_ :: MisoString -> Attribute action Source #

Set "style" property

view m = div_ [ styleInline_ "background-color:red;color:blue;" ] [ "foo" ]

https://developer.mozilla.org/en-US/docs/Web/CSS

Events

Smart constructors

on :: MisoString -> Decoder r -> (r -> action) -> Attribute action Source #

Convenience wrapper for onWithOptions defaultOptions.

let clickHandler = on "click" emptyDecoder $ \() -> Action
in button_ [ clickHandler, class_ "add" ] [ text_ "+" ]

onWithOptions :: Options -> MisoString -> Decoder r -> (r -> action) -> Attribute action Source #

onWithOptions opts eventName decoder toAction is an attribute that will set the event handler of the associated DOM node to a function that decodes its argument using decoder, converts it to an action using toAction and then feeds that action back to the update function.

opts can be used to disable further event propagation.

let clickHandler = onWithOptions defaultOptions "click" emptyDecoder $ \() -> Action
in button_ [ clickHandler, class_ "add" ] [ text_ "+" ]

Lifecycle events

onMounted :: action -> Attribute action Source #

onMounted action is an event that gets called after the actual DOM element is created.

Important note: Any node that uses this event MUST have a unique Key, otherwise the event may not be reliably called!

onUnmounted :: action -> Attribute action Source #

onUnmounted action is an event that gets called before the DOM element is removed from the DOM. The action is given the DOM element that was removed from the DOM tree.

Important note: Any node that uses this event MUST have a unique Key, otherwise the event may not be reliably called!

onCreated :: action -> Attribute action Source #

onCreated action is an event that gets called after the actual DOM element is created.

Important note: Any node that uses this event MUST have a unique Key, otherwise the event may not be reliably called!

onDestroyed :: action -> Attribute action Source #

onDestroyed action is an event that gets called after the DOM element is removed from the DOM. The action is given the DOM element that was removed from the DOM tree.

Important note: Any node that uses this event MUST have a unique Key, otherwise the event may not be reliably called!

onBeforeDestroyed :: action -> Attribute action Source #

onBeforeDestroyed action is an event that gets called before the DOM element is removed from the DOM. The action is given the DOM element that was removed from the DOM tree.

Important note: Any node that uses this event MUST have a unique Key, otherwise the event may not be reliably called!

Mouse

Keyboard

Form

Focus

onBlur :: action -> Attribute action Source #

blur event defined with custom options

https://developer.mozilla.org/en-US/docs/Web/Events/blur

Drag

Drop

Select

Pointer

Virtual DOM

Types

newtype VTree Source #

Virtual DOM implemented as a JavaScript Object. Used for diffing, patching and event delegation. Not meant to be constructed directly, see View instead.

Constructors

VTree 

Fields

data View action Source #

Core type for constructing a virtual DOM in Haskell

Instances
Functor View Source # 
Instance details

Defined in Miso.Types

Methods

fmap :: (a -> b) -> View a -> View b Source #

(<$) :: a -> View b -> View a Source #

IsString (View a) Source #

IsString instance

Instance details

Defined in Miso.Types

Methods

fromString :: String -> View a Source #

ToView (View action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (View action) :: Type Source #

Methods

toView :: View action -> View (ToViewAction (View action)) Source #

ToHtml [View a] Source #

Render a [View] to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: [View a] -> ByteString Source #

ToHtml (View a) Source #

Render a View to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: View a -> ByteString Source #

HasRouter (View a) Source #

View

Instance details

Defined in Miso.Router

Associated Types

type RouteT (View a) a :: Type Source #

Methods

mkRouter :: Proxy (View a) -> Proxy a0 -> RouteT (View a) a0 -> Router a0 Source #

HasLink (View a :: Type) Source #

For constructing type-safe links

Instance details

Defined in Miso.Types

Associated Types

type MkLink (View a) a :: Type Source #

Methods

toLink :: (Link -> a0) -> Proxy (View a) -> Link -> MkLink (View a) a0 Source #

type ToViewAction (View action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action
type RouteT (View a) x Source # 
Instance details

Defined in Miso.Router

type RouteT (View a) x = x
type MkLink (View a :: Type) b Source # 
Instance details

Defined in Miso.Types

type MkLink (View a :: Type) b = b

data Attribute action Source #

Attribute of a vnode in a View.

The Sink callback can be used to dispatch actions which are fed back to the update function. This is especially useful for event handlers like the onclick attribute. The second argument represents the vnode the attribute is attached to.

Instances
Functor Attribute Source # 
Instance details

Defined in Miso.Types

Methods

fmap :: (a -> b) -> Attribute a -> Attribute b Source #

(<$) :: a -> Attribute b -> Attribute a Source #

newtype Key Source #

A unique key for a dom node.

This key is only used to speed up diffing the children of a DOM node, the actual content is not important. The keys of the children of a given DOM node must be unique. Failure to satisfy this invariant gives undefined behavior at runtime.

Constructors

Key MisoString 
Instances
ToJSVal Key Source #

ToJSVal instance for Key

Instance details

Defined in Miso.Types

ToKey Key Source #

Identity instance

Instance details

Defined in Miso.Types

Methods

toKey :: Key -> Key Source #

data NS Source #

Namespace of DOM elements.

Constructors

HTML

HTML Namespace

SVG

SVG Namespace

MATHML

MATHML Namespace

Instances
Eq NS Source # 
Instance details

Defined in Miso.Types

Methods

(==) :: NS -> NS -> Bool Source #

(/=) :: NS -> NS -> Bool Source #

Show NS Source # 
Instance details

Defined in Miso.Types

ToJSVal NS Source # 
Instance details

Defined in Miso.Types

Classes

class ToView a where Source #

Convenience class for using View

Associated Types

type ToViewAction a :: Type Source #

Methods

toView :: a -> View (ToViewAction a) Source #

Instances
ToView (View action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (View action) :: Type Source #

Methods

toView :: View action -> View (ToViewAction (View action)) Source #

ToView (Component effect model action a) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (Component effect model action a) :: Type Source #

Methods

toView :: Component effect model action a -> View (ToViewAction (Component effect model action a)) Source #

ToView (App effect model action a) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (App effect model action a) :: Type Source #

Methods

toView :: App effect model action a -> View (ToViewAction (App effect model action a)) Source #

Combinators

node :: NS -> MisoString -> Maybe Key -> [Attribute action] -> [View action] -> View action Source #

Create a new Miso.Html.Types.Node.

node ns tag key attrs children creates a new node with tag tag and Key key in the namespace ns. All attrs are called when the node is created and its children are initialized to children.

text :: MisoString -> View action Source #

Create a new Text with the given content.

textRaw :: MisoString -> View action Source #

TextRaw creation. Don't use directly

rawHtml :: MisoString -> View action Source #

Create a new Miso.Html.Types.TextRaw.

expandable a rawHtml node takes raw HTML and attempts to convert it to a VTree at runtime. This is a way to dynamically populate the virtual DOM from HTML received at runtime. If rawHtml cannot parse the HTML it will not render.

prop :: ToJSON a => MisoString -> a -> Attribute action Source #

prop k v is an attribute that will set the attribute k of the DOM node associated with the vnode to v.

style_ :: Map MisoString MisoString -> Attribute action Source #

style_ attrs is an attribute that will set the style attribute of the associated DOM node to attrs.

style attributes not contained in attrs will be deleted.

import qualified Data.Map as M
div_ [ style_  $ M.singleton "background" "red" ] [ ]

https://developer.mozilla.org/en-US/docs/Web/CSS

Classes

class ToHtml a where Source #

Class for rendering HTML

Methods

toHtml :: a -> ByteString Source #

Instances
ToHtml [View a] Source #

Render a [View] to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: [View a] -> ByteString Source #

ToHtml (View a) Source #

Render a View to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: View a -> ByteString Source #

ToHtml (Component effect model action a) Source #

Render a Component to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: Component effect model action a -> ByteString Source #

Combinator

data HTML Source #

HTML MimeType used for servant APIs

type Home = "home" :> Get '[HTML] (Component model action)
Instances
Accept HTML Source #
text/html;charset=utf-8
Instance details

Defined in Miso.Render

ToHtml a => MimeRender HTML a Source #

Render HTML from a servant API

Instance details

Defined in Miso.Render

Mathml

Combinator

nodeMathml :: MisoString -> [Attribute action] -> [View action] -> View action Source #

Used to construct Node in View

Router

Classes

class HasRouter layout where Source #

This is similar to the HasServer class from servant-server. It is the class responsible for making API combinators routable. RouteT is used to build up the handler types. Router is returned.

Associated Types

type RouteT layout a :: Type Source #

Type family for route dispatch

Methods

mkRouter :: Proxy layout -> Proxy a -> RouteT layout a -> Router a Source #

Transform a mkRouter handler into a Router.

Instances
HasRouter Raw Source #

Raw

Instance details

Defined in Miso.Router

Associated Types

type RouteT Raw a :: Type Source #

Methods

mkRouter :: Proxy Raw -> Proxy a -> RouteT Raw a -> Router a Source #

HasRouter (View a) Source #

View

Instance details

Defined in Miso.Router

Associated Types

type RouteT (View a) a :: Type Source #

Methods

mkRouter :: Proxy (View a) -> Proxy a0 -> RouteT (View a) a0 -> Router a0 Source #

(HasRouter x, HasRouter y) => HasRouter (x :<|> y) Source #

Alternative

Instance details

Defined in Miso.Router

Associated Types

type RouteT (x :<|> y) a :: Type Source #

Methods

mkRouter :: Proxy (x :<|> y) -> Proxy a -> RouteT (x :<|> y) a -> Router a Source #

(HasRouter sublayout, FromHttpApiData x, KnownSymbol sym) => HasRouter (QueryParam sym x :> sublayout) Source #

QueryParam

Instance details

Defined in Miso.Router

Associated Types

type RouteT (QueryParam sym x :> sublayout) a :: Type Source #

Methods

mkRouter :: Proxy (QueryParam sym x :> sublayout) -> Proxy a -> RouteT (QueryParam sym x :> sublayout) a -> Router a Source #

(HasRouter sublayout, FromHttpApiData x, KnownSymbol sym) => HasRouter (QueryParams sym x :> sublayout) Source #

QueryParams

Instance details

Defined in Miso.Router

Associated Types

type RouteT (QueryParams sym x :> sublayout) a :: Type Source #

Methods

mkRouter :: Proxy (QueryParams sym x :> sublayout) -> Proxy a -> RouteT (QueryParams sym x :> sublayout) a -> Router a Source #

(HasRouter sublayout, KnownSymbol sym) => HasRouter (QueryFlag sym :> sublayout) Source #

QueryFlag

Instance details

Defined in Miso.Router

Associated Types

type RouteT (QueryFlag sym :> sublayout) a :: Type Source #

Methods

mkRouter :: Proxy (QueryFlag sym :> sublayout) -> Proxy a -> RouteT (QueryFlag sym :> sublayout) a -> Router a Source #

HasRouter sublayout => HasRouter (Header sym x :> sublayout) Source #

Header

Instance details

Defined in Miso.Router

Associated Types

type RouteT (Header sym x :> sublayout) a :: Type Source #

Methods

mkRouter :: Proxy (Header sym x :> sublayout) -> Proxy a -> RouteT (Header sym x :> sublayout) a -> Router a Source #

(HasRouter sublayout, FromHttpApiData x) => HasRouter (Capture sym x :> sublayout) Source #

Capture

Instance details

Defined in Miso.Router

Associated Types

type RouteT (Capture sym x :> sublayout) a :: Type Source #

Methods

mkRouter :: Proxy (Capture sym x :> sublayout) -> Proxy a -> RouteT (Capture sym x :> sublayout) a -> Router a Source #

(HasRouter sublayout, KnownSymbol path) => HasRouter (path :> sublayout) Source #

Path

Instance details

Defined in Miso.Router

Associated Types

type RouteT (path :> sublayout) a :: Type Source #

Methods

mkRouter :: Proxy (path :> sublayout) -> Proxy a -> RouteT (path :> sublayout) a -> Router a Source #

HasRouter (Verb m s c a) Source #

Verb

Instance details

Defined in Miso.Router

Associated Types

type RouteT (Verb m s c a) a :: Type Source #

Methods

mkRouter :: Proxy (Verb m s c a) -> Proxy a0 -> RouteT (Verb m s c a) a0 -> Router a0 Source #

Types

data Router a Source #

A Router contains the information necessary to execute a handler.

Routing

route :: HasRouter layout => Proxy layout -> RouteT layout (m -> a) -> (m -> URI) -> m -> Either RoutingError a Source #

Executes router This is most likely the function you want to use. See haskell-miso.orgsharedCommon.hs for usage.

Run

Live reload

run :: JSM () -> IO () Source #

Entry point for a miso application When compiling with jsaddle on native platforms run will start a web server for live reload of your miso application.

When compiling to WASM use 'jsaddle-wasm'. When compiling to JS no special package is required (simply the id function). JSM becomes a type synonym for IO

Exception

Types

data MisoException Source #

The MisoException type is used to catch Component-related mounting errors.

The two mounting errors that can occur during the lifetime of a miso application are

  • Not Mounted Exception

This occurs if a user tries to call sample myComponent when myComponent is currently not mounted on the DOM.

  • Already Mounted Exception

It is a requirement that all Component be named uniquely (this is to avoid runaway recursion during mounting). If we detect a Component is attempting to be mounted twice this exception will be raised.

Other exceptions can arise, but its up to the user to handle them in the update function. All unhandled exceptions are caught in the event loop and logged to the console with console.error()

Constructors

NotMountedException MisoString

Thrown when a Component is sampled, yet not mounted.

AlreadyMountedException MisoString

Thrown when a Component is attempted to be mounted twice.

Functions

exception :: SomeException -> JSM JSVal Source #

Exception handler

Used to catch Component mounting exceptions

action `catch` exception

Subs

Mouse

Subscription

mouseSub :: (PointerEvent -> action) -> Sub action Source #

Captures mouse coordinates as they occur and writes them to an event sink

Keyboard

Types

data Arrows Source #

type for arrow keys currently pressed 37 left arrow ( x = -1 ) 38 up arrow ( y = 1 ) 39 right arrow ( x = 1 ) 40 down arrow ( y = -1 )

Constructors

Arrows 

Fields

Instances
Eq Arrows Source # 
Instance details

Defined in Miso.Subscription.Keyboard

Show Arrows Source # 
Instance details

Defined in Miso.Subscription.Keyboard

Subscriptions

arrowsSub :: (Arrows -> action) -> Sub action Source #

Maps Arrows onto a Keyboard subscription

directionSub :: ([Int], [Int], [Int], [Int]) -> (Arrows -> action) -> Sub action Source #

Maps a specified list of keys to directions (up, down, left, right)

keyboardSub :: (Set Int -> action) -> Sub action Source #

Returns subscription for Keyboard

wasdSub :: (Arrows -> action) -> Sub action Source #

Maps Arrows onto a Keyboard subscription for directions (W+A+S+D keys)

History

Subscription

uriSub :: (URI -> action) -> Sub action Source #

Subscription for popstate events, from the History API

Functions

getCurrentURI :: JSM URI Source #

Retrieves current URI of page

pushURI :: URI -> JSM () Source #

Pushes a new URI onto the History stack

replaceURI :: URI -> JSM () Source #

Replaces current URI on stack

back :: JSM () Source #

Navigates backwards

forward :: JSM () Source #

Navigates forwards

go :: Int -> JSM () Source #

Jumps to a specific position in history

Types

data URI Source #

Represents a general universal resource identifier using its component parts.

For example, for the URI

  foo://anonymous@www.haskell.org:42/ghc?query#frag

the components are:

Constructors

URI 

Fields

Instances
Eq URI 
Instance details

Defined in Network.URI

Methods

(==) :: URI -> URI -> Bool Source #

(/=) :: URI -> URI -> Bool Source #

Data URI 
Instance details

Defined in Network.URI

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> URI -> c URI Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c URI Source #

toConstr :: URI -> Constr Source #

dataTypeOf :: URI -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c URI) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c URI) Source #

gmapT :: (forall b. Data b => b -> b) -> URI -> URI Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> URI -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> URI -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> URI -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> URI -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> URI -> m URI Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> URI -> m URI Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> URI -> m URI Source #

Ord URI 
Instance details

Defined in Network.URI

Methods

compare :: URI -> URI -> Ordering Source #

(<) :: URI -> URI -> Bool Source #

(<=) :: URI -> URI -> Bool Source #

(>) :: URI -> URI -> Bool Source #

(>=) :: URI -> URI -> Bool Source #

max :: URI -> URI -> URI Source #

min :: URI -> URI -> URI Source #

Show URI 
Instance details

Defined in Network.URI

Generic URI 
Instance details

Defined in Network.URI

Associated Types

type Rep URI :: Type -> Type Source #

Methods

from :: URI -> Rep URI x Source #

to :: Rep URI x -> URI Source #

NFData URI 
Instance details

Defined in Network.URI

Methods

rnf :: URI -> () Source #

type Rep URI 
Instance details

Defined in Network.URI

Window

Subscription

windowSub :: MisoString -> Decoder r -> (r -> action) -> Sub action Source #

windowSub eventName decoder toAction provides a subscription to listen to window level events.

windowCoordsSub :: ((Int, Int) -> action) -> Sub action Source #

Captures window coordinates changes as they occur and writes them to an event sink

windowPointerMoveSub :: (PointerEvent -> action) -> Sub action Source #

window.addEventListener ("pointermove", (event) => handle(event)) A Sub for handler PointerEvent on window

windowSubWithOptions :: Options -> MisoString -> Decoder r -> (r -> action) -> Sub action Source #

windowSubWithOptions options eventName decoder toAction provides a subscription to listen to window level events.

Websocket

Types

data WebSocket action Source #

WebSocket connection messages

Instances
Eq action => Eq (WebSocket action) Source # 
Instance details

Defined in Miso.WebSocket

Methods

(==) :: WebSocket action -> WebSocket action -> Bool Source #

(/=) :: WebSocket action -> WebSocket action -> Bool Source #

Show action => Show (WebSocket action) Source # 
Instance details

Defined in Miso.WebSocket

Methods

showsPrec :: Int -> WebSocket action -> ShowS Source #

show :: WebSocket action -> String Source #

showList :: [WebSocket action] -> ShowS Source #

newtype URL Source #

URL of Websocket server

Constructors

URL MisoString 
Instances
Eq URL Source # 
Instance details

Defined in Miso.WebSocket

Methods

(==) :: URL -> URL -> Bool Source #

(/=) :: URL -> URL -> Bool Source #

Show URL Source # 
Instance details

Defined in Miso.WebSocket

newtype Protocols Source #

Protocols for Websocket connection

Constructors

Protocols [MisoString] 
Instances
Eq Protocols Source # 
Instance details

Defined in Miso.WebSocket

Show Protocols Source # 
Instance details

Defined in Miso.WebSocket

data CloseCode Source #

Code corresponding to a closed connection https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent

Constructors

CLOSE_NORMAL

1000, Normal closure; the connection successfully completed whatever purpose for which it was created.

CLOSE_GOING_AWAY

1001, The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection.

CLOSE_PROTOCOL_ERROR

1002, The endpoint is terminating the connection due to a protocol error.

CLOSE_UNSUPPORTED

1003, The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a textonly endpoint received binary data).

CLOSE_NO_STATUS

1005, Reserved. Indicates that no status code was provided even though one was expected.

CLOSE_ABNORMAL

1006, Reserved. Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected.

Unsupported_Data

1007, The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., nonUTF8 data within a text message).

Policy_Violation

1008, The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable.

CLOSE_TOO_LARGE

1009, The endpoint is terminating the connection because a data frame was received that is too large.

Missing_Extension

1010, The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't.

Internal_Error

1011, The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

Service_Restart

1012, The server is terminating the connection because it is restarting.

Try_Again_Later

1013, The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients.

TLS_Handshake

1015, Reserved. Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).

OtherCode Int

OtherCode that is reserved and not in the range 0999

Instances
Eq CloseCode Source # 
Instance details

Defined in Miso.WebSocket

Show CloseCode Source # 
Instance details

Defined in Miso.WebSocket

Generic CloseCode Source # 
Instance details

Defined in Miso.WebSocket

Associated Types

type Rep CloseCode :: Type -> Type Source #

ToJSVal CloseCode Source # 
Instance details

Defined in Miso.WebSocket

FromJSVal CloseCode Source # 
Instance details

Defined in Miso.WebSocket

type Rep CloseCode Source # 
Instance details

Defined in Miso.WebSocket

type Rep CloseCode = D1 (MetaData "CloseCode" "Miso.WebSocket" "miso-1.9.0.0-ZJqKd2LHjaBpN766aHKPE" False) (((C1 (MetaCons "CLOSE_NORMAL" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "CLOSE_GOING_AWAY" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "CLOSE_PROTOCOL_ERROR" PrefixI False) (U1 :: Type -> Type))) :+: ((C1 (MetaCons "CLOSE_UNSUPPORTED" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "CLOSE_NO_STATUS" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "CLOSE_ABNORMAL" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Unsupported_Data" PrefixI False) (U1 :: Type -> Type)))) :+: (((C1 (MetaCons "Policy_Violation" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "CLOSE_TOO_LARGE" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "Missing_Extension" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Internal_Error" PrefixI False) (U1 :: Type -> Type))) :+: ((C1 (MetaCons "Service_Restart" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "Try_Again_Later" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "TLS_Handshake" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "OtherCode" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int))))))

newtype WasClean Source #

Wether or not the connection closed was done so cleanly

Constructors

WasClean Bool 
Instances
Eq WasClean Source # 
Instance details

Defined in Miso.WebSocket

Show WasClean Source # 
Instance details

Defined in Miso.WebSocket

newtype Reason Source #

Reason for closed connection

Constructors

Reason MisoString 
Instances
Eq Reason Source # 
Instance details

Defined in Miso.WebSocket

Show Reason Source # 
Instance details

Defined in Miso.WebSocket

Subscription

websocketSub :: FromJSON m => URL -> Protocols -> (WebSocket m -> action) -> Sub action Source #

WebSocket subscription

send :: ToJSON a => a -> JSM () Source #

Sends message to a websocket server

close :: JSM () Source #

Sends message to a websocket server

connect :: URL -> Protocols -> JSM () Source #

Connects to a websocket server

getSocketState :: JSM SocketState Source #

Retrieves current status of WebSocket

SSE

Subscription

sseSub :: FromJSON msg => MisoString -> (SSE msg -> action) -> Sub action Source #

Server-sent events Subscription

Types

data SSE message Source #

Server-sent events data

Constructors

SSEMessage message 
SSEClose 
SSEError 
Instances
Eq message => Eq (SSE message) Source # 
Instance details

Defined in Miso.Subscription.SSE

Methods

(==) :: SSE message -> SSE message -> Bool Source #

(/=) :: SSE message -> SSE message -> Bool Source #

Show message => Show (SSE message) Source # 
Instance details

Defined in Miso.Subscription.SSE

Methods

showsPrec :: Int -> SSE message -> ShowS Source #

show :: SSE message -> String Source #

showList :: [SSE message] -> ShowS Source #

Storage

Local

getLocalStorage :: FromJSON model => MisoString -> JSM (Either String model) Source #

Retrieve a value stored under given key in local storage

setLocalStorage :: ToJSON model => MisoString -> model -> JSM () Source #

Set the value of a key in local storage.

setLocalStorage key value sets the value of key to value.

removeLocalStorage :: MisoString -> JSM () Source #

Removes an item from local storage

removeLocalStorage key removes the value of key.

clearLocalStorage :: JSM () Source #

Clear local storage

clearLocalStorage removes all values from local storage.

localStorageLength :: JSM Int Source #

Local storage length

localStorageLength returns the count of items in local storage

Session

getSessionStorage :: FromJSON model => MisoString -> JSM (Either String model) Source #

Retrieve a value stored under given key in session storage

setSessionStorage :: ToJSON model => MisoString -> model -> JSM () Source #

Set the value of a key in session storage.

setSessionStorage key value sets the value of key to value.

removeSessionStorage :: MisoString -> JSM () Source #

Removes an item from session storage.

removeSessionStorage key removes the value of key.

clearSessionStorage :: JSM () Source #

Clear session storage

clearSessionStorage removes all values from session storage.

sessionStorageLength :: JSM Int Source #

Session storage length

sessionStorageLength returns the count of items in session storage

Util

withFoldable :: Foldable t => t a -> (a -> b) -> [b] Source #

Generic map function, useful for creating Views from the elements of some Foldable. Particularly handy for Maybe, as shown in the example below.

view model =
    div_ [] $
     withFoldable (model ^. mSomeMaybeVal) $ someVal ->
        p_ [] [ text $ "Hey, look at this value: " <> ms (show someVal) ]

conditionalViews :: Bool -> [View action] -> [View action] Source #

Hides the Views the condition is False. Shows them when the condition is True.

(=:) :: k -> a -> Map k a Source #

Smart constructor for Attributes. This function is helpful when constructing numerous Attributes Example shown below.

div_ [ style_  $ ("background" =: "red" <> "width" =: "250px" <> "height" =: "250px") ] []

FFI

set :: ToJSVal v => MisoString -> v -> Object -> JSM () Source #

Set property on object

consoleLog :: MisoString -> JSM () Source #

Outputs a message to the web console

See https://developer.mozilla.org/en-US/docs/Web/API/Console/log

Console logging of JavaScript strings.

consoleLog' :: JSVal -> JSM () Source #

Console-logging of JSVal

consoleError :: MisoString -> JSM () Source #

Outputs an error message to the web console

See https://developer.mozilla.org/en-US/docs/Web/API/Console/error

Console logging of JavaScript strings.

consoleWarn :: MisoString -> JSM () Source #

Outputs a warning message to the web console

See https://developer.mozilla.org/en-US/docs/Web/API/Console/warn

Console logging of JavaScript strings.

getElementById :: MisoString -> JSM JSVal Source #

Returns an Element object representing the element whose id property matches the specified string.

See https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById

focus :: MisoString -> JSM () Source #

Fails silently if the element is not found.

Analogous to document.getElementById(id).focus().

blur :: MisoString -> JSM () Source #

Fails silently if the element is not found.

Analogous to document.getElementById(id).blur()

alert :: MisoString -> JSM () Source #

Calls the alert() function.

reload :: JSM () Source #

Calls the location.reload() function.