re-frame
re-frame copied to clipboard
v1.0.0-rc2 throws error on React Native Expo
Error message
addEventListener and attachEvent are unavailable
Other info
I was working on updating deps and adding deps.edn support for projects created with this create kit.
v1.0.0-rc2
throws the error above when the app first starts. v0.12.0
works fine.
Thanks for the report @jgoodhcg, you've indeed found a bug 🐛 👍
This error is occurring here in the google closure library due to my unconditional use of the goog events api here.
The fix will be to first check that the environment (e.g. react native expo) supports the event APIs prior to calling it. We'll get this done in 1.0.0-rc3
.
This might be fixed by #615 so I have released 1.0.0-rc3
and left this issue open for feedback @jgoodhcg
It looks like there is still a problem using 1.0.0.-rc3
.

The problem stills on 1.0.0-rc5. Version 0.12.0 works fine.
In 1.0.0-rc6
we have added a try
/catch
that ignores the exception on environments that do not support addEventListener
via the goog.events/listen
API (e.g. React Native).
This fixes the issue but does mean that in React Native :loaded?
in settings will never be set to true, so you'll continue to get superfluous duplicate event handler warnings when hot reloading code (e.g. via shadow-cljs, figwheel etc).
If you have any suggestions on the following please let us know @neural-works @jgoodhcg
- What is a good way for re-frame to detect that it is in the React Native environment ?
- Is there an alternative in React Native to
goog.events/listen
onjs/self
(i.e. the global object, usuallyjs/window
) to listen for the"load"
event ? Or in other words, to execute a fn when all scripts have loaded ?
Reopened awaiting response to above. Any feedback on above two questions @neural-works @jgoodhcg on how to detect being in React Native ?
I have not had the to develop a library that runs on all the platforms , but a quick google search found this option for detecting environment.
I've not seen anything for executing a function when scripts load. There should be some example in expo.
Updated to 1.1.1
today and it seems to be working :smile:. Thanks!