This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-21
Channels
- # beginners (5)
- # boot (15)
- # capetown (1)
- # chestnut (2)
- # cljs-dev (9)
- # cljsjs (3)
- # cljsrn (1)
- # clojure (190)
- # clojure-brasil (2)
- # clojure-greece (14)
- # clojure-italy (3)
- # clojure-poland (8)
- # clojure-romania (1)
- # clojure-russia (2)
- # clojure-serbia (3)
- # clojure-spec (38)
- # clojure-uk (98)
- # clojure-ukraine (2)
- # clojurescript (65)
- # clojurex (1)
- # core-async (16)
- # cursive (16)
- # datomic (3)
- # defnpodcast (7)
- # emacs (11)
- # funcool (2)
- # hoplon (16)
- # jobs (1)
- # leiningen (4)
- # lumo (9)
- # off-topic (2)
- # om (1)
- # other-languages (1)
- # protorepl (1)
- # re-frame (50)
- # reagent (16)
- # reitit (32)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (73)
- # spacemacs (36)
- # specter (21)
- # sql (6)
- # unrepl (107)
- # untangled (4)
Reminder, there are commercial courses on re-frame
available here:
https://purelyfunctional.tv/courses/understanding-re-frame/
@danielcompton maybe x kb or xx kb in my page. It seems the key strings are used for check specs?
currently we have this js file online: https://m.joudou.com/asset/doumi/js/doumi.9e08d9.js
maybe like @mikethompson says, if we do not use check specs, the key strings will be advanced compiled away? I haven't tried this.
@cmal the ClojureScript keyword:
:annc-toggle-display-type
is transpiled to:
var blah = new Keyword(... "annc-toggle-display-type", ...)
which, after :advanced
, becomes:
var Jj=new M(null,"annc-toggle-display-type","annc-toggle-display-type",-302319952)
So, yes, when you use keywords, you end up with strings.
On JS platforms, strings are interned. So although a string might appear multiple times in the source (which is bad because it increases load times), once the strings are loaded, there will only ever be one copy of any one string.
Either way, this is a ClojureScript thing, an not something we have any control over. It arises from use of KeyWords.
Thanks @mikethompson. Is this related to that I used the specs (like the todomvc exmaple)?
specs involve keywords, so yes
See above my notes on how keywords are transpiled
If you use keywords, you'll end up with strings
But this is generally not much of a problem
You'd have to be using a LOT of keywords for it to be an issue
So every keyword I used in the handlers and subscriptions are compiled. I am just not sure about this. 😄
Thank you very much @mikethompson
hi, is there a way to fetch app.js
with async option? I see that even the production build does document.write
which makes async option when loading the script not to work. I'd like to fetch app.js
in async way, and then its js to go and modify <div id='app'/>
element. Maybe there's an build option to get rid of document.write?
Hi, is it possible to use an effect multiple times in the same event ? For instance if I have a save-to-db effect and I have one event that saves a thing and another that saves a collection of things I would like to reuse that effect for both and be able to make changes to app-db as well
e.g.
(rf/reg-event-fx
:my-event-a
(fn [{:keys [db]} event-vec]
{:db (update-app-db db)
:save-to-db (extract-things-for-saving event-vec)}))
(rf/reg-event-fx
:my-event-b
(fn [{:keys [db]} event-vec]
{:db (update-app-db db)
:save-to-db (extract-things-for-saving event-vec)}))
your save-to-db effect could just know when to save a coll vs a single based on the incoming args. Or you could have an effect for each. I don’t see what part is what you are specifically curious about though
@mikerod sorry my formulation was not clear, in your code snippet event-b would basically do same as a but for a collection
so one way to achieve it would be to dispatch event a for each element or like cmal suggests have a plural version of the effect
Hi, are there any examples on drag-and-drop
and brush
actions using re-frame
? like https://github.com/d3/d3-brush and https://github.com/d3/d3-drag
I am rewriting a ns that was using old version of re-frame to clean up so the idea is that in one case I receive a status and in the other a collection of statuses
but my question has pretty much been answer I can either use dispatch-n to dispatch one event for each status in the collection or I can use a plural version of the save-discover effect
I’m fighting re-frame syntax again. I have:
(reg-sub
::route
(fn [_ _]
(subscribe [:dre.base.subs/cur-page-id]))
(fn [cur-page-id]
(subscribe [:page/state cur-page-id]))
(fn [page-state]
(:page/route page-state)))
but re-frame says:
re-frame: expected a vector, but got: λ[cur-page-id]I don't think it's possible to call reg-sub
like that https://github.com/Day8/re-frame/blob/master/src/re_frame/subs.cljc#L203
@borkdude yep, please be sure to read the docs (see Domino 4 heading): https://github.com/Day8/re-frame/tree/master/docs#domino-4-subscriptions
I have read the docs and I watched that infographic before asking this questino… again 😉
No problem, if there's anything the dosc should make clearer please be sure to say
One thing that isn’t obvious to me is this one:
:<- [:todos]
Can that handle arguments as well? Like :<- [:todo id]
?
No, it can't handle arguements
It is just syntactic sugar for simple cases
so in general, it possible to have one or many unrelated signals in a subscription, but no chaining of signals in one subscription -right?
Yes, but I'd say it like this:
1. A subscription can have many input signals
2. But it represents only one node in an eventual signal graph
3. If you want to define multiple nodes, which chain, then that's multiple reg-sub
calls
is there any way in a registered -fx
handler to automatically get something out of the app-state database, without having to have it passed in?
not as far as I know, unfortunately, you have to get the bits you need in the handler and pass them through
We have our app db organized like this:
{:cur-page-id :page/search
:page/search {:search/query …, :page/title "Search",},
:page/details {:page/title "Details"}}
We also have a wrapping component, which displays the :page/title
of every selected page. The disadvantage of this structure is that you need a subscription on the whole db to get to the page title, because the currently selected page :cur-page-id
is dynamic. We could refactor this, but maybe it’s good to know first what this costs in performance. Is there a way to measure this properly?
We could e.g. go to:
{:cur-page-id :page/search
:titles {:page/search "Search", :page/details "Details"}
:page/search {:search/query …,},
:page/details {...}}
so the wrapping component would only need to subscribe to a subscription which looks at :titles
instead of the whole dbnot as far as I know, unfortunately, you have to get the bits you need in the handler and pass them through