Fork me on GitHub
#figwheel-main
<
2020-07-09
>
dominicm11:07:54

I rebase many times a day, or switch branches, I seem to break my build whenever I do. I get weird errors, usually with broken JS output or similar. How can I resolve this?

dominicm11:07:07

I'm guessing there's no debounce or something

bhauman12:07:53

@dominicm I’m pretty sure there is a debounce

bhauman12:07:07

maybe its not long enough?

dominicm12:07:34

do debounces go into a queue? They should wait for the previous build to finish, if they don't.

dominicm12:07:28

I'll look at what throttle does :)

bhauman12:07:45

it basically says if there are no changes in 50ms

bhauman12:07:58

then continue I think

dominicm12:07:43

right, so no prevention of overlap

dominicm12:07:55

So your build has to be <50ms otherwise 💥

bhauman12:07:10

no between each file change

dominicm12:07:29

Let me re-read, I must have misunderstood

dominicm12:07:43

that's not my interpretation of it

bhauman12:07:45

it runs on the assumption that the time between files changes is small and if it’s exceeded

dominicm12:07:39

yeah, I'm still reading it as not be a debounce. It basically just sleeps 50ms from the first event coming in.

dominicm12:07:01

I should double check my terminology, I know there's a distinction from debounce/throttle, but I forget repeatedly

dominicm12:07:47

yeah, this has 2 big bold definitions. This is a throttle: > Throttling enforces a maximum number of times a function can be called over time. As in “execute this function at most once every 100 milliseconds.” except 50ms

dominicm12:07:59

> Debouncing enforces that a function not be called again until a certain amount of time has passed without it being called. As in “execute this function only if 100 milliseconds have passed without it being called.” This is what you described

bhauman12:07:31

yeah it should be named debounce

dominicm12:07:43

Hmm, no. I'm saying the name is right. It behaves as a throttle?

bhauman12:07:43

dang that algorithm is hard to read first thing in the morning

bhauman12:07:37

ok yeah I guess it is a throttle

dominicm12:07:37

Either way, neither prevents overlapping builds.

bhauman12:07:51

thats true

dominicm12:07:19

You'd need a lock or queue to prevent that.

bhauman12:07:28

wait a second

bhauman12:07:02

hmmm OK yep

bhauman12:07:17

this should be easy enough

dominicm12:07:28

Great. 😁

bhauman13:07:27

(defn throttle [millis f]
  (fn [{:keys [collector] :as ctx} e]
    (let [collector (or collector (atom {}))
          {:keys [collecting? events]} (deref collector)]
      (if collecting?
        (swap! collector update :events (fnil conj []) e)
        (let [events (volatile! nil)]
          (swap! collector #(-> %
                                (assoc :collecting? true)
                                (update :events (fn [evts] (vreset! events evts) nil))))
          (future
            (f (cons e @events))
            (Thread/sleep millis) ;; is this needed now?
            (swap! collector assoc :collecting? false))))
      (assoc ctx :collector collector))))

bhauman13:07:54

@dominicm deployed the fix to 0.2.10-SNAPSHOT

bhauman13:07:05

thanks for prompting me on that

dominicm13:07:22

hum, that doesn't look right to me. Doesn't that call f straight away?

bhauman13:07:36

yes but it works

bhauman13:07:51

well I changed it

bhauman13:07:59

(defn throttle [millis f]
  (fn [{:keys [collector] :as ctx} e]
    (let [collector (or collector (atom {}))
          {:keys [collecting? events]} (deref collector)]
      (if collecting?
        (swap! collector update :events (fnil conj []) e)
        (let [events (volatile! nil)]
          (swap! collector assoc :collecting? true)
          (future
            (try
              (Thread/sleep millis) ;; is this needed now?
              (swap! collector update :events (fn [evts] (vreset! events evts) nil))
              (f (cons e @events))
              (finally
                (swap! collector assoc :collecting? false))))))
      (assoc ctx :collector collector))))

bhauman13:07:43

when collecting? is true things get collected, and f is blocking

dominicm13:07:46

ah, so it cleans up at a different time, nice. Subtle.

bhauman13:07:44

less machinery and relying heavily on the properties of atom

dominicm13:07:18

Does the event list grow forever? I just noticed that.

bhauman13:07:41

(swap! collector update :events (fn [evts] (vreset! events evts) nil))

bhauman13:07:55

sets it to nil

bhauman13:07:24

relying on swap to grab the current events and delete them atomicly

dominicm13:07:12

ah, I see. And then any that come in during f will be collected and in the queue for later, great!

bhauman13:07:50

yeah it was right there, I guess I was tired/lazy when I was initially coding it??

bhauman13:07:06

so similar to the original version

dominicm13:07:37

There's a lot of considerations to factor in this little function. State is really hard.

dominicm13:07:47

Those 15 loc are thick with meaning.

bhauman13:07:20

can’t argue with that

bhauman13:07:41

but its really nice to have that fixed

bhauman13:07:23

@admin055 I got rid of the dependency on create-react-class so that’s no longer a problem

bhauman13:07:01

I’m now going to install android … which I was avoiding until now

Michaël Salihi14:07:03

@bhauman Perfect, thx for the information.

Michaël Salihi14:07:45

> Thanks for trying this out @admin055 > I really need this early feedback to work out the last bugs.  Sorry I > didn’t try this with android.  It’s such a large setup time. it's always a pleasure to use and test your work. I'll retry today later and let you know.

Michaël Salihi15:07:49

Thx @bhauman, all works perfect on Android emulator for me now. For Android emulator and real devices, we must only do on more command: adb reverse tcp:9500 tcp:9500 to get access to:

Michaël Salihi15:07:18

Last night it was too late i didn't even think about that! :)

Michaël Salihi15:07:30

Android real device test checked ✔️

bhauman15:07:58

oh really wow

bhauman15:07:36

Would you want to add android notes to the react native figwheel docs?

bhauman15:07:53

also you may want to try the :launch-js configuration and see how it works?

bhauman15:07:38

especially if when you stop figwheel and relaunch

bhauman15:07:00

without closing metro or android

bhauman15:07:06

it should just work

Michaël Salihi16:07:00

@bhauman > Would you want to add android notes to the react native figwheel docs? PR done. > also you may want to try the :launch-js configuration and see how it works? Work perfectly, nice work!

bhauman18:07:52

This is fantastic! Great!

👍 3