Fork me on GitHub
#re-frame
<
2015-12-31
>
snowell15:12:50

So I’m noticing that as of recently re-frame has started complaining when I do Chrome’s “Empty cache and hard reload” option. I generally make a habit of doing this while testing webapps, but now when I do it, re-frame tells me that my event handlers don’t exist. I can ‘fix’ it by doing a normal refresh, but this seems weird. Anybody experience this?

snowell15:12:25

Guess I should add: It also does this when I do a “Hard reload"

darwin15:12:38

I guess this is some timing issue in your code. Maybe you are registering your handlers in some async callback or delayed. And the fact that cache is cold causes this callback to fire later than usual. I would recommend to pause re-frame event processing until you register all your handlers

snowell15:12:53

As far as I know, I’m registering them the normal way: require-ing the ns in core.cljs

snowell15:12:20

And my handlers.cljs is simply one def (standard-middleware) and a series of register-handler

darwin15:12:53

aren’t you calling dispactch in some other place, before handles.cljs code gets actually evaluated?

snowell15:12:45

I didn’t think so, but that’s how it appears

darwin15:12:46

I think good approach is to avoid any sideeffect in namespaces, you should implement some init! function where you setup your re-frame and then call first dispatch, this init function should be called from your core ns as a side-effect, that is the only place where you call a fn when loading ns

snowell15:12:27

Hmm, I think I can do that

darwin15:12:38

have to go, will be back in 30mins

snowell15:12:48

No worries. Thanks for the help!

darwin15:12:47

keep in mind that goog.base is requiring namespaces asynchronously, this might play a role, you are not in control when those side-effects will run

darwin15:12:04

not sure I may be wrong here

snowell15:12:02

It sounds legit simple_smile

snowell15:12:21

Yup, that works like a champ

simax9916:12:45

I’m using re-frame with pushy (which uses HTML5 push state and lets me have URI’s w/out the #). If I type in a URI into the browser address bar of course that gets sent to the server where my app is served from. The server then decides it doesn’t know about the URI, which is true because its a client side URI. How do I deal with that. I presume I would need to send the requested URI back in the response map and somehow then let the client deal with re-creating app-db and routing the client back to the right place. This seems like a common scenario. Is there a pattern for this? Any examples? Am I even right in my assumptions?

darwin16:12:49

this is unrelated to re-frame, this is more of a general question related to javascript SPA design

darwin16:12:00

personally I would use urls with # and call it a day

darwin16:12:40

I’m not familiar with HTML5 push state in detail, but I guess there could be some way how to prevent browser from requesting a new page on url change

darwin16:12:18

also I think that you can just setup your server to always serve base app on all urls with given prefix, you don’t have to pass requested URI back, client can see it in javascript

simax9916:12:21

Thanks for answering, and apologies for asking in the wrong channel. I agree this is not specifically a re-frame question. I know I can use URI’s with # in them, I just wanted to try w/out. I know its possible because @pupeno talks about it here https://carouselapps.com/2015/12/05/tour-of-the-source-code-of-ninja-tools-part-2/. And yes thinking about it there’s no need to send back the requested URI. I’ll keep plugging away, thanks again.

darwin16:12:37

@simax99: I would think pushy should give you some docs/examples how to deal with HTML5 push state w/out #

simax9917:12:54

@darwin I found the project that @pupeno describes in his screencast on Github so I have a good example now. Thanks again.