Skip to content

Instantly share code, notes, and snippets.

@micha
Created December 10, 2014 17:32
Show Gist options
  • Select an option

  • Save micha/998911896dbd457040c1 to your computer and use it in GitHub Desktop.

Select an option

Save micha/998911896dbd457040c1 to your computer and use it in GitHub Desktop.
(page "index.html"
(:require
[tailrecursion.hoplon.reload :refer [reload-all]]))
(reload-all 1000)
(defn clamp [lower x upper]
(max lower (min x upper)))
;; this cell contains some info, but we want to make sure
;; it satisfies some constraint (eg. clamped to some range)
(defc age 0)
;; use javelin "lens" to clamp age to range [0, 100]
(defc= clamped-age age #(reset! age (clamp 0 % 100)))
(html
(head)
(body
(h1 "Hello, World!")
(form
(input
:type "text"
:value clamped-age
:change #(reset! clamped-age (js/parseInt @%))))))
;; debug cell value to js console
(cell= (prn :clamped-age clamped-age))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment