Skip to content

Commit

Permalink
Fixed #16 inappropriately referencing this in a context where this is…
Browse files Browse the repository at this point in the history
… actually undefined.
  • Loading branch information
Erin Doyle committed May 26, 2017
1 parent 8e6d829 commit a7eb16f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"es2015",
"stage-0",
"react"
]
, "plugins": [
],
"plugins": [
"transform-runtime"
]
}
20 changes: 11 additions & 9 deletions src/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export default class A11y {
*/
constructor(...args) {
const {
React
, ReactDOM
, ...options
} = validate(...args);
React,
ReactDOM,
...options
} = validate(...args);

this.options = options;
this.React = React;
Expand All @@ -34,7 +34,7 @@ export default class A11y {
// save old createElement
this._createElement = this.React.createElement;

const that = this;
const _this = this;
this.React.createElement = function (klass, _props = {}, ...children) {
// fix for props = null
const props = _props || {};
Expand All @@ -56,16 +56,16 @@ export default class A11y {

const newProps = typeof klass === 'string' ? { ...props, ref } : props;

const reactEl = that._createElement(klass, newProps, ...children);
const reactEl = _this._createElement(klass, newProps, ...children);

// only test html elements
if (typeof klass === 'string') {
const handler = that.failureHandler(reactEl, refs);
const handler = _this.failureHandler(reactEl, refs);
const childrenForTest = children.length === 0
? props.children || []
: children;

that.suite.test(klass, props, childrenForTest, handler);
_this.suite.test(klass, props, childrenForTest, handler);
}

return reactEl;
Expand Down Expand Up @@ -122,14 +122,16 @@ export default class A11y {
// TODO: reduce the number of case where ther is no instance
// by forcing every component to have one.
if (browser && !this.__sync && owner && owner._instance) {
const _this = this;
const instance = owner._instance;

// Cannot log a node reference until the component is in the DOM,
// so defer the call until componentDidMount or componentDidUpdate.
after.render(instance, () => {
// unpack the ref
let DOMNode = false;
if (typeof ref === 'string') {
DOMNode = this.ReactDOM.findDOMNode(instance.refs[ref]); // TODO: replace use of findDOMNode
DOMNode = _this.ReactDOM.findDOMNode(instance.refs[ref]); // TODO: replace use of findDOMNode
} else if ('node' in ref) {
DOMNode = ref.node;
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/after.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const after = (host, name, cb) => {

// override host
host[name] = (...args) => {
// perform original
original.apply(this, args);
// perform cb
cb.apply(this, args);

This comment has been minimized.

Copy link
@erin-doyle

erin-doyle May 26, 2017

Collaborator

These two references to this were being transpiled to undefined because this is undefined in this particular context.

// perform original
original.apply(host, args);
// perform cb
cb(...args);
};

// save restoring function
Expand Down

0 comments on commit a7eb16f

Please sign in to comment.