snabbdom is functional virtual DOM library.
How it works
The entry point is the
app procedure which takes as arguments the following:
containerthe dom node that will be used for rendering
inita procedure that will return the initial state of the app
viewthe procedure that takes
stateas argument and will render the application according to that state. It must return sxml-like datastructure with
on-fooattribute to bind events to callbacks called actions.
Actions are created from scheme procedure which have the following
state -> event -> state. Hence they return the new
state of the application.
Here is an example action:
(define (title-clicked state) (lambda (event) (if (null? state) "How are you doing?" '())))
Actions are directly bound to events in the sxml. For instance:
(define (view state) `(h1 (@ (on-click . ,title-clicked)) "Héllo World!"))
There is no reducers.
Read the source
All this is implemented in
Where do we go from here?
Here are the things that can be done to improve further this prototype:
- Make use of ajax
- Build isomorphic app
- Make use of history api