This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-21
Channels
- # adventofcode (24)
- # announcements (1)
- # beginners (122)
- # braveandtrue (9)
- # calva (45)
- # cider (24)
- # cljdoc (8)
- # cljs-dev (23)
- # clojure (112)
- # clojure-europe (2)
- # clojure-india (2)
- # clojure-italy (36)
- # clojure-nl (3)
- # clojure-spec (32)
- # clojure-uk (35)
- # clojurescript (52)
- # core-typed (12)
- # cursive (4)
- # datomic (61)
- # emacs (4)
- # figwheel-main (2)
- # fulcro (14)
- # hoplon (5)
- # hyperfiddle (1)
- # jobs-discuss (6)
- # kaocha (5)
- # leiningen (2)
- # nrepl (15)
- # off-topic (62)
- # re-frame (26)
- # reagent (39)
- # ring (3)
- # shadow-cljs (56)
- # spacemacs (8)
- # specter (5)
- # tools-deps (1)
- # yada (2)
something i've always wondered about but never found an elegant solution: i have a simple event to update a text filter, and then a few dynamic subscriptions to filter a collection based on the filter value (reg-ex string matching). as i update the filter value, the text filter component drops input characters while the subscriptions do their job. i don't think this is a use case for ^{:flush-dom}
(or is it?). should i bite the bullet and move to web workers?
i realise this is a single thread problem and irrespective of the framework, but i was wondering if there's a nifty re-frame way to handle it. 🙂
Try to do a dispatch-sync
instead of a dispatch
in that one case.
Where performance is needed
So I'm guessing that it isn't the subscriptions
(Although obviously I don't know enough to really be sure)
thanks mike. specifically, a dispatch-sync instead of a dispatch when firing the event to update the text filter value based on the input textbox?
Yeah if you are dispatching on each keypress
and you are droping chars
try dispatch-sync instead
hmm. still dropping characters.
[:input.form-control.form-control-lg.mb-4
{:type "text"
:value @(subscribe [::events/text-filter database])
:on-change (fn [e] (dispatch-sync [::events/set-text-filter database (oget e :target :value)]))}]
not binding :value
to a subscription solves the problem, but it's still a little choppy
I’ve solved text-field problems by binding :value
to a ratom and using goog.functions/debounce
to ‘flush’ the ratom state to app-db
using dispatch
after 200ms or so.
This is not super elegant but it works. No dropping characters or any other symptoms (that I’m aware of).
good thinking. i tried that, but found i was still dropping characters between when the debounce eventually fired and when a new char was inputted directly thereafter. less characters lost but still one every once in a while. if it worked for you then i must be doing something wrong. will review my code 🙂
Here’s my take if you want to have a look https://github.com/lipas-liikuntapaikat/lipas/blob/dev/webapp/src/cljs/lipas/ui/components.cljs#L383-L412
I’m using events.cljc to define events and using fn-traced
from day8.re-frame.tracing
(0.5.1). However the code won’t compile and throws a java.lang.ClassNotFoundException: debux.dbgn
. Code compiles when I rename my file to events.cljs, indicating that the original tracing.cljc might not be compatible on both platforms.` For instance, debux.dbgn is written in clj.
(ns app.events
(:require
[re-frame.core :as reframe :refer [reg-event-db reg-event-fx inject-cofx path after]]
[cljs.spec.alpha :as s]
[app.db :as db]
#?(:clj
[day8.re-frame.tracing :refer [fn-traced defn-traced]]
:cljs
[day8.re-frame.tracing :refer-macros [fn-traced defn-traced]])))
(reframe/reg-event-db
::initialize-db
(fn-traced [_ _]
db/default-db))
Exception occurs at fn-traced
. What am I missing?Late to the party @U055C1RAD, but I've always just done
(:require [day8.re-frame.tracing :refer [fn-traced defn-traced]])
without any reader conditionals without any problems -- although I also typically write event handlers in a cljs
file.
grabbing a small project and renaming my events.cljs
to events.cljc
doesn't seem to provoke any problems