This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-13
Channels
- # admin-announcements (208)
- # beginners (53)
- # boot (46)
- # cider (10)
- # cljs-dev (26)
- # cljsjs (10)
- # clojure (66)
- # clojure-dev (3)
- # clojure-russia (14)
- # clojurecup (5)
- # clojurescript (302)
- # cursive (22)
- # data-science (1)
- # datomic (10)
- # emacs (1)
- # events (2)
- # hoplon (91)
- # incanter (1)
- # ldnclj (3)
- # leiningen (1)
- # off-topic (2)
- # om (41)
- # re-frame (40)
- # reagent (78)
@micha, @alandipert: I tried to make javeline-like (in sense of being glitch-free) reactive expressions, but with two differences: * child cell/formula register itself in the parent one on deref (i took this idea from freactive.core, but implemented in glitch-free manner) * if you call a function which produces formula inside of creating another formula, it still will be interpreted as reactive input, not literally (no need to do tricks like that (snippet from one of my hoplon projects):
(defn t [k] ((formula (fn [lang] (t* lang k))) lang))
;; NOTE do not inline `c`, it prevents `text` from recognizing it as a cell
(defn ttext [k] (let [c (t k)] (text c)))
)
* formulas performs self-cleanup (detach from sources) if no sinks or watches attached to them after update or watch removal — in most cases it allows to not care about manual disposal and prevents memory leaks while doing a lot of dynamic formulas
I will be happy to hear any feedback and ideasthis tricked me several times, so i decided to experiment with alternative implementation of frp
t
takes a key of message to be translated ans returns formula, which contains translation depending on lang
cell value
the tradeoff with marking cells in formulas with deref is that you need to know which things are cells
yep, i understand, but as far as you are using f1
in handlers or in making formulas like in my snippet, you anyway should care about its nature
i'm interested to see if you can make the autodetatchment work in a ui with async stuff
the problem comes when you have an async process that derefs the cells without a watch etc
(let [c (cell nil)]
(form :submit #(doit @c)
(input :keyup #(reset! c @%))
(input :type "submit")))
from what? it does not participate in any formula and can be gc'ed. in my implementation source cells not linked from anywhere
so, if c
is lens (like (formula #(@source-cell) #(reset! source-cell %))
then it will be not autodetached automatically on form
disappear. It will be detached only if and when source-cell
will be next time updated
it is the weak place, yes, but it is known to me from the beginning — it is why i call it high-probability autodetach, not guarantee
as far as i can see in my apps, this case is rare — if formula has unupdatable sources for a long time and is used just in closure
thank you for discussion! if some kind of cross-pollination with javelin will happen, i will be happy
i guess the tricky part is to correctly remove watches when things are removed from the dom
follow back from the cell the watch was removed from, detatching cells that have only one reference left
yes, i'm doing it recursive:
(clean [this]
(when (and (empty? sinks) (empty? watches))
(doseq [source sources]
(remove-sink source this)
(when (satisfies? IReactiveExpression source)
(clean source)))
(set! sources #{})
(set! state ::thunk)))
and what is good, that if one of the detached formulas is referenced somewhere in the code and reused again later