Would like to be able to call arbitrary init-fn with ui-channel & !app in scope.
mjg123 opened this issue · comments
We use secretary & accountant for routing. It's seems currently that it's tricky to integrate with petrol, which is otherwise really nice. Problem:
;; secretary defines routes like:
(defroute "/foo/:id" [id]
(do-something-to-an-atom! id))
Ideally we'd like to be able to petrol/send!
events to the ui-channel instead of directly poking the atom here, but it's nearly impossible to get hold of the channel.
The bidi integration is nice, but we're not keen because (a) it's hard-coded to use the URL fragment (hash) instead of the actual path, and (b) it's not straightforward to make an equivalent for this section of code
petrol/src/petrol/routing.cljs
Lines 19 to 23 in 607166a
history.pushState()
is called. Accountant and secretary solve these problems very nicely for us.
I've forked, to https://github.com/mjg123/petrol to experiment, and am happy to send a PR. My idea at the moment is to add a (optional) 4th arg to start-message-loop!
which is a 2-arg init-fn to be called with ui-channel and app. The calls to defroute
and friends can be inside that fn. What do you think?
Ah. I think I can do this with a separate channel for nav-events which goes into the 3rd arg for start-message-loop
.
Yep - I figured it out:
https://github.com/mjg123/reagent-secretary-accountant-petrol-example
Glad you solved it. As you've figured out, the ui-channel is supposed to be isolated, and adding a new channel for other kinds of event is the way to go. :-)