Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polyfill for React Native Android environment #73

Closed
serhiipalash opened this issue Jun 14, 2018 · 14 comments

Comments

@serhiipalash
Copy link

commented Jun 14, 2018

HI @sylvainpolletvillard !

I tried your library with React Native in Android simulator and got Can't find variable: Symbol for v3.4.6 and undefined is not a function (evaluating Object.setPrototypeOf(child, parent)) for v3.2.0.

Can you advice how to fix it right? Is it possible with some babel-plugin?

We really want to keep using your great library. In React Native iOS it works fine.

@serhiipalash

This comment has been minimized.

Copy link
Author

commented Jun 14, 2018

screen shot 2018-06-14 at 6 17 23 pm

@sylvainpolletvillard

This comment has been minimized.

Copy link
Owner

commented Jun 14, 2018

Hi @serhiipalash ,

ObjectModel v3 only targets ES2015-compliant environments, so it might break on older browsers or exotic environments. Symbol and Object.setPrototypeOf are both ES6 features, so it looks like the React Native environment on Android is not supporting ES6 (at least, not all of it). I found some possible solutions here:
https://medium.com/@jordan_mohi/cant-find-variable-symbol-in-react-native-782489d86bd7

If you need broader support, please consider using ObjectModel v2. v2 is supporting older browsers like IE11, so it should work on React Native for Android too. The v2 documentation is still available on the website: http://objectmodel.js.org/docs/v2/

@serhiipalash

This comment has been minimized.

Copy link
Author

commented Jun 14, 2018

Thanks @sylvainpolletvillard !

I'll try that fix and let you know if it works.

We can't use v2. If you remember there was a bug report from me to make your library work with Firebase, and it works great now. The fix was somewhere in 3.2.0 I think.

@serhiipalash

This comment has been minimized.

Copy link
Author

commented Jun 14, 2018

When I add this

import 'es6-symbol/implement'

and this

Object.setPrototypeOf = Object.setPrototypeOf ||
  function(obj, proto) {
    obj.__proto__ = proto
    return obj
  }

all works, but only if I comment delete model.name; here

initModel = (model, def) => {
	model.definition = def;
	model.assertions = [...model.assertions];
	define(model, "errors", []);
	// delete model.name;
},
@sylvainpolletvillard

This comment has been minimized.

Copy link
Owner

commented Jun 14, 2018

I can try to report this specific fix on v2 if this is all what is required.

If you manage to get it working with polyfills, good for you ! I cannot guarantee that everything will work perfectly though, these polyfills are not 100% spec compliant and have some limitations

@serhiipalash

This comment has been minimized.

Copy link
Author

commented Jun 19, 2018

@rclai already did )

@serhiipalash

This comment has been minimized.

Copy link
Author

commented Jun 19, 2018

Btw, @sylvainpolletvillard can you tell after what Node.js version I can safely use objectmodel in it?

@sylvainpolletvillard

This comment has been minimized.

Copy link
Owner

commented Jun 19, 2018

Yeah I upgraded the docs about browser/node support.

v2: Node >= 4
v3: Node >= 6

So ObjectModel v3 can be used with the latest LTS 👍
Unit tested here : https://travis-ci.org/sylvainpolletvillard/ObjectModel

@sylvainpolletvillard

This comment has been minimized.

Copy link
Owner

commented Jun 19, 2018

@serhiipalash I checked the fix I did on v3.2, from your previous issue with Firebase here : #57 (comment)

The bug was related to the ownKeys trap behaviour, but this is a Proxy-related feature, and Proxies are only used since v3. So there is no fix to report 😕

@serhiipalash

This comment has been minimized.

Copy link
Author

commented Jun 19, 2018

I checked the fix I did on v3.2, from your previous issue with Firebase

@sylvainpolletvillard thanks for checking!

We will have Android app release in a month and I think we have to remove objectmodel from the code :(

We will do this for the stability of both our mobile applications and code consistency. But we still going to use it in our Google Cloud Functions.

@sylvainpolletvillard

This comment has been minimized.

Copy link
Owner

commented Jun 19, 2018

No problem, this lib has been made to avoid problems, not to create new ones. Use it where you can and where it truely provides value

@serhiipalash

This comment has been minimized.

Copy link
Author

commented Jun 19, 2018

Lets keep this open if you don't mind. As I understand proxies for Android JsCore are in progress.

@serhiipalash

This comment has been minimized.

Copy link
Author

commented Nov 7, 2018

Expo 31 has updated JSCore for Android and proxies are there!
https://expo.canny.io/feature-requests/p/javascript-proxy-support-for-android-upgrade-jscore

Finally I can use the same model library on Web, iOS, Android and Node.js! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.