You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rendering.md
+20-14Lines changed: 20 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,18 @@ mount :: forall model message. QuerySelector -> Application model message -> Eff
24
24
```
25
25
The first parameter is a css selector used as mount point.Under the hood, Flame uses the [snabbdom](https://github.com/snabbdom/snabbdom) virtual DOM.
26
26
27
+
#### Hooks
28
+
29
+
Snabbdom provides [hooks](https://github.com/snabbdom/snabbdom#hooks) to inject code into the DOM lifecycle.Since hooks directly manipulate virtual nodes, the functions exported by `Flame.Renderer.Hook` expect foreign interface callbacks, e.g.:
30
+
```haskell
31
+
--| Foreign VNode hook function with two parameters
32
+
typeHookFn2=EffectFn2VNodeVNodeUnit
33
+
34
+
--| Attaches a hook for a vnode element been patched
to install event handlers in the pre rendered markup.The `Generic` constraint is necessary since Flame will serialize the initial state of `PreApplication`
50
-
```haskell
51
55
typePreApplicationmodelmessage= {
52
56
init::model,
53
57
view::model->Htmlmessage
54
58
}
55
-
```
56
-
into the rendered markup. For this reason, the `QuerySelector` passed to `preMount` and `resumeMount` must match -- otherwise the application will crash with an exception. To avoid diffing issues, the same `view` function should be passed to both function records as well.
Notice how `init` only contains the initial messages to be raised. The `update` function responsible for handling events is added on client side as well.
72
+
to install event handlers in the pre rendered markup.The `SerializeModel`/`UnserializeModel` type class automatically serialize the initial state as JSON, provided it is either a record or has a `Generic` instance.The `QuerySelector` passed to `preMount`and`resumeMount` must match -- otherwise the application will crash with an exception. To avoid diffing issues, the same `view` function should be used on the server and client side as well.
67
73
68
74
See the [Dice application](https://github.com/easafe/purescript-flame/tree/master/examples/EffectList/ServerSideRendering) for an example of how to pre render an application on server side.
0 commit comments