This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-10
Channels
- # aleph (1)
- # aws-lambda (1)
- # beginners (80)
- # boot (20)
- # cider (75)
- # cljs-dev (45)
- # cljsjs (1)
- # cljsrn (11)
- # clojure (428)
- # clojure-dusseldorf (13)
- # clojure-italy (4)
- # clojure-russia (153)
- # clojure-spec (47)
- # clojure-taiwan (1)
- # clojure-uk (62)
- # clojurescript (84)
- # cursive (19)
- # datascript (96)
- # datomic (75)
- # dirac (9)
- # docs (3)
- # emacs (19)
- # jobs (5)
- # jobs-discuss (20)
- # jobs-rus (17)
- # lein-figwheel (5)
- # leiningen (1)
- # liberator (4)
- # luminus (12)
- # off-topic (4)
- # om (31)
- # onyx (102)
- # pamela (1)
- # parinfer (3)
- # pedestal (3)
- # proton (1)
- # protorepl (14)
- # re-frame (54)
- # reagent (22)
- # rum (40)
- # spacemacs (2)
- # specter (8)
- # test-check (5)
- # unrepl (110)
- # untangled (80)
- # vim (3)
- # yada (46)
@petr What does the :set-active-panel event handler look like? And the :active-panel subscription?
@gklijs should be fine
@petr shouldn't it be (re-frame/subscribe [:active-panel])
?
[
:set-active-panel
:job-panel
:CleverTraining
]
is what I see in frisk, however I have this sub
(re-frame/reg-sub
:active-panel
(fn [db _]
(:active-panel db)))
When I try to do anythign similar to this, the page breaks
(let [moo (re-frame/subscribe :active-panel)]
;;(js/alert moo)
(js/console.log (first moo))
[re-com/v-box
:gap "1em"
:children [[re-com/title
:label (str "This is the moo Page." moo "JKFKDJF")
:level :level1] [link-to-home-page]]])
@petr For starters, it should be (re-frame/subscribe [:active-panel])
(like @alanspringfield said)
@curlyfry I'm confused, if you look at this line,that's what I'm doing: moo (re-frame/subscribe :active-panel)
(re-frame/reg-event-db
:set-active-panel
(fn [db [_ active-panel]]
(assoc db :active-panel active-panel)))
So you wanted to include job in your dispatch, right? Try logging active-panel
and I think you'll see that it just evaluates to :job-panel. You have to set up your parameter list correctly!
Your event handler does not expect a job
parameter as it is defined now, and no job
is assoc
d anywhere in the db
Sorry. I meant in reply to Try logging active-panel and I think you'll see that it just evaluates to :job-panel
In essence, I could do this:
(re-frame/reg-event-db
:set-active-panel
(fn [db [_ active-panel params]]
(assoc db :active-panel active-panel :params params)))
re-frame lets you choose how to do stuff like this this yourself, it's not coupled to any routing library
You could possibly also use something like secretary/decode-query-params
and just look at whatever value is in the url in the browser
I do have one question regarding correctness. Let's pretend I went with my current solution. Would it be more correct to add additional params to the :set-active-panel
or to do another dispatch
?
I did something very stupid. Now, I get a react error of : "Error: Invalid arity: 1" clearly this is my fault with my Hiccup somewhere. Problem is: I have no idea where.
@curlyfry So one error I was making is that I needed to deref. However, moo
now returns :job-panel
. Is there a way to get the last element of the vector?
Hello everyone, I use the standard re-frame template with +routes. I have a route "/items/new" which opens a panel with a form for adding new items. If the user clicks on a save button I add the new element to the database and call "dispatch [:set-active-panel :items-index]" to redirect the user to a panel which shows all saved items. My problem is, that this does not change the route (url in the address bar). What is the right way to handle the panel change after clicking on the button?
i typically force everything through the router
so, after adding the element, you change the URL with ... can't remmber the function off hand, (secretary/dispatch!) or something like that
in the defroute, that is where you would dispatch the [:set-active-panel :items-index]
Thank you, yes the dispatch in the defroute was already defined but I did not know about the dispatch functionality of secretary. This should solve my problem - thank you 🙂
It seems as if secretary/dispatch! will only call the function which is defined via defroute, but will not change the url in the address bar
@burke: https://github.com/yogthos/memory-hole/blob/master/src/cljs/memory_hole/routes.cljs might help as an example of how to use secretary and re-frame together
alternatively you can use bide (https://github.com/funcool/bide) which can be integrated with re-frame easily
we’re using it on a fairly large re-frame app, very easy to see all routes in 1 place + we have 2nd router for REST API calls
thanks for the help! @kishanov But this will only handle URLs which are navigated by the browser (a-href links or address bar). In my case the navigation should be invoked if the user clicks on a button (which has no links defined via html). So the missing part for me, was the accountant library which is used in the example from @shaun-mahood
@burke quick solution would be to define an event handler that can do that, something like this
(re-frame/reg-event-db
::redirect!
(fn [db [_ name params query]]
(let [ui-router (get-in db ui-router-db-path)]
(set! js/window.location.hash (ui-path-for ui-router name params query)))
db))
or if you don’t want to have permalink for every view in your screen - just set something like :active-panel
in db
we pretty much adopted the philosopy of keechma (https://keechma.com/guides/router/) for routing and translated it to re-frame.
@kishanov yes, thats similar how I've implemented it. The difference is, that I dont want to use "js/window....". I prefer having some kind of abstraction layer between my application and the "native" js calls - therefore I replaced the "set! js/window..." part with accountant/navigate!
There's also sibiro if you're looking for routing libraries that don't drive you insane with weird, unnecessary complexity: https://github.com/aroemers/sibiro
One nice feature is that it works on the CLJ side as well if that's something you need
Also there's pushy which is a nicer interface to the HTML5 history stuff: https://github.com/kibu-australia/pushy