| Copyright | (C) 2016-2025 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Types
Description
Synopsis
- type App model action = Component ROOT model action
- data Component parent model action = Component {
- model :: model
- hydrateModel :: Maybe (JSM model)
- update :: action -> Effect parent model action
- view :: model -> View model action
- subs :: [Sub action]
- events :: Events
- styles :: [CSS]
- scripts :: [JS]
- initialAction :: Maybe action
- mountPoint :: Maybe MountPoint
- logLevel :: LogLevel
- mailbox :: Mail -> Maybe action
- bindings :: [Binding parent model]
- type ComponentId = Int
- data SomeComponent parent = Eq model => SomeComponent (Component parent model action)
- data View model action
- = VNode NS MisoString [Attribute action] [View model action]
- | VText MisoString
- | VComp NS MisoString [Attribute action] (SomeComponent model)
- newtype Key = Key MisoString
- data Attribute action
- = Property MisoString Value
- | Event (Sink action -> VTree -> LogLevel -> Events -> JSM ())
- | Styles (Map MisoString MisoString)
- data NS
- data CSS
- data JS
- data LogLevel
- newtype VTree = VTree {}
- type MountPoint = MisoString
- type DOMRef = JSVal
- data ROOT
- type Transition model action = Effect ROOT model action
- data URI = URI {}
- data JSM a
- class ToKey key where
- data Binding parent child
- = ParentToChild (parent -> field) (field -> child -> child)
- | ChildToParent (field -> parent -> parent) (child -> field)
- | Bidirectional (parent -> field) (field -> parent -> parent) (child -> field) (field -> child -> child)
- emptyURI :: URI
- component :: model -> (action -> Effect parent model action) -> (model -> View model action) -> Component parent model action
- (-->) :: Lens parent a -> Lens model a -> Binding parent model
- (<--) :: Lens parent a -> Lens model a -> Binding parent model
- (<-->) :: Lens parent field -> Lens child field -> Binding parent child
- (<--->) :: Lens' parent field -> Lens' child field -> Binding parent child
- (--->) :: Lens' parent field -> Lens' child field -> Binding parent child
- (<---) :: Lens' parent field -> Lens' child field -> Binding parent child
- mount :: forall child model action a. Eq child => ([View model a] -> View model a) -> Component model child action -> View model a
- (+>) :: forall child model action a. Eq child => ([View model a] -> View model a) -> Component model child action -> View model a
- getMountPoint :: Maybe MisoString -> MisoString
- optionalAttrs :: ([Attribute action] -> [View model action] -> View model action) -> [Attribute action] -> Bool -> [Attribute action] -> [View model action] -> View model action
- optionalChildren :: ([Attribute action] -> [View model action] -> View model action) -> [Attribute action] -> [View model action] -> Bool -> [View model action] -> View model action
- prettyURI :: URI -> MisoString
- prettyQueryString :: URI -> MisoString
- node :: NS -> MisoString -> [Attribute action] -> [View model action] -> View model action
- text :: MisoString -> View model action
- text_ :: [MisoString] -> View model action
- type MisoString = JSString
- toMisoString :: ToMisoString str => str -> MisoString
- fromMisoString :: FromMisoString a => MisoString -> a
- ms :: ToMisoString str => str -> MisoString
Types
data Component parent model action Source #
Application entry point
Constructors
| Component | |
Fields
| |
type ComponentId = Int Source #
ComponentId of the current Component
data SomeComponent parent Source #
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 | |
| VComp NS MisoString [Attribute action] (SomeComponent model) |
Instances
| Functor (View model) Source # | |
| ToHtml [View m a] Source # | Render a |
Defined in Miso.Html.Render Methods toHtml :: [View m a] -> ByteString Source # | |
| IsString (View model action) Source # |
|
Defined in Miso.Types Methods fromString :: String -> View model action # | |
| ToHtml (View m a) Source # | Render a |
Defined in Miso.Html.Render Methods toHtml :: View m a -> ByteString 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
| ToJSON Key Source # | |
| IsString Key Source # | |
Defined in Miso.Types Methods fromString :: String -> Key # | |
| Show Key Source # | |
| Eq Key Source # | |
| ToJSVal Key Source # | ToJSVal instance for |
| ToMisoString Key Source # | |
Defined in Miso.Types Methods toMisoString :: Key -> MisoString Source # | |
| ToKey Key Source # | Identity instance |
data Attribute action Source #
Attribute of a vnode in a View.
Constructors
| Property MisoString Value | |
| Event (Sink action -> VTree -> LogLevel -> Events -> JSM ()) | The |
| Styles (Map MisoString MisoString) |
Allow users to express CSS and append it to <head> before the first draw
Href "http://domain.com/style.css"
Style "body { background-color: red; }"Constructors
| Href MisoString |
|
| Style MisoString | |
| Sheet StyleSheet |
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 "alert("hi");"
ImportMap [ "key" =: "value" ]
Constructors
| Src MisoString |
|
| Script MisoString |
|
| Module MisoString |
|
| ImportMap [(MisoString, MisoString)] |
|
Optional logging for debugging miso internals (useful to see if prerendering is successful)
Constructors
| Off | No debug logging, the default value used in |
| 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 |
type MountPoint = MisoString Source #
mountPoint for Component, e.g "body"
type Transition model action = Effect ROOT model action Source #
Type for dealing with URI. See the official specification
Constructors
| URI | |
Fields | |
Instances
| Show URI Source # | |
| Eq URI Source # | |
| ToMisoString URI Source # | |
Defined in Miso.Types Methods toMisoString :: URI -> MisoString Source # | |
Re-exports
The JSM monad keeps track of the JavaScript execution context.
When using GHCJS it is IO.
Given a JSM function and a JSContextRef you can run the
function like this...
runJSM jsmFunction javaScriptContext
Instances
Classes
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 (different inputs must map to different outputs).
Data Bindings
data Binding parent child Source #
Binding is used to synchronize parent and child model changes at the granularity specified by a Lens
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).
main :: IO ()
main = run app { bindings = [ parentLens <--> childLens ] }
Since: 1.9.0.0
Constructors
| ParentToChild (parent -> field) (field -> child -> child) | |
| ChildToParent (field -> parent -> parent) (child -> field) | |
| Bidirectional (parent -> field) (field -> parent -> parent) (child -> field) (field -> child -> child) |
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.
(-->) :: Lens parent a -> Lens model a -> Binding parent model Source #
Unidirectionally binds a parent field to a child field
Since: 1.9.0.0
(<--) :: Lens parent a -> Lens model a -> Binding parent model Source #
Unidirectionally binds a child field to a parent field
Since: 1.9.0.0
(<-->) :: Lens parent field -> Lens child field -> Binding parent child Source #
Bidirectionally binds a child field to a parent field, using Lens
This is a bidirectional reactive combinator for a miso Lens.
Since: 1.9.0.0
(<--->) :: Lens' parent field -> Lens' child field -> Binding parent child Source #
Bidirectionally binds a child field to a parent field, using Lens'
This is a bidirectional reactive combinator for a van Laarhoven Lens'
Since: 1.9.0.0
(--->) :: Lens' parent field -> Lens' child field -> Binding parent child Source #
Unidirectionally binds a parent field to a child field, for van Laarhoven
style Lens'
Since: 1.9.0.0
(<---) :: Lens' parent field -> Lens' child field -> Binding parent child Source #
Unidirectionally binds a child field to a parent field, for van Laarhoven
style Lens'
Since: 1.9.0.0
Component
mount :: forall child model action a. Eq child => ([View model a] -> View model a) -> Component model child action -> View model a Source #
(+>) :: forall child model action a. Eq child => ([View model a] -> View model a) -> Component model child action -> View model a infixr 0 Source #
Utils
getMountPoint :: Maybe MisoString -> MisoString Source #
Convenience for extracting mount point
Arguments
| :: ([Attribute action] -> [View model action] -> View model action) | |
| -> [Attribute action] | Attributes to be added unconditionally |
| -> Bool | A condition |
| -> [Attribute action] | Additional attributes to add if the condition is True |
| -> [View model action] | Children |
| -> View model action |
Utility function to make it easy to specify conditional attributes
view :: Bool -> View model action view danger = optionalAttrs textarea_ [ id_ "txt" ] danger [ class_ "danger" ] ["child"]
Since: 1.9.0.0
Arguments
| :: ([Attribute action] -> [View model action] -> View model action) | |
| -> [Attribute action] | Attributes to be added unconditionally |
| -> [View model action] | Children to be added unconditionally |
| -> Bool | A condition |
| -> [View model action] | Additional children to add if the condition is True |
| -> View model action |
Utility function to make it easy to specify conditional children
view :: Bool -> View model action view withChild = optionalChildren div_ [ id_ "txt" ] [] withChild [ "foo" ]
Since: 1.9.0.0
prettyQueryString :: URI -> MisoString Source #
URI query string pretty-printing
Combinators
node :: NS -> MisoString -> [Attribute action] -> [View model action] -> View model action Source #
Create a new VNode.
node ns tag attrs children creates a new node with tag tag
in the namespace ns. All attrs are called when
the node is created and its children are initialized to children.
text_ :: [MisoString] -> View model action Source #
Create a new VText containing concatenation of the given strings.
MisoString
type MisoString = JSString Source #
String type swappable based on compiler
toMisoString :: ToMisoString str => str -> MisoString Source #
Convert a type into MisoString
fromMisoString :: FromMisoString a => MisoString -> a Source #
Reads a MisoString, throws an error when decoding
fails. Use fromMisoStringEither as a safe alternative.
ms :: ToMisoString str => str -> MisoString Source #
Convenience function, shorthand for toMisoString