This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-25
Channels
- # announcements (66)
- # aws (1)
- # beginners (60)
- # boot (6)
- # calva (80)
- # cider (3)
- # clj-kondo (14)
- # cljdoc (4)
- # cljs-dev (27)
- # clojure (65)
- # clojure-dev (24)
- # clojure-europe (13)
- # clojure-gamedev (3)
- # clojure-italy (3)
- # clojure-nl (21)
- # clojure-uk (35)
- # clojurescript (98)
- # cursive (25)
- # data-science (3)
- # datomic (10)
- # dirac (16)
- # duct (2)
- # events (2)
- # fulcro (39)
- # jobs-discuss (1)
- # malli (2)
- # other-languages (1)
- # pedestal (26)
- # re-frame (61)
- # reagent (1)
- # reitit (7)
- # shadow-cljs (230)
- # specter (1)
- # tools-deps (29)
- # vim (1)
- # yada (4)
Hi, I'm learning re-frame by building a fairly complex audio application, and am looking for examples for reference/inspiration. I'm not having any particular issues but just curious to see how folks deal with the Web Audio API, and want to learn how to do everything "properly".
@kenny the UI is only redrawn once every animation frame. subscriptions are calculated at that frequency too. Do you need to debounce more than that?
For example, are you de-bouncing server interactions, in response to user input changes?
Unfortunately, I think so. I have a s/valid?
call in a subscription. That subscription is getting updated every time the user types in an input box causing significant lag while typing.
@kenny So perhaps the other way of saying this is: I need to debounce the server requests?
The subscription is pulling in a large map and validating it against a spec. The user's input is only changing one small part of the large map.
When the user types in an input, it causes that subscription to run every single time a letter is added/removed.
Reminder: subscription are simply a way to deliver data (a materialized view of data) to views. They are reactive. When the underlying data in app-db changes, data will flow through the subscription. So why is the subscription doing validation?
The event handler putting data INTO app-db should be validating.
So: 1. each time the user types something in 2. an event is dispatched 3. an event handler updates app-db 4. causing subscriptions to fire?
IMO, any validation should really be happening in step 3.
As you say, perhaps we are just moving the problem,
Technically the valid?
is a projection of the data in the app-db. It seems clean to have it in a subscription.
I think in this case I would debounce the event, and have the input be uncontrolled
I disagree.
valid?
is about the state in the app
When you update the app-db you are changing that sate
Hmm. What context?
Other data in app-db?
there are two contexts: - UI state - state of application you want the user to be able to put garbage in the UI, and validate it before it populates the application state
It gets complicated to have it in every event handler. We have hundreds of inputs that would all need to be debounced and include the s/valid? call.
And each user imput processed requires that is be recomputed
even still, updating the app-db in this case is expensive because of the validation
you can easily build a debounced-input
component that will track its UI state locally and call the on-change
handler only once per 300ms or so
Indeed
So you are debouncing the changes to app-db
But I'd still be thinking carefully about the expensive validation process.
Is there some way to make that less expensive More incremental
Then, this whole problem goers away
^^ slack reordered my messages, have corrected
There's lots of and
type predicates in this validation that requires a larger "scope" to correctly validate.
Really the tradeoff is in UX, I suppose. You either provide the user an immediate feedback on valid/invalid or you do it on click.
I think it’s generally accepted practice to have complex UIs that track their state locally and then populate up on debounce/blur/etc. for performance or UX reasons.
Hard to know what to do without knowing your application but you could do:
1. Update the app-db straight away
2. signal that you want to do a validation in 300ms time
Which is effectively debouncing the expensive valid?
check
But updating app-db straight away
problem is that you still need to do the work of debouncing the signal to validate or else you still end up chugging
Dunno if that would work
the use case I had recently was filtering a huge table of complex, calculated data. there had been several attempts to address this with various methods, one of which was firing an event to do the re-calculating <n>ms after updating the db with the filter. this still caused lag, because the CPU from the re-calc events would end up blocking the event queue
1. it’s quite easy to debounce the input using the google closure library, whereas debouncing a dispatch required us to do side-effects directly in our event handler
2. we can now remove all of the logic spread across our event handlers in dealing with this perf problem and instead isolate it to this component that is a drop-in replacement for an :input
tag