visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.68k stars 688 forks source link

Few conditions to improve Node.js support #438

Closed PaulMaly closed 6 years ago

matthewp commented 6 years ago

Hey @PaulMaly, looks like there are conflicts. Also can you consolidate this type of thing into a function? Create a isWindow function that checks for window, document, and location.

PaulMaly commented 6 years ago

Hi, @matthewp. Yep, this the first that comes to mind when we think about the support of different environments. But, I think it's bad approach because we need to clearly know which global object belongs to what environment. And not only object itself (document, window, etc.), but also combination of objects (hm, window + history + document + location == browser ??? )

I believe that good approach is if you're using some global defined stuff just check it before you go. Just check all global objects you use. That's why I do it in-place. This code works for me in my isomorphic projects well, in nodejs too. If you think it should be rewritten, perhaps I could create an issue for that?

matthewp commented 6 years ago

@PaulMaly I think you make a fair point, just means the code is a little less pretty :D . No worries, I think this is acceptable.