This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-22
Channels
- # beginners (240)
- # boot (23)
- # bristol-clojurians (3)
- # cider (101)
- # cljs-dev (52)
- # cljsrn (17)
- # clojure (212)
- # clojure-dusseldorf (2)
- # clojure-greece (2)
- # clojure-italy (9)
- # clojure-russia (1)
- # clojure-spec (91)
- # clojure-uk (33)
- # clojurescript (164)
- # community-development (23)
- # core-async (24)
- # core-logic (9)
- # cursive (18)
- # datavis (1)
- # datomic (119)
- # emacs (13)
- # events (1)
- # figwheel (2)
- # fulcro (86)
- # graphql (1)
- # immutant (5)
- # jobs-discuss (6)
- # leiningen (19)
- # lumo (46)
- # nyc (7)
- # off-topic (23)
- # parinfer (15)
- # pedestal (3)
- # planck (32)
- # re-frame (48)
- # reagent (75)
- # ring-swagger (13)
- # rum (32)
- # shadow-cljs (402)
- # spacemacs (5)
- # specter (3)
- # tools-deps (11)
- # unrepl (20)
- # vim (135)
- # yada (3)
Does anyone have an example of how to use reagent.core/partial? https://github.com/reagent-project/reagent/blob/1000672d76454bc83001d3a7618a9e2401909bf2/src/reagent/core.cljs#L340-L343
(js/console.log "cljs.core/partial" (= (partial println "foo") (partial println "foo")))
(js/console.log "reagent.core/partial" (= (r/partial println "foo") (r/partial println "foo")))
Real use could look like:
(defn foo-component []
[input-component {:on-change (r/partial change-callback :foo) ...}])
Normal partial here would cause input-component
to be re-rendered always as the on-change function identity could change each rendernice! And it only compares as equal if the arguments do I assume?
I guess the same could be accomplished with
(defn foo-component []
(let [on-change (change-callback :foo)]
(fn []
[input-component {:on-change on-change ...}])))
(js/console.log "cljs.core/partial" (= (partial println "foo") (partial println "foo")))
(js/console.log "reagent.core/partial" (= (r/partial println "foo") (r/partial println "foo")))
Real use could look like:
(defn foo-component []
[input-component {:on-change (r/partial change-callback :foo) ...}])
Normal partial here would cause input-component
to be re-rendered always as the on-change function identity could change each renderI'm kinda in shock that I haven't seen this before
How did I miss this?
Why wasn't I told? :-)
Haven't really used it myself
@mikethompson I know the feeling. Just when you thought that you've seen it all...
as far as I can see, it's similar to using a Form-2 component with a fn bound in a let though
(defn foo-component [{:keys [something another]}]
[input-component {:on-change (r/partial change-callback something) ...}])
although.... if the arguments to the function stay the same, the child wouldn't necessarily rerender
I mean if the arguments depend on the props
In the example, if something
doesn't change, the :on-change
fn shouldn't change either
that's clever
In re-frame terms, this old way:
(defn foo-component [{:keys [something another]}]
[input-component {:on-change #(dispatch [:it-changed]) ...}])
becomes:
(defn foo-component [{:keys [something another]}]
[input-component {:on-change (r/partial dispatch [:it-changed]) ...}])
true, it's a great fit for dispatch
well it won't work with on-change because you'd need the argument...
it would get added as a 2nd argument to dispatch
Indeed. So more thought needed. But I like it.
it could be helpful as an optimization to prevent unnecessary rerenders
Yes, exactly. But how to package it without confusing everyone. I look at things through the lens of "how much docs to explain this"
You could introduce a macro which reuses the same idea as r/partial
: {:on-change (rf/dispatch-fn [new-text] [:it-changed new-text])}
rf/dispatch-fn
being analogous to clojure.core/fn
the danger is that it become hard to grok what's going on behind the scenes
I have 2 components Iām trying to import via shadow-cljs, after previously using the ādouble bundleā method.
One of these components is accessed via [:> foo]
, while the other is [:> (.-default bar)]
Now that Iāve switched the build to shadow-cljs, the first component does not work with either method.
try printing out foo
to the console
these days I always inspect in the console first; it always gives you a first clue
but @thheller may have a better idea what's going on
thats a good start. react component libs are bundled in a variety of ways and something its not exactly clear whether you are supposed to use default export or something else
Let me back upā¦ once Iāve required the componentā¦ Iām using a let binding to get a local name
Like this:
["react-avatar-editor" :as react-avatar-editor]
Itās an empty object ATM š
Let me try the original ns
(:require ["react-avatar-editor" :as react-avatar-editor])
then [:> react-avatar-editor ...]
Well, thatās revealing. Both objects are empty.
what do you mean empty? {}
or null
that's peculiar
how are you printing the object? console.log
?
log
says {}
while dir
shows nothing
I don't know then, except that that's not normal
ok, hold onā¦ back to shadow
Has anyone ever managed to create a file input element in reagent that refuses to actually open the dialog box? I moved some code that used to work into its own file and now this happens. I cannot for the life of me figure out how I broke this.
@lee.justin.m No console clues?
I did one of these recently, but it didnāt break.
If that happened to me I think my first try would be shut down the repl, lein clean
and restart. Sounds like something's corrupted somewhere
Thatās a good thing to try
Also could it be that a function call needs to happen in the same event loop tick as a user click?
A stab in the dark admittedly
Has anyone run into this issue posted here? https://stackoverflow.com/questions/49419189/render-table-element-with-colspan-in-reagent
@lee.justin.m What does the callback look like? Iāve gotten the lambda wrong sometimes, and the event was never handled.
Is your event named correctly? case, etc?
Can you try in multiple browsers?
[:input {:type :file :accept "image/*"
:style {:position :absolute
:top 0
:right 0
:width 65
:height 55
:opacity 0.0
:cursor :pointer}
:on-change #(handle-file-change %)}]
@lee.justin.m You're talking about the browser's built-in file input, with the button you click to select the files, right? If that's not working, there's a good chance something corrupted in the browser itself -- a browser restart and/or hard cache reset might be in order.
Or if you have an :accept
setting, check that for weirdness.
@lee.justin.m did you figure it out?
no. something very strange is going on here. iām trying to reboot the improbability drive
@manutter51 @jmckitrick thanks for your help. the issue was that a back onclick handler in the parent div prevented the native widget from working. Iām quite surprised by that, but maybe the click has to propagate all the way up to work (?)
(the real problem is that my hot reload environment was getting screwed up so i kept doing experiments that werenāt actually having any effect)
Glad you figured it out. Iām also interested in what went wrong in your env, once you know.
okay this is the issue: i was using the the olā āhidden inputā trick. this worked fine before because the visible div button and the input were siblings. then i moved them into their own file and the input became a child of the div. you click on the div, it calls .click on the input, which of course then propagates the click back to the same click handler. i donāt know why this doesnāt cause an infinite loop--there may be some kind of code prevention in the browser for that.