Fork me on GitHub
#re-frame
<
2019-09-17
>
restenb18:09:54

so i'm on a re-frame app with ring/compojure backend and just added wrap-keyword-params middleware to keywordize request params

restenb18:09:31

which works, but then crashes (I assume when generating a response) with java.lang.IllegalArgumentException: No implementation of method: :write-body-to-stream of protocol: #'ring.core.protocols/StreamableResponseBody found for class: clojure.lang.Var

restenb18:09:43

if I remove the middleware, everything works fine

jahson18:09:26

It might be the order of middlewares

johanatan20:09:51

in re-frame 10x, how do people handle the fact that time travelling back to previous epochs may kick off event dispatches that result in ajax loaders running which of course generate new epochs, browsing you away from the epoch you were trying to view and to the tail of the epoch list ?

isak22:09:01

What do people do when wanting text input controls that 1) don't stutter, and 2) can be provided a different value from outside the field?

Lu22:09:14

For my personal experience I wouldn’t use re-frame to store input values.. I put together some lines of code to leverage both reagent and re-frame without storing the local inputs in the global state.. feels unnecessary .. you can use the function set-values to set the inputs from outside a field component https://github.com/luciodale/fork

isak22:09:09

@UE35Y835W interesting, that seems like a big problem though, because you loose all the benefits of one global app-state

isak22:09:56

E.g., it is pretty common for there to be more than 1 way to set some piece of data

isak22:09:16

So if I were to do it with a function, for example, I'd need to maintain a list of all refs for each piece of state, then call a function on all those refs anytime there was a change triggered from outside the text component. Seems bad

Lu22:09:54

You would update directly the local state and the component picks it up automatically.. that’s how it is done

isak22:09:04

Maybe a good way would be to just use a reagent/atom, but then also reset that in a lifecycle method when appropriate. Then you get the perf, but also the global app-state

Lu22:09:50

If your component is unmounted the local state is reset automatically :)

isak22:09:51

along with only updating the global-state with on-blur

isak22:09:19

Hm, are you suggesting managing react-keys or something? Because otherwise I can't rely on the component getting re-mounted

isak22:09:36

Both it and the other component triggering an update to its state may be mounted at the same time

Lu22:09:58

What is exactly your use case?

Lu22:09:43

You have an input being set by itself and another input?

isak22:09:28

yea, but the other thing is more like a button, not another text input

isak22:09:48

I think the lifecycle thing I was talking about will work though

Lu22:09:43

Yes, I agree you should store it in an ratom.. this is a perfect use case for the lib I linked.. but feel free to implement some logic yourself :) .. I don’t think you need to manage any lifecycle at all.. you can simply pass the derefed atom as a param to an event whenever the user submits or leaves the view

Lu22:09:58

(defn foo []
  [fork/fork {:initial-values
              {"input" ""}}
   (fn [{:keys [values
                set-values
                handle-change
                handle-blur]}]
     [:div
      [:button 
        {:on-click #(set-values {"input" “hello”})
        “Click me”]
      [:input
       {:name "input"
        :value (values "input")
        :on-change handle-change
        :on-blur handle-blur}]])])

Lu23:09:25

It would be as simple as this :)

isak23:09:57

hm, I think that will make the rest of the app a little less convenient. I will paste what I have in mind soon, sec

👍 4
isak23:09:55

Yea, looks like this works, without requiring me to change any other code: https://gist.github.com/isaksky/75277660572c079a97b71babe80b5667

lilactown23:09:52

I just today wrote a component for work that debounces on-change, and uses a couple of local atoms to track the state in between on-change fires

4
stathissideris07:09:24

@U4YGF4NGM I was just doing that yesterday, it sounds like it’s a common problem

stathissideris07:09:30

I ended up using an r/atom to track local content and a normal atom for the timeout object. The local content is cleared whenever the input loses focus, so “external” values (from the global state) can be rendered instead when the global state changes

isak14:09:50

@U050AACJB interesting approach. Do you get a 'flash of old content' when tabbing out, though?

stathissideris14:09:19

this is very new, so not well tested yet, but I didn’t notice that. By the time I tab out, the content should have propagated to the global state, so why should I see the old content at all?

isak14:09:11

it looks like it clears the local ratom before the debounced dispatch

isak14:09:16

E.g., , start new field, keep typing continuously (no 300 ms break), then tab out. I'd expect to see the field flash back to initial state "" for debounce duration before it shows the new value

stathissideris21:09:18

I tested this and you’re right, there is a flash, but not to the initial state (`""`) but to some previous shorter string that the user typed

stathissideris21:09:49

oh it’s worse than I thought, longer debounce timeouts uncovered a bug…