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

Miso

Description

 
Synopsis

API

Entry

miso :: Eq model => (URI -> App model action) -> 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.

(🍜) :: Eq model => (URI -> App model action) -> JSM () Source #

Alias for miso.

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

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

Sink

withSink :: (Sink action -> JSM ()) -> Effect model action Source #

sink allows users to access the sink of the Component or top-level App in their application. This is useful for introducing IO into the system.

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.

update FetchJSON = withSink $ \sink -> getJSON (sink . ReceivedJSON) (sink . HandleError)

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

Function to asynchronously dispatch actions to the update function.

Sampling

sample :: Component model action -> 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 model action -> action -> JSM () Source #

Used for bidirectional communication between components. Specify the mounted Component's App you'd like to target. This function is used to send messages to Components on other parts of the application

Subscription

start :: SubName -> Sub action -> Effect action model Source #

start

Starts a named Sub dynamically, during the life of a Component. The Sub can be stopped by calling stop subName from the update function. All Sub started will be stopped if a Component is unmounted.

start_ :: Sub action -> Effect action model Source #

start_

Starts an unnamed Sub dynamically, during the lifetime of a Component.

Sub that are unnamed have their names autogenerated and cannot be stopped. This is useful for long-running actions that do not need to be stopped.

stop :: SubName -> Effect action model Source #

stop

Stops a named Sub dynamically, during the life of a Component. All Sub started will be stopped automatically if a Component is unmounted.

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 into the update function.

type SubName = MisoString Source #

SubName The name of a Sub (e.g. "websocket")

Effect

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

batch :: [JSM action] -> Effect model action Source #

Smart constructor for an Effect with multiple actions.

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

Like io_ 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.

io_ :: 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.

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

Like io but generalized to any instance of Foldable

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

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

Smart constructor for Component construction. Needed when calling embed and embedWith

component_ :: App model action -> Component model action Source #

Smart constructor for Component construction. This is a nameless component, which means that it is isolated and cannot be communicated with by other components via notify or sample.

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

Smart constructor for App with sane defaults.

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

Used in the view function to embed Components in App

embedKeyed :: Eq model => Component model action -> [Attribute b] -> Key -> 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

data App model action Source #

Application entry point

Constructors

App 

Fields

  • model :: model

    initial model

  • update :: action -> Effect model action

    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 Capture

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

  • styles :: [CSS]

    List of CSS styles expressed as either a URL (Href) or as Style text. These styles are appended dynamically to the head section of your HTML page before the initial draw on body occurs.

  • initialAction :: Maybe action

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

    Since: 1.9.0.0

  • 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

Instances

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

Defined in Miso.Types

Associated Types

type ToViewAction (App model action) 
Instance details

Defined in Miso.Types

type ToViewAction (App model action) = action

Methods

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

