miso
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.Types

Description

 
Synopsis

Types

type App model action = Component ROOT model action Source #

For top-level Component, ROOT must always be specified for parent.

data Component parent model action Source #

Application entry point

Constructors

Component 

Fields

  • model :: model

    initial model

  • update :: action -> Effect parent model action

    Function to update model, optionally providing effects.

  • view :: model -> View model action

    Function to draw View

  • subs :: [Sub action]

    List of subscriptions to run during application lifetime

  • events :: Events

    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.

    Since: 1.9.0.0

  • scripts :: [JS]

    List of JavaScript scripts expressed as either a URL (Src) or raw JS text. These scripts are appended dynamically to the head section of your HTML page before the initial draw on body occurs.

    Since: 1.9.0.0

  • initialAction :: Maybe action

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

    Since: 1.9.0.0

  • mountPoint :: Maybe MountPoint

    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

  • mailbox :: Mail -> Maybe action

    Used to receive mail from other Component

    Since: 1.9.0.0

  • bindings :: [Binding parent model]
     

Instances

Instances details
ToView model (Component parent model action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction model (Component parent model action) 
Instance details

Defined in Miso.Types

type ToViewAction model (Component parent model action) = action

Methods

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

type ToViewAction model (Component parent model action) Source # 
Instance details

Defined in Miso.Types

type ToViewAction model (Component parent model action) = action

data Binding parent model Source #

Type used for React-like "props" functionality. This is used to to bind parent model changes to the child model, or vice versa.

The difference between miso and React here is that miso is synchronizing model states of Components declaratively (outside of the view). In React "props" are used in the view code.

https://react.dev/learn/passing-props-to-a-component

This can be thought of as establishing an "edge" in the Component graph, whereby events cause model change synchronization to "ripple" or "pulsate" through the views. The "reactivity" of the graph is constructed manually by the end-user, using the edge primitives -->, <--, <--> (reactive combinators).

This can also be thought of as a Wire (from netwire) for reactive variable synchronization, except done at the granularity specified by the Lens.

main :: IO ()
main = run app { bindings = [ parentLens --> childLens ] }

Since: 1.9.0.0

Constructors

Binding Direction (Lens parent a) (Lens model a) 

data SomeComponent parent Source #

Existential wrapper used to allow the nesting of Component in Component

Constructors

Eq model => SomeComponent (Component parent model action) 

data View model action Source #

Core type for constructing a virtual DOM in Haskell

Constructors

VNode NS MisoString [Attribute action] [View model action] 
VText MisoString 
VTextRaw MisoString 
VComp NS MisoString [Attribute action] (SomeComponent model) 

Instances

Instances details
HasRouter (View m a :: Type) Source #

View

Instance details

Defined in Miso.Router

Methods

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

ToView model (View model action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction model (View model action) 
Instance details

Defined in Miso.Types

type ToViewAction model (View model action) = action

Methods

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

HasLink (View m a :: Type) Source #

For constructing type-safe links

Instance details

Defined in Miso.Types

Methods

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

Functor (View model) Source # 
Instance details

Defined in Miso.Types

Methods

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

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

ToHtml [View m a] Source #

Render a [View] to a L.ByteString

Instance details

Defined in Miso.Render

Methods

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

IsString (View model action) Source #

IsString instance

Instance details

Defined in Miso.Types

Methods

fromString :: String -> View model action #

ToHtml (View m a) Source #

Render a View to a L.ByteString

Instance details

Defined in Miso.Render

Methods

toHtml :: View m a -> ByteString Source #

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

Defined in Miso.Types

type ToViewAction model (View model action) = action
type RouteT (View m a :: Type) x Source # 
Instance details

Defined in Miso.Router

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

Defined in Miso.Types

type MkLink (View m 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

Instances details
ToJSON Key Source # 
Instance details

Defined in Miso.Types

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

Sheet StyleSheet

Sheet is meant to be CSS built with Style

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 JS Source #

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

This is meant to be useful in development only.

  Src "http://example.com/script.js"
  Script "http://example.com/script.js"
  ImportMap [ "key" =: "value" ]

Constructors

Src MisoString

src is a URL meant to link to hosted JS

Script MisoString

script is meant to be raw JS in a script tag

ImportMap [(MisoString, MisoString)]

script is meant to be an import map in a script tag

Instances

Instances details
Show JS Source # 
Instance details

Defined in Miso.Types

Methods

showsPrec :: Int -> JS -> ShowS #

show :: JS -> String #

showList :: [JS] -> ShowS #

Eq JS Source # 
Instance details

Defined in Miso.Types

Methods

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

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

data LogLevel Source #

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

Constructors

Off

No debug logging, the default value used in component

DebugHydrate

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

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

Instances

Instances details
ToJSVal VTree Source # 
Instance details

Defined in Miso.Types

type MountPoint = MisoString Source #

mountPoint for Component, e.g "body"

type DOMRef = JSVal Source #

Type to represent a DOM reference

data ROOT Source #

A top-level Component can have no parent

The ROOT type is for disallowing a top-level mounted Component access into its parent state. It has no inhabitants (spiritually Data.Void.Void)

type Transition model action = Effect ROOT model action Source #

When Component are not in use, also for pre-1.9 miso applications.

Classes

class ToView m a where Source #

Convenience class for using View

Associated Types

type ToViewAction m a Source #

Methods

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

Instances

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

Defined in Miso.Types

Associated Types

type ToViewAction model (View model action) 
Instance details

Defined in Miso.Types

type ToViewAction model (View model action) = action

Methods

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

ToView model (Component parent model action) Source # 
Instance details

Defined in Miso.Types

Associated Types

type ToViewAction model (Component parent model action) 
Instance details

Defined in Miso.Types

type ToViewAction model (Component parent model action) = action

Methods

toView :: Component parent model action -> View model (ToViewAction model (Component parent model action)) 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

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 #

Smart Constructors

component :: model -> (action -> Effect parent model action) -> (model -> View model action) -> Component parent model action Source #

Smart constructor for Component with sane defaults.

Data binding

(-->) :: Lens parent a -> Lens model a -> Binding parent model Source #

Smart constructor for a Binding, unidirectionally binds parent to child

Since: 1.9.0.0

(<--) :: Lens parent a -> Lens model a -> Binding parent model Source #

Smart constructor for a Binding, unidirectionally binds child to parent

Since: 1.9.0.0

(<-->) :: Lens parent a -> Lens model a -> Binding parent model Source #

Smart constructor for a Binding, bidirectionlly binds child to parent

Since: 1.9.0.0

getDirection :: Binding parent model -> Direction Source #

Extract Direction from Binding

data Direction Source #

Instances

Instances details
Show Direction Source # 
Instance details

Defined in Miso.Types

Eq Direction Source # 
Instance details

Defined in Miso.Types

Component

mount :: forall parent model action a. Eq model => ([View parent a] -> View parent a) -> Component parent model action -> View parent a Source #

Used in the view function to mount a Component on any VNode

  mount (p_ [ key_ "component-1" ]) $ component $ \m ->
    div_ [ id_ "foo" ] [ text (ms m) ]

Warning this *is* a partial function. Do not attempt to mount on a Text node. This function will ignore the children given and mount the new Component on top of them. Attempts to mount a Component ontop of an existing Component always prioritize the component specified in the lowest level.

See usage above. In general, it's wise to only mount on VNode.

Since: 1.9.0.0

(+>) :: forall parent model action a. Eq model => ([View parent a] -> View parent a) -> Component parent model action -> View parent a infixr 0 Source #

Utils

getMountPoint :: Maybe MisoString -> MisoString Source #

Convenience for extracting mount point

Combinators

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

Create a new Miso.Types.VNode.

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 parent action Source #

Create a new Text with the given content.

text_ :: [MisoString] -> View parent action Source #

Create a new Text with the given content.

textRaw :: MisoString -> View parent action Source #

TextRaw creation. Don't use directly

rawHtml :: MisoString -> View parent action Source #

Create a new Miso.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.

MisoString

type MisoString = Text Source #

String type swappable based on compiler

fromMisoString :: FromMisoString a => MisoString -> a Source #

Parses a MisoString, throws an error when decoding fails. Use fromMisoStringEither for as a safe alternative.

ms :: ToMisoString str => str -> MisoString Source #

Convenience function, shorthand for toMisoString