This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-28
Channels
- # ai (1)
- # beginners (239)
- # bitcoin (1)
- # boot (4)
- # cider (5)
- # clara (3)
- # cljs-dev (16)
- # cljsjs (5)
- # cljsrn (1)
- # clojure (152)
- # clojure-android (3)
- # clojure-dev (3)
- # clojure-greece (4)
- # clojure-italy (5)
- # clojure-spec (14)
- # clojure-uk (24)
- # clojurescript (81)
- # data-science (1)
- # datomic (47)
- # devcards (34)
- # docs (3)
- # emacs (6)
- # ethereum (1)
- # events (9)
- # flambo (5)
- # fulcro (11)
- # graphql (1)
- # immutant (3)
- # lein-figwheel (2)
- # leiningen (2)
- # luminus (6)
- # lumo (90)
- # off-topic (25)
- # proton (2)
- # re-frame (44)
- # reagent (5)
- # ring (7)
- # ring-swagger (11)
- # shadow-cljs (11)
- # spacemacs (6)
- # vim (13)
- # yada (25)
and I have more than one component that needs to use the input, so I can’t really use .-onkeydown
could be like so: require [goog.events :as events]
and then (events/listen js/window (.-KEYPRESS events/EventType) (fn [ev] (foo)))
@yury.solovyov it would have the same issue I think
I’ve tried a few different approaches. The one sketched above will have the key set for two lifecycles, so in my case the caret jumps two positions instead of one upon a single press
if I use .-onkeydown
from within form-1
components, one will overwrite the other and lastly, if I use addEventListener
within a form-1
it will be re-added upon every change
@hkjels What is your dispatch doing? Updating the state with the currently pressed key?
And you move the caret based on that state? It's a bit hard to help without more code/context
Ok! I think a better approach would be to not move the caret based on the currently pressed key, but instead have the caret position as part of the state and compute the new caret position in your keydown event handler
Read the whole convo, this really seems like a way to go to me to, @hkjels - I think I would do it this way, too
I would totally agree if this was in re-frame land, but it’s more in reagent land to be honest
… but you can do the same thing with reagent, no? re-frame is just structured reagent.
(that could be taken as condescending to the re-frame effort, sorry about that guys 😄 But for simple code like this, the statement holds, I think. Events and subscriptions are *just* ( 😛 ) formal structure around swap!
ing a r/atom and deref
ing the same r/atom . )
Or is there something I’m missing?
That way your behavior is based on when the key event is fired rather than when the browser repaints
Why would you need that? My thought was making a :caret-position
sub that your component can use.
I realize that I really should have posted in the reagent
-channel. This code is in a ui-library with mostly local state using atoms
Read the whole convo, this really seems like a way to go to me to, @hkjels - I think I would do it this way, too
@hkjels have you looked at re-com? There might be some key event stuff there, I can’t remember
@danielcompton nope. I’ll do that