Fork me on GitHub
#re-frame
<
2023-02-01
>
hifumi12307:02:00

Does anyone here use a custom clj-kondo config for re-frame? I found two interesting options but they seem unmaintained

p-himik07:02:15

No idea what you're looking at, but it's quite often that something in the CLJ world appears unmaintained where it's actually simply complete.

p-himik07:02:14

So why do you think it's unmaintained? It's been last updated just a year ago. Does it not work?

hifumi12307:02:54

I guess I can try them out… I was just wondering how many people actually use these custom linters

p-himik07:02:01

FWIW, I don't. :) There are 2 linters in the first project. The first one now has a warning issued by re-frame itself and the second one doesn't seem that useful because the app will blow up as soon as you use such an event. The second one seems a bit more useful though.

hifumi12307:02:54

Sweet. 🙂 I think I’ll try the gist and see if I get a more helpful experience than what clojure-lsp already offers (namely, autocompleting keywords and jumping to definition)

hifumi12307:02:51

For some context: I’ve decided to start customizing clj-kondo for some things like line length limits, and I figured I may as well check out custom linters people use for popular libraries out there.

p-himik07:02:03

Yeah, that makes sense.

borkdude08:02:00

Why would you need extra config for re-frame?

p-himik08:02:02

The second link has some IMO useful linters, like the :<- check (which could also be expanded to :-> and :=>, I imagine).

hifumi12308:02:16

For me: mostly bells and whistles to improve the programming experience. While an unused sub may cause clj-kondo to warn the user about unreferenced keywords, it seems nicer to me to explicitly say “this subscription is not being used anywhere”. Or possibly catching anti-patterns like calling rf/subscribe outside of a reactive context So that’s why I ended up searching around for re-frame-specific setups

👍 2
joshcho17:02:21

What is an idiomatic way to keep track of focused item? Should the focused element be kept as part of app-db (if so, then keeping track of element id?) or something else? Then perhaps every switch of focus (like tab or mouse click) must be captured in order to fire off the correct event that changes app-db? Curious how others have managed this.

zalky18:02:25

Hi, so in the past I've modelled focus using a combination of things: 1. Each component that needs focus gets a unique id 2. There is a global piece of state that tracks what component currently has focus, usually this would be modelled as a stack so you can return focus to previous components 3. Reactive subscriptions that depend on the global piece of state, and whether the component should regain focus I'm actually releasing a library in the next couple of days that helped me with 1, and tying everything together.

p-himik18:02:33

To properly answer the OP's questions, one would need to know why focus tracking is needed in the first place. And what "tracking" means exactly.

joshcho18:02:42

I would like to keep track of a focus in a cell in a table, and depending on keyboard input, perform certain actions on the table. For instance, "j" would go down a cell, "h" would go left a cell. I have other things (like cloning a cell with "c") that are not necessarily navigational, so keeping track of which element is in focus is important. And by tracking, I just mean having it be subscribable by other elements of the webpage.

p-himik18:02:53

Instead of keeping track of the focus, I'd: • Intercept all keyboard events of interest • In the event handler, get currently focused element • Figure out how that focused element should react to that keyboard event, if at all

❤️ 2
zalky18:02:53

👆This is good. I would also add that you need to determine whether you are dealing with input elements, and need to shift the cursor between those input elements. Or whether you are simply showing visual feedback to the user about the currently "active" cell.

joshcho21:02:20

Thanks, that seems like a better way to go about it.

joshcho17:02:59

In a similar fashion, how do people keep track of mouse position?

zalky18:02:44

Mouse position is a little different because it is not necessarily tied to any one component, and depends on what you're trying to accomplish. If you just want to always have the current position of the mouse represented in app state, then you probably want to attach a global "mousemove" event listener to the document, and on each event, grab the mouse position from the event and add that to your global state in your db. There's some considerations here about maybe wanting to debounce that, so you don't unnecessarily thrash your db with excessive updates. Also, depending on what you're trying to do you may want to conditionally enable or disable that global "mousemove" listener over time. For example, if you are dragging something and want to track the mouse position, you only really want the listener enabled for the duration of the drag.

❤️ 2
joshcho18:02:14

Thanks! I can see how they are different.

dvingo21:02:16

I always thought this technique using core.async was really elegant: https://swannodette.github.io/2013/07/12/communicating-sequential-processes/ and the accompanying talk https://www.youtube.com/watch?v=AhxcGGeh5ho doesn't really deal with tracking the state, but if you're doing interactive dynamic UI with events it can be quite elegant