bhauman / lein-figwheel

Figwheel builds your ClojureScript code and hot loads it into the browser as you are coding!
Eclipse Public License 1.0
2.88k stars 208 forks source link

Add support for reloading in React Native environment #524

Closed rasom closed 7 years ago

rasom commented 7 years ago

Currently lein-figwheel >= 0.5.9 crashes with Reload not defined for this platform error message in React Native applications (re-natal). This commit fixes the problem.

bhauman commented 7 years ago

Well it's pretty obvious we are going to have to start moving to an idea of traits rather than going by an environment.

But for now I'd like to have a react-native-env? and a :react-native key returned by host-env?

And then look for the spots that are using (html-env?) as a behavior switch and include react native as needed.

Ideally if you find a spot that is testing for (html-env?) that needs to include react-native then it would be best to create a function that tests for the trait that is being looked for

(defn trait-console? [] (exists? js/console))

(defn trait-console-warn? [] (and (trait-console?) (exists? js/console.warn))

How does that sound?

bhauman commented 7 years ago

Those trait functions would go in the utils.cljs

rasom commented 7 years ago

Thanks, @bhauman, sounds reasonable.

I've just added updates in another commit, let's see if I understand you correctly.

bhauman commented 7 years ago

The only other thing I worry about, is if goog.global.navigator will exist in all environments?

rasom commented 7 years ago

The only other thing I worry about, is if goog.global.navigator will exist in all environments?

You are right, I'm not sure that it exists in all environments

tiensonqin commented 7 years ago

@rasom I got this same problem when using React Native with Exponent exponent-cljs-template, so thanks for your work.

I've tested goog.global.navigator on these 4 environments:

  1. html, exists
  2. worker, exists
  3. node, not exists
  4. react-native, exists and goog.global.navigator.product equals to react-native.

https://github.com/facebook/react-native/issues/1331

rasom commented 7 years ago

@tiensonqin, thanks for checking this. I suppose that (commit)

(and (exists? goog/global.navigator)
     (= goog/global.navigator.product "ReactNative")

will be safe in all environments.