This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-26
Channels
- # arachne (80)
- # beginners (76)
- # boot (16)
- # cider (66)
- # cljs-dev (62)
- # cljsjs (1)
- # clojure (106)
- # clojure-dev (5)
- # clojure-greece (2)
- # clojure-italy (9)
- # clojure-russia (1)
- # clojure-spec (61)
- # clojure-uk (130)
- # clojurescript (21)
- # core-async (9)
- # cursive (3)
- # datomic (37)
- # events (41)
- # figwheel (31)
- # fulcro (27)
- # hoplon (1)
- # jobs (2)
- # lumo (11)
- # off-topic (155)
- # re-frame (71)
- # reagent (27)
- # ring-swagger (3)
- # shadow-cljs (132)
- # spacemacs (5)
- # specter (1)
- # sql (37)
- # test-check (10)
- # uncomplicate (5)
- # unrepl (2)
- # yada (3)
I moved my comments to a thread since I didn’t mean to spam this man channel - Sorry if that was confusing.
If anyone knows how to force a component with local state to reload from scratch, it might save me a bunch of time. any takers?
(defn text-area [{:keys [path default-value id] :as props}]
(let [value (r/atom (if default-value default-value ""))]
(r/create-class
{:display-name "text-area"
:component-did-mount
(fn text-area-did-mount [this]
(js/autosize (r/dom-node this)))
:reagent-render
(fn text-area-render [{:keys [path default-value id] :as props}]
[:textarea.form-control.autosizing
(merge (dissoc props :path)
(addid
id
{:value @value
:on-change #(reset! value (-> % .-target .-value))
:on-blur #(rf/dispatch [:update-value path @value])}))])})))
Seems there is no way to change the state inside a component from outside. So... will try another way. cheers 🍺
I did get it to work by hiding the component, then enabling it later, but that was pretty hacky
On mobile so can’t get the full context from the code, but a hack is to change the ^{:key for a component to force it to be created
re-frame-trace 0.1.16 is out https://github.com/Day8/re-frame-trace/releases/tag/0.1.16. Now with React 16 and Reagent 0.8.0 support
@danielcompton thanks, it removed the React.createClass is deprecated and will be removed in version 16
warning from my console
@danielcompton I just upgraded re-frame-trace
on a project where I’m using [garden "2.0.0-alpha1"]
. It seems that my version of garden takes presidence, but it’s API is not compatible. Do you know of a quick-fix?
I've pushed out a release bundling Garden source dependencies in 0.1.17-20180127.054500-1
, can you give it a go and let me know how you get on?
Hi, I’m sorry for the late feedback ;( Unfortunately, it did not solve the issue completely, it failed at another fn
It doesn’t seem like the correct behavior by ClojureScript. Versions are pinned, so both should be running side-by-side
just wrapping my head around the undo fx: if a dependency of my project also uses undo and it mutates the config with custom harvesters, those configurations leak into the parent app, right? https://github.com/Day8/re-frame-undo
Hi! I'm trying to figure out how a subscription in re-frame works. Maybe some can help me? I've always believed that calling (subscribe [:something])
returned something which is exactly the same as a reagent reaction. However, I when I deref a subscribe
in a reagent run!
macro, the body isn't rerun when the subscribed data changes...
This does work however when I replace subscribe
with a reaction. For example (reaction (::db/cart @re.frame.db/app-db))
. I cannot figure out why this is different...
Hello, I’m trying to learn re-frame to upgrade my cljs apps. Are there any resources/tutorials/books out there that may help me?
I liked the todomvc implementation https://github.com/Day8/re-frame/tree/master/examples/todomvc
@U7V9HE682 there's tons of docs as well in the re-frame repo
There's also https://github.com/Day8/re-frame/tree/master/docs#commercial-grade-video-training
@stex subscribe
does return a reagent reaction. The reaction is created when you call reg-sub
. See here: https://github.com/Day8/re-frame/blob/master/src/re_frame/subs.cljc#L327
@kenny Thanks! The puzzeling thing is that a subscribe
doesn't work in a run!
macro, which is essentially just a reaction which auto-runs.
See: https://github.com/reagent-project/reagent/blob/master/src/reagent/ratom.clj#L9
@hkjels https://clojurians.slack.com/archives/C073DKH9P/p1516959476000169 You can only run one version of a library at a time, Leiningen/Boot will only pick one if there are multiple different versions required
hi gang ... hoping someone could point me to a tutorial on file downloads (alternately, tell me that I'm fundamentally misconceiving this problem):
I have client-side state that I want to render as an Excel file, and js-xlsx isn't going to cut it, so I'm wanting to use docjure.
my current experiment, summarized: user hits "download as excel" button. This dispatches a please-download event. Event is caught by fx handler.
fx handler sets a "downloading" flag in app-db for UI feedback, and dispatches an http-xhrio
POST with the browser-side data from the app-db.
a ring handler picks up the POST data, does what it needs to do to make up an Excel file, and ...
so here's where I go off the rails. I've tested giving back a text file in the xhrio success handler with the Content-Disposition header set to attachment but that's almost certainly not what I want and I've run smack into the joy that is dealing with file writes in a browser.
so I can log the text file contents (ie. cljs-ajax is receiving OK) in the re-frame event handler, but I'm scratching my head a bit on the right thing to google here.
@rgm what exactly is the problem? i.e. what do you want to happen that isn't happening here?
Sounds like you're wanting to trigger the browsers file download mechanism?
Experience suggests I'm off the track here given there's no obvious re-frame doc to read.
Ignoring re-frame for a second, how would you do this with JS or CLJS?
probably just do a straight-up form POST and have the server use Content-Disposition in the response to trigger a download.
that'll work, at which point re-frame's job is really just to keep a hidden input's value in sync with the app db.
so yeah, assuming the /xlsx
endpoint sends down a Content-Disposition: attachment; filename="testfile.txt"
this invokes a download
Does an XHR POST have the same effect?
outside of re-frame
re-frame's role with fx is around translating stateful actions into data descriptions
Doing it with cljs-ajax directly in the event handler instead of emitting the effect
Content-Disposition seems not to have an effect, which also (kind of?) makes sense to me.
@rgm I chime in here incase it is useful. Using a side-thread to not overly spam the re-frame
channel. I can’t be sure, but I think you are really wanting an xhrio (async) request/response that triggers a file download. content-disposition
doesn’t work for that need since you end up needing to programmatically trigger the browser to save the file. At least, this has been my experience.
I have had the most luck with using the popular FileSaver.js
lib (which supports a wide-range of different browser oddities) for doing programmatic client-side JS things that trigger browser file downloads.
I think this approach will most smoothly fit into the model of using xhrio to get the (binary) xls data back and programmatically triggering the download if that is successful vs not
And luckily, with FileSaver.js, there is a CLJSJS package for it already available, unless you have particular reasons you don’t want to use CLJSJS. You may be able to do some node module for it or something too, I just haven’t to give you experience on that.
So Basically, you end up with
(:require <etc> [cljsjs.filesaverjs] <etc>)
(defn write-xls! [xls-data filename]
(let [blob (js/Blob. #js[xls-data]
;; NOTE: I think this long thing is the mime type for xlsx
#js{"type" "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})]
(js/saveAs blob filename)))
With something like that, you can use re-frame
around all the other edges of the interchange between client-server and app state
I believe you could just put the write-xls!
call itself in a re-frame
“effect” via rf/reg-fx
Oh nice. Thanks. I used filesaver a while back for a weird data:
URL file generation scheme. 🙏
Had kind of forgotten about it because it had some Safari limitations but looks like those have been addressed.
At least this time it’s CLJ on the server side and I’m not doing Node acrobatics to avoid blocking the main loop during file generation.
Greatly appreciate the help @danielcompton ... I think the short version is that I was on the wrong path and overthinking it.