ohanhi / elm-native-ui

[CLOSED] Experiment: mobile apps in Elm using React Native.
BSD 3-Clause "New" or "Revised" License
1.54k stars 76 forks source link

elm-native-ui/core: Symbol throws an error and App doesn't work #33

Closed sudhirvkumar closed 8 years ago

sudhirvkumar commented 8 years ago

@mk @ohanhi @eeue56

in src/Native/Runtime.js the following lines throw error in Redbox and nothing works.

// React elements have a$$typeofmarker whose value is an // ES6 Symbol. IfSymboldoes not exist, we bail out early. if (typeof(window.Symbol) === 'undefined') { throw new Error( 'You seem to be running on an unsupported platform.\n' + 'Elm.embedReact is currently only supported for React Native.\n' + 'Please use Elm.embed or Elm.fullscreen instead.' ); }

As I checked the react source. Symbol or a polyfill may or may not be available always and they use a plan number 0xeac7 as fallback to represent ReactElement Type. This happens at runtime so the value for REACT_ELEMENT_TYPE is not fixed across all compiled files. We need to figure this out in runtime not development time. It has to be dynamic not static.

The following is the code from https://github.com/facebook/react/blob/0.14-stable/src/isomorphic/classic/element/ReactElement.js

var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) || 0xeac7;

sudhirvkumar commented 8 years ago

I had to comment out the whole if block to make the code work.

Also... I had to change the

function isReactElement(maybeElement) { return maybeElement['$$typeof'] === Symbol.for('react.element'); }

to simply return true... which is a hack.

I guess we have to use var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) || 0xeac7; to determine if an element is React Element.

Please let me know your thoughts

sudhirvkumar commented 8 years ago

@ohanhi @mk @eeue56 any ideas?

sudhirvkumar commented 8 years ago

Copied this issue to https://github.com/elm-native-ui/core/issues/3