Héllo,
I am experimenting using biwascheme and
snabbdom to hopefully create an app. snabbdom is functional virtualdom library written in scheme similar in principle to reactjs.
Inspired from reactjs/redux and
functional frontend architecture I made a little experiment that I am sharing with you, see the attachment. The goal of the experiment is to create three independant clickable counters.
Here is the interesting part:
;; FIXME: (getelem "#main") doesn't seem to work.
(define body (car (js-array->list ($ "body"))))
(define main (element-new '(div#main "getting started")))
(element-append-child! body main)
(define *state* `((counter0 . 0) (counter1 . 0) (counter2 . 0)))
(define (render)
;; patch will update the dom efficently
(set! main (patch main (view *state*))))
(define (action:increment counter-name)
(lambda ()
;; update state
(set! *state* (alist-set *state* counter-name (+ (alist-ref *state* counter-name) 1)))
(render)))
(define (view:counter name count)
;; return the view code for a counter given its NAME and state COUNT
(h "div.counter" `(("click" . ,(action:increment name))) count))
(define (view state)
;; return the whole view of the "app" based on STATE
(let ((counter0 (alist-ref *state* 'counter0))
(counter1 (alist-ref *state* 'counter1))
(counter2 (alist-ref *state* 'counter2)))
(h "div#main" '()
(view:counter 'counter0 counter0)
(view:counter 'counter1 counter1)
(view:counter 'counter2 counter2))))
(render) ;; initial render
Happy hacking!