type ToViewAction (App model action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (App model action) = action

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

Instances details
Functor Attribute Source # 
Instance details

Defined in Miso.Types

Methods

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

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

data CSS Source #

Allow users to express CSS and append it to head before the first draw

Href "http://domain.com/style.css

Constructors

Href MisoString

Href is a URL meant to link to hosted CSS

Style MisoString

Style is meant to be raw CSS in a style_ tag

Instances

Instances details
Show CSS Source # 
Instance details

Defined in Miso.Types

Methods

showsPrec :: Int -> CSS -> ShowS #

show :: CSS -> String #

showList :: [CSS] -> ShowS #

Eq CSS Source # 
Instance details

Defined in Miso.Types

Methods

(==) :: CSS -> CSS -> Bool #

(/=) :: CSS -> CSS -> Bool #

data Component model action Source #

A Component wraps an App and can be communicated with via componentName when using notify. Its state is accessible via sample.

Constructors

Component 

Instances

Instances details
ToHtml (Component model action) Source #

Render a Component to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: Component model action -> ByteString Source #

ToView (Component model action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (Component model action) 
Instance details

Defined in Miso.Types

type ToViewAction (Component model action) = action

Methods

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

type ToViewAction (Component model action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (Component model action) = action

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

Instances details
IsString Key Source # 
Instance details

Defined in Miso.Types

Methods

fromString :: String -> Key #

Show Key Source # 
Instance details

Defined in Miso.Types

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String #

showList :: [Key] -> ShowS #

Eq Key Source # 
Instance details

Defined in Miso.Types

Methods

(==) :: Key -> Key -> Bool #

(/=) :: Key -> Key -> Bool #

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 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

Instances details
Show LogLevel Source # 
Instance details

Defined in Miso.Types

Eq LogLevel Source # 
Instance details

Defined in Miso.Types

data NS Source #

Namespace of DOM elements.

Constructors

HTML

HTML Namespace

SVG

SVG Namespace

MATHML

MATHML Namespace

Instances

Instances details
Show NS Source # 
Instance details

Defined in Miso.Types

Methods

showsPrec :: Int -> NS -> ShowS #

show :: NS -> String #

showList :: [NS] -> ShowS #

Eq NS Source # 
Instance details

Defined in Miso.Types

Methods

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

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

ToJSVal NS Source # 
Instance details

Defined in Miso.Types

data SomeComponent Source #

Existential wrapper used to allow the nesting of Component in App

Constructors

Eq model => SomeComponent (Component model action) 

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

Instances details
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 #

ToKey Text Source #

Convert T.Text to Key

Instance details

Defined in Miso.Types

Methods

toKey :: Text -> Key Source #

ToKey String Source #

Convert String to Key

Instance details

Defined in Miso.Types

Methods

toKey :: String -> Key Source #

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 #

class ToView a where Source #

Convenience class for using View

Associated Types

type ToViewAction a Source #

Methods

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

Instances

Instances details
ToView (View action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (View action) 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action

Methods

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

ToView (App model action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (App model action) 
Instance details

Defined in Miso.Types

type ToViewAction (App model action) = action

Methods

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

ToView (Component model action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (Component model action) 
Instance details

Defined in Miso.Types

type ToViewAction (Component model action) = action

Methods

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

type family ToViewAction a Source #

Instances

Instances details
type ToViewAction (View action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action
type ToViewAction (App model action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (App model action) = action
type ToViewAction (Component model action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (Component model action) = action

data View action Source #

Core type for constructing a virtual DOM in Haskell

Instances

Instances details
Functor View Source # 
Instance details

Defined in Miso.Types

Methods

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

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

HasRouter (View a :: Type) Source #

View

Instance details

Defined in Miso.Router

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

Methods

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

IsString (View a) Source #

IsString instance

Instance details

Defined in Miso.Types

Methods

fromString :: String -> View a #

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 #

ToView (View action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (View action) 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action

Methods

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

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

Defined in Miso.Router

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

Defined in Miso.Types

type MkLink (View a :: Type) b = b
type ToViewAction (View action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action

Effect

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

Effect smart constructor, flipped

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

Smart constructor for an Effect with exactly one action.

batch :: [JSM action] -> Effect model action Source #

Smart constructor for an Effect with multiple actions.

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

Deprecated: Please use put and batch instead

effectSub :: model -> (Sink action -> JSM ()) -> Effect model action Source #

Deprecated: Please use put and withSink instead

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

Like io but generalized to any instance of Foldable

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

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

Like io_ 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.

io_ :: 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.

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

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

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

noEff :: model -> Effect model action Source #

Deprecated: Please use put instead

runEffect :: Effect model action -> MisoString -> model -> (model, [Sink action -> JSM ()]) Source #

Internal function used to unwrap an EffectCore

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

Deprecated: Please use io_ instead

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

Deprecated: Please use for instead

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

Deprecated: Please use io instead

scheduleSub :: (Sink action -> JSM ()) -> Effect model action Source #

Deprecated: Please use withSink instead

withSink :: (Sink action -> JSM ()) -> Effect model action Source #

sink allows users to access the sink of the Component or top-level App in their application. This is useful for introducing IO into the system.

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.

update FetchJSON = withSink $ \sink -> getJSON (sink . ReceivedJSON) (sink . HandleError)

type Effect model action = EffectCore model action () Source #

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

Effect is a RWS, where the State 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!"
  , ...
  }

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

Function to asynchronously dispatch actions to the update function.

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 into the update function.

type SubName = MisoString Source #

SubName The name of a Sub (e.g. "websocket")

Event

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

Smart constructor for building a Decoder.

checkedDecoder :: Decoder Checked Source #

Retrieves "checked" field in Decoder

emptyDecoder :: Decoder () Source #

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

keyInfoDecoder :: Decoder KeyInfo Source #

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

keycodeDecoder :: Decoder KeyCode Source #

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

pointerDecoder :: Decoder PointerEvent Source #

Pointer decoder for use with events like "onpointerover"

valueDecoder :: Decoder MisoString Source #

Retrieves "value" field in Decoder

defaultEvents :: Map MisoString Capture Source #

Default delegated events

defaultOptions :: Options Source #

Default value for Options.

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

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.

Instances

Instances details
ToJSVal DecodeTarget Source #

ToJSVal instance for Decoder

Instance details

Defined in Miso.Event.Decoder

data Decoder a Source #

Decoder data type for parsing events

Constructors

Decoder 

Fields

newtype AllowDrop Source #

Related to using drop-related events

Constructors

AllowDrop Bool 

Instances

Instances details
FromJSON AllowDrop Source # 
Instance details

Defined in Miso.Event.Types

Show AllowDrop Source # 
Instance details

Defined in Miso.Event.Types

Eq AllowDrop Source # 
Instance details

Defined in Miso.Event.Types

type Capture = Bool Source #

Capture

Used to determine if *capture* should be set when using addEventListener

https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#capture

newtype Checked Source #

Type used for Checkbox events.

Constructors

Checked Bool 

Instances

Instances details
FromJSON Checked Source # 
Instance details

Defined in Miso.Event.Types

Show Checked Source # 
Instance details

Defined in Miso.Event.Types

Eq Checked Source # 
Instance details

Defined in Miso.Event.Types

Methods

(==) :: Checked -> Checked -> Bool #

(/=) :: Checked -> Checked -> Bool #

Ord Checked Source # 
Instance details

Defined in Miso.Event.Types

type Events = Map MisoString Capture Source #

Convenience type for Events

newtype KeyCode Source #

Constructors

KeyCode Int 

Instances

Instances details
FromJSON KeyCode Source # 
Instance details

Defined in Miso.Event.Types

Show KeyCode Source # 
Instance details

Defined in Miso.Event.Types

Eq KeyCode Source # 
Instance details

Defined in Miso.Event.Types

Methods

(==) :: KeyCode -> KeyCode -> Bool #

(/=) :: KeyCode -> KeyCode -> Bool #

Ord KeyCode Source # 
Instance details

Defined in Miso.Event.Types

data KeyInfo Source #

Type useful for both KeyCode and additional key press information.

Constructors

KeyInfo 

Fields

Instances

Instances details
Show KeyInfo Source # 
Instance details

Defined in Miso.Event.Types

Eq KeyInfo Source # 
Instance details

Defined in Miso.Event.Types

Methods

(==) :: KeyInfo -> KeyInfo -> Bool #

(/=) :: KeyInfo -> KeyInfo -> Bool #

data Options Source #

Options for handling event propagation.

Constructors

Options 

Instances

Instances details
Generic Options Source # 
Instance details

Defined in Miso.Event.Types

Associated Types

type Rep Options 
Instance details

Defined in Miso.Event.Types

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

Methods

from :: Options -> Rep Options x #

to :: Rep Options x -> Options #

Show Options Source # 
Instance details

Defined in Miso.Event.Types

Eq Options Source # 
Instance details

Defined in Miso.Event.Types

Methods

(==) :: Options -> Options -> Bool #

(/=) :: Options -> Options -> Bool #

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-inplace" 'False) (C1 ('MetaCons "Options" 'PrefixI 'True) (S1 ('MetaSel ('Just "preventDefault") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool) :*: S1 ('MetaSel ('Just "stopPropagation") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)))

data PointerEvent Source #

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

Constructors

PointerEvent 

Fields

Instances

Instances details
Show PointerEvent Source # 
Instance details

Defined in Miso.Event.Types

Eq PointerEvent Source # 
Instance details

Defined in Miso.Event.Types

Property

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

Set field to Bool value

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

Set field to Double value

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

Set field to Int value

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

Set field to Integer value

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.

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

Set field to String value

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

Set field to Text value

Html

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

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/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.

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/Reference/Elements/li

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

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

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/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_ :: [Attribute action] -> MisoString -> View action Source #

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/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>"

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/Reference/Elements/tr

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_ "+" ]

onBeforeCreated :: action -> Attribute action Source #

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

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.

onBeforeMounted :: action -> Attribute action Source #

onBeforeMounted action is an event that gets called before the actual DOM element is created.

onBeforeUnmounted :: action -> Attribute action Source #

onBeforeUnmounted action is an event that gets called before the DOM element is removed from the DOM.

onBlur :: action -> Attribute action Source #

blur event defined with custom options

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

onCreated :: action -> Attribute action Source #

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

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.

onMounted :: action -> Attribute action Source #

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

onUnmounted :: action -> Attribute action Source #

onUnmounted action is an event that gets called after the DOM element is removed from the DOM.

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_ "+" ]

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.

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.

text :: MisoString -> View action Source #

Create a new Text with the given content.

textRaw :: MisoString -> View action Source #

TextRaw creation. Don't use directly

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 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

Instances details
Functor Attribute Source # 
Instance details

Defined in Miso.Types

Methods

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

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

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

Instances details
IsString Key Source # 
Instance details

Defined in Miso.Types

Methods

fromString :: String -> Key #

Show Key Source # 
Instance details

Defined in Miso.Types

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String #

showList :: [Key] -> ShowS #

Eq Key Source # 
Instance details

Defined in Miso.Types

Methods

(==) :: Key -> Key -> Bool #

(/=) :: Key -> Key -> Bool #

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

Instances details
Show NS Source # 
Instance details

Defined in Miso.Types

Methods

showsPrec :: Int -> NS -> ShowS #

show :: NS -> String #

showList :: [NS] -> ShowS #

Eq NS Source # 
Instance details

Defined in Miso.Types

Methods

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

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

ToJSVal NS Source # 
Instance details

Defined in Miso.Types

class ToView a where Source #

Convenience class for using View

Associated Types

type ToViewAction a Source #

Methods

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

Instances

Instances details
ToView (View action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (View action) 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action

Methods

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

ToView (App model action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (App model action) 
Instance details

Defined in Miso.Types

type ToViewAction (App model action) = action

Methods

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

ToView (Component model action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (Component model action) 
Instance details

Defined in Miso.Types

type ToViewAction (Component model action) = action

Methods

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

type family ToViewAction a Source #

Instances

Instances details
type ToViewAction (View action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action
type ToViewAction (App model action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (App model action) = action
type ToViewAction (Component model action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (Component model action) = action

data View action Source #

Core type for constructing a virtual DOM in Haskell

Instances

Instances details
Functor View Source # 
Instance details

Defined in Miso.Types

Methods

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

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

HasRouter (View a :: Type) Source #

View

Instance details

Defined in Miso.Router

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

Methods

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

IsString (View a) Source #

IsString instance

Instance details

Defined in Miso.Types

Methods

fromString :: String -> View a #

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 #

ToView (View action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction (View action) 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action

Methods

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

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

Defined in Miso.Router

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

Defined in Miso.Types

type MkLink (View a :: Type) b = b
type ToViewAction (View action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction (View action) = action

data HTML Source #

HTML MimeType used for servant APIs

type Home = "home" :> Get '[HTML] (Component model action)

Instances

Instances details
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

class ToHtml a where Source #

Class for rendering HTML

Methods

toHtml :: a -> ByteString Source #

Instances

Instances details
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 model action) Source #

Render a Component to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: Component model action -> ByteString Source #

Mathml

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

Used to construct Node in View

Router

route :: forall {k} (layout :: k) m a. 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.

class HasRouter (layout :: k) 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 :: k) a 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

Instances details
HasRouter Raw Source #

Raw

Instance details

Defined in Miso.Router

Associated Types

type RouteT Raw x 
Instance details

Defined in Miso.Router

type RouteT Raw x = x

Methods

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

HasRouter (View a :: Type) Source #

View

Instance details

Defined in Miso.Router

Methods

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

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

Alternative

Instance details

Defined in Miso.Router

Methods

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

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

Path

Instance details

Defined in Miso.Router

Methods

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

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

Capture

Instance details

Defined in Miso.Router

Methods

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

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

Header

Instance details

Defined in Miso.Router

Methods

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

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

QueryFlag

Instance details

Defined in Miso.Router

Methods

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

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

QueryParam

Instance details

Defined in Miso.Router

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 :: Type) Source #

QueryParams

Instance details

Defined in Miso.Router

Methods

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

HasRouter (Verb m s c a :: Type) Source #

Verb

Instance details

Defined in Miso.Router

Methods

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

type family RouteT (layout :: k) a Source #

Type family for route dispatch

Instances

Instances details
type RouteT Raw x Source # 
Instance details

Defined in Miso.Router

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

Defined in Miso.Router

type RouteT (View a :: Type) x = x
type RouteT (x :<|> y :: Type) a Source # 
Instance details

Defined in Miso.Router

type RouteT (x :<|> y :: Type) a = RouteT x a :<|> RouteT y a
type RouteT (path :> sublayout :: Type) a Source # 
Instance details

Defined in Miso.Router

type RouteT (path :> sublayout :: Type) a = RouteT sublayout a
type RouteT (Capture sym x :> sublayout :: Type) a Source # 
Instance details

Defined in Miso.Router

type RouteT (Capture sym x :> sublayout :: Type) a = x -> RouteT sublayout a
type RouteT (Header sym x :> sublayout :: Type) a Source # 
Instance details

Defined in Miso.Router

type RouteT (Header sym x :> sublayout :: Type) a = Maybe x -> RouteT sublayout a
type RouteT (QueryFlag sym :> sublayout :: Type) a Source # 
Instance details

Defined in Miso.Router

type RouteT (QueryFlag sym :> sublayout :: Type) a = Bool -> RouteT sublayout a
type RouteT (QueryParam sym x :> sublayout :: Type) a Source # 
Instance details

Defined in Miso.Router

type RouteT (QueryParam sym x :> sublayout :: Type) a = Maybe x -> RouteT sublayout a
type RouteT (QueryParams sym x :> sublayout :: Type) a Source # 
Instance details

Defined in Miso.Router

type RouteT (QueryParams sym x :> sublayout :: Type) a = [x] -> RouteT sublayout a
type RouteT (Verb m s c a :: Type) x Source # 
Instance details

Defined in Miso.Router

type RouteT (Verb m s c a :: Type) x = x

data Router a Source #

A Router contains the information necessary to execute a handler.

data RoutingError Source #

When routing, the router may fail to match a location.

Constructors

Fail 

Run

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

exception :: SomeException -> JSM JSVal Source #

Exception handler

Used to catch Component mounting exceptions

action `catch` exception

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.

Subscriptions

back :: JSM () Source #

Navigates backwards

forward :: JSM () Source #

Navigates forwards

getURI :: JSM URI Source #

Retrieves current URI of page

go :: Int -> JSM () Source #

Jumps to a specific position in history

pushURI :: URI -> JSM () Source #

Pushes a new URI onto the History stack

replaceURI :: URI -> JSM () Source #

Replaces current URI on stack

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

Subscription for popstate events, from the History API

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. The callback will be called with the Set of currently pressed keyCodes.

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

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

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

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

sseSub Source #

Arguments

:: FromJSON msg 
=> MisoString

EventSource URL

-> (SSE msg -> action) 
-> Sub action 

Server-sent events Subscription

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

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

Sends message to a websocket server

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

WebSocket subscription

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 to handle PointerEvents on window

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

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

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

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

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

Instances details
Show Arrows Source # 
Instance details

Defined in Miso.Subscription.Keyboard

Eq Arrows Source # 
Instance details

Defined in Miso.Subscription.Keyboard

Methods

(==) :: Arrows -> Arrows -> Bool #

(/=) :: Arrows -> Arrows -> Bool #

data SSE message Source #

Server-sent events data

Constructors

SSEMessage message 
SSEClose 
SSEError 

Instances

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

Defined in Miso.Subscription.SSE

Methods

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

show :: SSE message -> String #

showList :: [SSE message] -> ShowS #

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

Defined in Miso.Subscription.SSE

Methods

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

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

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

Instances details
Generic CloseCode Source # 
Instance details

Defined in Miso.WebSocket

Associated Types

type Rep CloseCode 
Instance details

Defined in Miso.WebSocket

type Rep CloseCode = D1 ('MetaData "CloseCode" "Miso.WebSocket" "miso-1.9.0.0-inplace" '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))))))
Show CloseCode Source # 
Instance details

Defined in Miso.WebSocket

Eq CloseCode Source # 
Instance details

Defined in Miso.WebSocket

FromJSVal CloseCode Source # 
Instance details

Defined in Miso.WebSocket

ToJSVal 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-inplace" '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 Protocols Source #

Protocols for Websocket connection

Constructors

Protocols [MisoString] 

Instances

Instances details
Show Protocols Source # 
Instance details

Defined in Miso.WebSocket

Eq Protocols Source # 
Instance details

Defined in Miso.WebSocket

newtype Reason Source #

Reason for closed connection

Constructors

Reason MisoString 

Instances

Instances details
Show Reason Source # 
Instance details

Defined in Miso.WebSocket

Eq Reason Source # 
Instance details

Defined in Miso.WebSocket

Methods

(==) :: Reason -> Reason -> Bool #

(/=) :: Reason -> Reason -> Bool #

newtype URL Source #

URL of Websocket server

Constructors

URL MisoString 

Instances

Instances details
Show URL Source # 
Instance details

Defined in Miso.WebSocket

Methods

showsPrec :: Int -> URL -> ShowS #

show :: URL -> String #

showList :: [URL] -> ShowS #

Eq URL Source # 
Instance details

Defined in Miso.WebSocket

Methods

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

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

newtype WasClean Source #

Wether or not the connection closed was done so cleanly

Constructors

WasClean Bool 

Instances

Instances details
Show WasClean Source # 
Instance details

Defined in Miso.WebSocket

Eq WasClean Source # 
Instance details

Defined in Miso.WebSocket

data WebSocket action Source #

WebSocket connection messages

Instances

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

Defined in Miso.WebSocket

Methods

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

show :: WebSocket action -> String #

showList :: [WebSocket action] -> ShowS #

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

Defined in Miso.WebSocket

Methods

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

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

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

Instances details
FromJSON URI Source #

Since: aeson-2.2.0.0

Instance details

Defined in Data.Aeson.Types.FromJSON

FromJSONKey URI Source #

Since: aeson-2.2.0.0

Instance details

Defined in Data.Aeson.Types.FromJSON

ToJSON URI Source #

Since: aeson-2.2.0.0

Instance details

Defined in Data.Aeson.Types.ToJSON

ToJSONKey URI Source #

Since: aeson-2.2.0.0

Instance details

Defined in Data.Aeson.Types.ToJSON

NFData URI Source # 
Instance details

Defined in Network.URI

Methods

rnf :: URI -> () #

Data URI Source # 
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 #

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

toConstr :: URI -> Constr #

dataTypeOf :: URI -> DataType #

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

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

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

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

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

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

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

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

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

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

Generic URI Source # 
Instance details

Defined in Network.URI

Associated Types

type Rep URI 
Instance details

Defined in Network.URI

Methods

from :: URI -> Rep URI x #

to :: Rep URI x -> URI #

Show URI Source # 
Instance details

Defined in Network.URI

Methods

showsPrec :: Int -> URI -> ShowS #

show :: URI -> String #

showList :: [URI] -> ShowS #

Eq URI Source # 
Instance details

Defined in Network.URI

Methods

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

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

Ord URI Source # 
Instance details

Defined in Network.URI

Methods

compare :: URI -> URI -> Ordering #

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

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

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

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

max :: URI -> URI -> URI #

min :: URI -> URI -> URI #

Lift URI Source # 
Instance details

Defined in Network.URI

Methods

lift :: Quote m => URI -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => URI -> Code m URI #

type Rep URI Source # 
Instance details

Defined in Network.URI

Storage

clearLocalStorage :: JSM () Source #

Clear local storage

clearLocalStorage removes all values from local storage.

clearSessionStorage :: JSM () Source #

Clear session storage

clearSessionStorage removes all values from session storage.

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

Retrieve a value stored under given key in local storage

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

Retrieve a value stored under given key in session storage

localStorageLength :: JSM Int Source #

Local storage length

localStorageLength returns the count of items in local storage

removeLocalStorage :: MisoString -> JSM () Source #

Removes an item from local storage

removeLocalStorage key removes the value of key.

removeSessionStorage :: MisoString -> JSM () Source #

Removes an item from session storage.

removeSessionStorage key removes the value of key.

sessionStorageLength :: JSM Int Source #

Session storage length

sessionStorageLength returns the count of items in session 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.

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.

Fetch

fetchJSON Source #

Arguments

:: FromJSON action 
=> MisoString

url

-> MisoString

method

-> Maybe MisoString

body

-> [(MisoString, MisoString)]

headers

-> (action -> JSM ())

successful callback

-> (MisoString -> JSM ())

errorful callback

-> JSM () 

Retrieve JSON via Fetch API

Basic GET of JSON using Fetch API, will be expanded upon.

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

Util

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

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

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) ]

FFI

addStyle :: MisoString -> JSM () Source #

Appends a style_ element containing CSS to head_

addStyle "body { background-color: green; }"
<head><style>body { background-color: green; }</style></head>

addStyleSheet :: MisoString -> JSM () Source #

Appends a StyleSheet link_ element to head_ The link_ tag will contain a URL to a CSS file.

addStyleSheet "https://cdn.jsdelivr.net/npm/todomvc-common@1.0.5/base.min.css"
<head><link href="https://cdn.jsdelivr.net/npm/todomvc-common@1.0.5/base.min.css" ref="stylesheet"></head>

alert :: MisoString -> JSM () Source #

Calls the alert() function.

asyncCallback :: JSM () -> JSM Function Source #

Creates an asynchronous callback function

blur :: MisoString -> JSM () Source #

Fails silently if the element is not found.

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

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.

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

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.

focus :: MisoString -> JSM () Source #

Fails silently if the element is not found.

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

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

reload :: JSM () Source #

Calls the location.reload() function.

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

Set property on object

syncCallback :: JSM () -> JSM Function Source #

Creates a synchronous callback function (no return value)

State management

ask :: MonadReader r m => m r #

Retrieves the monad environment.

modify :: MonadState s m => (s -> s) -> m () #

Monadic state transformer.

Maps an old state to a new state inside a state monad. The old state is thrown away.

     Main> :t modify ((+1) :: Int -> Int)
     modify (...) :: (MonadState Int a) => a ()

This says that modify (+1) acts over any Monad that is a member of the MonadState class, with an Int state.

modify' :: MonadState s m => (s -> s) -> m () #

A variant of modify in which the computation is strict in the new state.

Since: mtl-2.2

get :: MonadState s m => m s #

Return the state from the internals of the monad.

gets :: MonadState s m => (s -> a) -> m a #

Gets specific component of the state, using a projection function supplied.

put :: MonadState s m => s -> m () #

Replace the state inside the monad.

tell :: MonadWriter w m => w -> m () #

tell w is an action that produces the output w.