Fork me on GitHub
#clojurescript
<
2019-10-20
>
lilactown00:10:06

@benzap I have used binding with async code in the past where, on each async boundary, I lexically bind the current value of the dynamic var outside, then inside re-`binding` the dynamic var

lilactown00:10:50

example:

(def ^:dynamic *foo*)

(defn use-foo-broken []
  (prn *foo*)
  (js/setTimout use-foo-broken 100))

(binding [*foo* "bar"]
  (use-foo-broken))
;; prints: "bar" nil nil nil ...

(defn use-foo-works []
  (prn *foo*)
  (let [foo *foo*] ;; lexically bind the current value of *foo*
    (js/setTimeout 
      (fn []
        (binding [*foo* foo]
          (use-foo-works))) 1000)))

(binding [*foo* "bar"]
  (use-foo-works))
;; prints: "bar" "bar" "bar" "bar" ...

lilactown00:10:07

it’s pretty gross for userland code, but I’ve used it with success for library-level code to build powerful abstractions in CLJS

lilactown00:10:14

I can’t remember if binding conveyance works in cljs.core.async

lilactown00:10:13

but something like that could be used to provide binding conveyance at a syntax level

benzap00:10:50

@lilactown this seems like a pretty awesome workaround, thanks! I wish I knew about this before I changed a bunch of code a wrote a while back, haha

kwladyka19:10:06

What is you favourite way to record GIF images from your website? Like 1) click here, scroll mouse, write something here, wait x sec. But not for testing, but for GIF recording from your website. What tools do you use for your SPA in cljs?

p4ulcristian19:10:32

Hey guys, how I call #'component' with parameters? I need to pass around reagent componenents, and it works, but can't do it on components with parameters. Where component is (defn component [some-props] [:div some-props])

lilactown19:10:35

@paul931224 I don’t know what you mean by call. how are you trying to call it?

lilactown19:10:56

[component "hello"] when it’s inside of another reagent component

p4ulcristian19:10:40

this is what I mean, I tried it with (apply components props), but it didn't work, I don't really understand this part yet 😄

p4ulcristian20:10:23

@lilactown I guess my question is how would you make a wrapper component which counts how many times did its child re-render. I may have approached it in the wrong way

dpsutton20:10:30

(into [component] args)

lilactown20:10:48

You can't measure how many times a child rendered afaik

lilactown20:10:28

Unless the component communicates to it's parent explicitly

p4ulcristian20:10:42

well somehow it must be possible, I watched https://youtu.be/g01dGsKbXOk?t=664 and I very much like the idea of a render visualizer, that's my first approach to it.

p4ulcristian20:10:09

@dpsutton this doesn't work either 😕

lilactown21:10:44

@paul931224 that component he’s talking about is used as a mixin

lilactown21:10:04

(which are deprecated in React but you can do some similar things with class inheritance or a helper function)

lilactown21:10:51

it’s not tracking how often its child re-renders, but how often the component the visualizer is used in re-renders

ingesol03:10:35

Hi! I don’t have time to go in depth on this, and giving a proper answer would require some more context. But here’s a reagent implementation of modals, might help: https://github.com/Frozenlock/reagent-modals

ingesol03:10:27

this one might be simpler to understand https://github.com/benhowell/re-frame-modal

reallymemorable15:10:08

Basically, I want to do something along the lines of:

[:div {:class "bp3-button", :on-click #(js/confirm "App settings go here")}
[bp/icon {:icon "cog", :style {:color "#555555"}, :on-click #(dispatch [:div {:show? true, :child [myDialogPopup]}}]
]

reallymemorable15:10:22

Not sure if that makes it any clearer

reallymemorable15:10:09

I want to replace the standard Javascript confirm that is currently prompted --- :on-click #(js/confirm "App settings go here") --- to something that displays the custom blueprint popup I have defined in the gist.

reallymemorable21:10:12

im new to cljs and lost