re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
Gerome 2020-12-03T08:18:01.405600Z

Hello fellow clojurians! The other day, I was trying to build an input field that doesn't have its state in a reagent atom but stored in the db. I thought that introducing a reagent atom would introduce state separate from the db. If we have separate state, then there are times when the db doesn't reflect the actual application state and I felt this would break the whole idea of the UI as a state machine. So, this worked for 99% of all use cases until I, being German, started entering umlauts on macOS using dead keys. Suddenly, dead-umlaut + a = ¨ä instead of dead-umlaut + a = ä which is what it's actually supposed to be. I then noticed that in several examples (react, redux, re-frame and re-frame realworld example), everyone introduced a separate state for input fields. Is it even possible to write fields the way I did without breaking dead keys? Is this because of the way React realizes the on-change event? (I noticed that the standard html on-change fires later than the one React implements on the input field.) See an example of how I did this below.

p-himik 2020-12-03T08:22:28.406100Z

Just as an experiment - have you tried using rf/dispatch-sync?

Gerome 2020-12-03T08:36:52.406300Z

Oh, interesting. No, I hadn't tried that. I'm pretty new to re-frame and reagent. I'll check it out.

Gerome 2020-12-03T08:42:13.406500Z

Hm, no, it has the same effect. The only way, I was able to improve this so far was to introduce a huge debounce in an effect that delayed storing the data in the db. However, this only worked after setting the delay to 100ms which made entering letters very sluggish. Maybe, I'll try keeping the reagent atom as an interim state between db and input field.

p-himik 2020-12-03T09:04:02.406700Z

That's an interesting issue, I have no clue what's going on. Alas, I cannot really help - I don't have a macOS and the input methods that I have in Ubuntu all work differently from what you observe.

Gerome 2020-12-03T19:42:10.407200Z

Well, thanks anyway :)

Gerome 2020-12-03T19:43:11.407400Z

Ah! I still had the debounce in place. dispatch-sync did the trick. Many thanks, @p-himik!

👍 1
p-himik 2020-12-03T19:53:48.407700Z

Then this is very much relevant: https://day8.github.io/re-frame/FAQs/laggy-input/