The first thing that caught my eye was
mercury.app(document.body, clickCount, render)
I immediately wanted to know the types of all 3 arguments. Obviously, render is a function that produces a virtual dom description, but it wasn't immediately clear what is clickCount - apparently its an observable application state whose value will be passed to the render function when a change is observed.
A more detailed discussion of the events part would be useful - it seems to be the least straightforward part. Its not clear what transformations are applied by mercury.xxxEvent
and mercury.event
to the function nor what the return type is. Its was also not clear to me if its possible to use valueEvent to observe the value of another component - e.g. to observe the value of a text field when a "Search" button is pressed - or would I need to combine click with change valueEvents (and how to do that - FRP style perhaps?).
Maybe this part could do well even without value-event. Seems like a distraction/indirection that is not strictly necessary, especially not in the introduction. For example, I had to replace mercury.changeEvent(sink)
with function(e) { sink({text: e.target.value}); }
to gain some understanding of the shared-state example. (Originally I expected value-event to deliver a value rather than wrapping it within an object)
We take an observable and a rendering function, we then create a rendering loop with the initial state by unpacking the observable, we call render, we create a dom element, append it as a child to document.body then when the observable state changes we tell the rendering loop to schedule a re-render on the next frame.