Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move setting up URL listeners into reg-fx #91

Closed
madvas opened this issue Nov 9, 2017 · 0 comments
Closed

Move setting up URL listeners into reg-fx #91

madvas opened this issue Nov 9, 2017 · 0 comments
Assignees

Comments

@madvas
Copy link
Contributor

madvas commented Nov 9, 2017

Those side effects should be done in reg-fx and called as regular re-frame events.

(if history/hashroutes?
(set! (.-onhashchange js/window)
#(dispatch [:district0x/set-active-page (d0x-ui-utils/match-current-location constants/routes)]))
(history/start! constants/routes))

But why?

The problem is that (history/start! constants/routes) fires [:active-page-changed] even before app is bootstrap, therefore before :district0x/smart-contracts-loaded. This causes error, because :active-page-changed assumes :district0x/smart-contracts-loaded.
Currently I used little hack to avoid error:

(when (all-contracts-loaded? db) ;; Pushstate URLs fire first event too early
(route->initial-effects (:active-page db) db))

So make it an re-frame event that's fired here at bootstrap
:dispatch-n [[:district0x/watch-my-eth-balances]

For (.-onhashchange js/window) we already have district0x.ui.window-fx file, you can put new reg-fx there.
For (history/start! constants/routes) you can create district0x.ui.history-fx. Don't put into district0x.ui.history because this file is required many times, so reg-fx is not overwritten every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants