-
Notifications
You must be signed in to change notification settings - Fork 467
connect: react-native support for 0x connect #342
Comments
This is also causing an issue for me! |
Hm, what replacement library would you recommend we use such that it works in browsers, node and react-native contexts? |
@fabioberger Actually it turns out that it may have been related to my simulator not being in debug mode. If the issue pops up again I'll do some more diligence. Really is one of the strangest bugs I've ever encountered in React Native. Thank you for the quick response, though! |
@kylanhurt is connect working for you in react native? |
@BMillman19 It's working. The isometric fetch issue is a nagging issue for many React Native projects (including outside of 0x-related stuff). I hope people find this issue so that they can see if my solution fixes it for them. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This is due to the different run time that React Native is using. |
@BMillman19 In 'use strict'
var __extends =
(this && this.__extends) ||
(function () {
var extendStatics = function (d, b) {
extendStatics =
Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && // <- this line will throw error
function (d, b) {
d.__proto__ = b
}) ||
function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]
}
return extendStatics(d, b)
}
return function (d, b) {
extendStatics(d, b)
function __ () {
this.constructor = d
}
d.prototype =
b === null ? Object.create(b) : ((__.prototype = b.prototype), new __())
}
})()
... In 'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const ansiStyles = require('ansi-styles');
const stdoutColor = require('supports-color').stdout;
const template = require('./templates.js');
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
// `supportsColor.level` → `ansiStyles.color[name]` mapping
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
// `color-convert` models to exclude from the Chalk API due to conflicts and such
const skipModels = new Set(['gray']);
// Object = global;
const styles = Object.create(null);
function applyOptions(obj, options) {
options = options || {};
// Detect level if not set manually
const scLevel = stdoutColor ? stdoutColor.level : 0;
obj.level = options.level === undefined ? scLevel : options.level;
obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
}
function Chalk(options) {
// We check for this.template here since calling `chalk.constructor()`
// by itself will have a `this` of a previously constructed chalk object
if (!this || !(this instanceof Chalk) || this.template) {
const chalk = {};
applyOptions(chalk, options);
chalk.template = function () {
const args = [].slice.call(arguments);
return chalkTag.apply(null, [chalk.template].concat(args));
};
Object.setPrototypeOf(chalk, Chalk.prototype); // this line throws error
Object.setPrototypeOf(chalk.template, chalk);
chalk.template.constructor = Chalk;
return chalk.template;
}
applyOptions(this, options);
}
... Work Around (Hack)The two error cases above seems to be the same problem. Here's the polyfill we use Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
obj.__proto__ = proto
return obj
} 'use strict'
var __extends =
(this && this.__extends) ||
(function () {
var extendStatics = function (d, b) {
// Apply polyfill here
Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
obj.__proto__ = proto
return obj
}
extendStatics =
Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array &&
function (d, b) {
d.__proto__ = b
}) ||
function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]
}
return extendStatics(d, b)
}
return function (d, b) {
extendStatics(d, b)
function __ () {
this.constructor = d
}
d.prototype =
b === null ? Object.create(b) : ((__.prototype = b.prototype), new __())
}
})()
... 'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const ansiStyles = require('ansi-styles');
const stdoutColor = require('supports-color').stdout;
const template = require('./templates.js');
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
// `supportsColor.level` → `ansiStyles.color[name]` mapping
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
// `color-convert` models to exclude from the Chalk API due to conflicts and such
const skipModels = new Set(['gray']);
// Object = global;
const styles = Object.create(null);
function applyOptions(obj, options) {
options = options || {};
// Detect level if not set manually
const scLevel = stdoutColor ? stdoutColor.level : 0;
obj.level = options.level === undefined ? scLevel : options.level;
obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
}
function Chalk(options) {
// We check for this.template here since calling `chalk.constructor()`
// by itself will have a `this` of a previously constructed chalk object
if (!this || !(this instanceof Chalk) || this.template) {
const chalk = {};
applyOptions(chalk, options);
chalk.template = function () {
const args = [].slice.call(arguments);
return chalkTag.apply(null, [chalk.template].concat(args));
};
// Apply polyfill here
Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) { error
obj.__proto__ = proto
return obj
}
Object.setPrototypeOf(chalk, Chalk.prototype);
Object.setPrototypeOf(chalk.template, chalk);
chalk.template.constructor = Chalk;
return chalk.template;
}
applyOptions(this, options);
}
... DiscussionThe hacking work around doesn't seems to be a good solution. |
It seems 0x connect is using the
isomorphic-fetch
library which has no support for react-native. More specifically, I'm getting the following error:This is coming from here: https://github.com/matthew-andrews/isomorphic-fetch/blob/master/fetch-npm-browserify.js#L6.
Work Around (Hack)
For now, I've been changing instances of
self
toglobal
.The text was updated successfully, but these errors were encountered: