Copyright | (c) Mike Solomon 2020 |
---|---|
License | GPL-3 |
Maintainer | mike@meeshkan.com |
Stability | experimental |
Portability | POSIX, Windows |
Safe Haskell | Safe |
Language | Haskell2010 |
This module contains the base functions for plzwrk, notably the family of plzwrk functions needed for plzwrk to work. It also exports most of the utility functions used for building web applications, like event handling and attribute wrangling.
Synopsis
- plzwrk :: (state -> Node state jsval) -> state -> Browserful jsval -> String -> IO ()
- plzwrk' :: (state -> Node state jsval) -> state -> Browserful jsval -> IO ()
- plzwrk'_ :: (() -> Node () jsval) -> Browserful jsval -> IO ()
- plzwrkSSR :: (state -> Node state jsval) -> state -> Browserful jsval -> String -> IO ()
- toHTML :: (state -> Node state jsval) -> state -> String
- data Node s opq
- = Element {
- _elt_tag :: String
- _elt_attrs :: s -> Attributes s opq
- _elt_children :: [s -> Node s opq]
- | TextNode { }
- = Element {
- data Attributes s opq = MkAttributes {}
- data Browserful jsval = Browserful {
- consoleLog :: String -> IO ()
- consoleLog' :: jsval -> IO ()
- documentBody :: IO jsval
- documentCreateElement :: String -> IO jsval
- documentCreateTextNode :: String -> IO jsval
- documentGetElementById :: String -> IO (Maybe jsval)
- documentHead :: IO jsval
- elementSetAttribute :: jsval -> String -> String -> IO ()
- elementTagName :: jsval -> IO String
- eventTargetAddEventListener :: jsval -> String -> jsval -> IO ()
- eventTargetRemoveEventListener :: jsval -> String -> jsval -> IO ()
- getPropertyAsBool :: jsval -> String -> IO (Maybe Bool)
- getPropertyAsDouble :: jsval -> String -> IO (Maybe Double)
- getPropertyAsInt :: jsval -> String -> IO (Maybe Int)
- getPropertyAsOpaque :: jsval -> String -> IO (Maybe jsval)
- getPropertyAsString :: jsval -> String -> IO (Maybe String)
- htmlElemenetClick :: jsval -> IO ()
- invokeOn0 :: jsval -> String -> IO jsval
- mathRandom :: IO Double
- nodeAppendChild :: jsval -> jsval -> IO ()
- nodeChildNodes :: jsval -> IO [jsval]
- nodeInsertBefore :: jsval -> jsval -> jsval -> IO ()
- nodeRemoveChild :: jsval -> jsval -> IO ()
- nodeTextContent :: jsval -> IO String
- _freeCallback :: jsval -> IO ()
- _makeHaskellCallback :: (jsval -> IO ()) -> IO jsval
- (<.>) :: (s -> Attributes s opq) -> (s -> Attributes s opq) -> s -> Attributes s opq
- wStyle :: String -> String -> s -> Attributes s opq
- wStyle' :: String -> String -> Attributes s opq
- wStyles :: [(String, String)] -> s -> Attributes s opq
- wStyles' :: [(String, String)] -> Attributes s opq
- wClass :: String -> s -> Attributes s opq
- wClass' :: String -> Attributes s opq
- wClasses :: [String] -> s -> Attributes s opq
- wClasses' :: [String] -> Attributes s opq
- wOnClick :: (opq -> s -> IO s) -> s -> Attributes s opq
- wOnClick' :: (opq -> s -> IO s) -> Attributes s opq
- wId :: String -> s -> Attributes s opq
- wId' :: String -> Attributes s opq
- wOnInput :: (opq -> s -> IO s) -> s -> Attributes s opq
- wOnInput' :: (opq -> s -> IO s) -> Attributes s opq
- wAttr :: String -> String -> s -> Attributes s opq
- wAttr' :: String -> String -> Attributes s opq
- wAttrs :: [(String, String)] -> s -> Attributes s opq
- wAttrs' :: [(String, String)] -> Attributes s opq
- eventPreventDefault :: Browserful jsval -> jsval -> IO ()
- eventTargetBlur :: Browserful jsval -> jsval -> IO ()
- eventTargetValue :: Browserful jsval -> jsval -> IO (Maybe String)
Documentation
:: (state -> Node state jsval) | A function that takes a state and produces a DOM |
-> state | An initial state |
-> Browserful jsval | A browser implementation, ie Asterius or the mock browser |
-> String | The id of the element into which the DOM is inserted. Note that plzwrk manages all children under this element. Touching the managed elements can break plzwrk. |
-> IO () | Returns nothing |
The main function that makes a web app.
plzwrk' :: (state -> Node state jsval) -> state -> Browserful jsval -> IO () Source #
A variation of plzwrk that inserts the node as a child of the document's body.
plzwrk'_ :: (() -> Node () jsval) -> Browserful jsval -> IO () Source #
A variation of plzwrk that takes no state.
:: (state -> Node state jsval) | A function that takes a state and produces a DOM |
-> state | An initial state |
-> Browserful jsval | A browser implementation, ie Asterius or the mock browser |
-> String | The id of the element into which the DOM is inserted. Note that plzwrk manages all children under this element. Touching the managed elements can break plzwrk. |
-> IO () | Returns nothing |
A variant of plzwrk that acts on a node already rendered to the DOM, ie by server-side rendering. It assumes the node has been rendered with the same state-to-node function as well as the same state.
:: (state -> Node state jsval) | A function that takes a state and produces a DOM |
-> state | An initial state |
-> String | The resulting HTML |
Converts a Node to HTML.
A DOM node.
The easiest way to create nodes is using tags such as
span
or br
.
Nodes can be created for arbitrary tags using the Element
constructor.
Node is parameterized by two types
* s
- the type of the state
* opq
- the type of an opaque object in JavaScript
Note that nodes, when passed as an arguemnt to plzwrk
, need
to be Applicative Functors in the form (s -> Node s opq)
.
Element | |
| |
TextNode | |
data Attributes s opq Source #
Attributes for a DOM Node.
Attributes are parameterized by two types
* s
- the type of the state
* opq
- the type of an opaque object in JavaScript
You will rarely need to instantiate Attributes
yourself,
as it is easier to work with utility functions like wId
,
wStyle
etc that produce Applicative Functors with signature
(s -> Attributes s opq)
. These AFs are used in the Node
data.
Instances
Show (Attributes s opq) Source # | |
Defined in Web.Framework.Plzwrk.Base showsPrec :: Int -> Attributes s opq -> ShowS # show :: Attributes s opq -> String # showList :: [Attributes s opq] -> ShowS # |
data Browserful jsval Source #
A data class holding functions that operate on opaque
JavaScript types, parameterized by jsval
. When possible,
the real names of browser functions like addEventListener
and appendChild
are used.
Browserful is currently implemented as data instead of as
a typeclass because it is unclear what type of additional
monadic transformer around IO would be most appropriate to
retain the state of jsval
objects, whereas when part of
a dataclass, the state retention is abstracted away.
Browserful | |
|
(<.>) :: (s -> Attributes s opq) -> (s -> Attributes s opq) -> s -> Attributes s opq Source #
Merges two Attributes
wStyle :: String -> String -> s -> Attributes s opq Source #
Constrcts a stateful Attributes
applicative functor from a single style.
wStyle' :: String -> String -> Attributes s opq Source #
Constrcts an Attributes
from a single style.
wStyles :: [(String, String)] -> s -> Attributes s opq Source #
Constrcts a stateful Attributes
applicative functor from a list of styles.
wStyles' :: [(String, String)] -> Attributes s opq Source #
Constrcts an Attributes
from a list of styles.
wClass :: String -> s -> Attributes s opq Source #
Constrcts a stateful Attributes
applicative functor from a single class.
wClass' :: String -> Attributes s opq Source #
Constrcts an Attributes
from a single class.
wClasses :: [String] -> s -> Attributes s opq Source #
Constrcts a stateful Attributes
applicative functor from a list of clases.
wClasses' :: [String] -> Attributes s opq Source #
Constrcts an Attributes
from a list of classes.
wOnClick :: (opq -> s -> IO s) -> s -> Attributes s opq Source #
Constrcts a stateful Attributes
applicative functor from an onClick
callback.
wOnClick' :: (opq -> s -> IO s) -> Attributes s opq Source #
Constrcts an Attributes
from an onClick
callback.
wId :: String -> s -> Attributes s opq Source #
Constrcts a stateful Attributes
applicative functor with a given id.
wId' :: String -> Attributes s opq Source #
Constrcts an Attributes
with a given id.
wOnInput :: (opq -> s -> IO s) -> s -> Attributes s opq Source #
Constrcts a stateful Attributes
applicative functor from an onInput
callback.
wOnInput' :: (opq -> s -> IO s) -> Attributes s opq Source #
Constrcts an Attributes
from an onInput
callback.
wAttr :: String -> String -> s -> Attributes s opq Source #
Constrcts a stateful Attributes
applicative functor from a single attribute.
wAttr' :: String -> String -> Attributes s opq Source #
Constrcts an Attributes
from a single attribute.
wAttrs :: [(String, String)] -> s -> Attributes s opq Source #
Constrcts a stateful Attributes
applicative functor from a list of attributes.
wAttrs' :: [(String, String)] -> Attributes s opq Source #
Constrcts an Attributes
from a list of attributes.
eventPreventDefault :: Browserful jsval -> jsval -> IO () Source #
Take an event and prevent the default.
eventTargetBlur :: Browserful jsval -> jsval -> IO () Source #
From an event, takes the target and blurs it.
eventTargetValue :: Browserful jsval -> jsval -> IO (Maybe String) Source #
From an event, gets the target's value.