Skip to content

Commit

Permalink
Fixing "_ApiClient is not defined" by adding empty class method to Ap…
Browse files Browse the repository at this point in the history
…iClient

Fixes issue #14 #31 #51

Relevant Babel bug https://phabricator.babeljs.io/T2455 with more info.
They claim it's v8. It may be fixed in future versions of node. More
investigation is needed.
  • Loading branch information
AndrewRayCode committed Apr 20, 2016
1 parent d4d38aa commit be090cf
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/helpers/ApiClient.js
Expand Up @@ -13,13 +13,7 @@ function formatUrl(path) {
return '/api' + adjustedPath;
}

/*
* This silly underscore is here to avoid a mysterious "ReferenceError: ApiClient is not defined" error.
* See Issue #14. https://github.com/erikras/react-redux-universal-hot-example/issues/14
*
* Remove it at your own risk.
*/
class _ApiClient {
export default class ApiClient {
constructor(req) {
methods.forEach((method) =>
this[method] = (path, { params, data } = {}) => new Promise((resolve, reject) => {
Expand All @@ -40,8 +34,15 @@ class _ApiClient {
request.end((err, { body } = {}) => err ? reject(body || err) : resolve(body));
}));
}
/*
* There's a V8 bug where, when using Babel, exporting classes with only
* constructors sometimes fails. Until it's patched, this is a solution to
* "ApiClient is not defined" from issue #14.
* https://github.com/erikras/react-redux-universal-hot-example/issues/14
*
* Relevant Babel bug (but they claim it's V8): https://phabricator.babeljs.io/T2455
*
* Remove it at your own risk.
*/
empty() {}
}

const ApiClient = _ApiClient;

export default ApiClient;

0 comments on commit be090cf

Please sign in to comment.