andreypopp / andreypopp/react-async

this.<function from another mixin> is undefined in browser (isomorphic app)

オープン
#41 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
440
フォーク
24
PR マージ指標
30日以内にマージされた PR はありません

説明

I've been experiencing a weird issue when using react-async in conjunction with react-router-component in my isomorphic app.

Given the following mixin:

``` javascript
...
MyMixin = {
foo: function() {
console.log("hello!");
}
}
...
```

and the React class:

``` javascript
...
var MyView = React.createClass({
mixins: [Async.Mixin, MyMixin],

getInitialStateAsync: function(cb) {
this.foo(); // only works in the browser
...
}
...
});
```

When mounting, the browser will throw an error saying `this.foo()` is undefined. The workaround is to do something like (courtesy of @theadam):

``` javascript
...
var MyView = React.createClass({
mixins: [Async.Mixin, MyMixin],

getInitialStateAsync: function(cb) {
var component = this.type && this.type.prototype ? this.type.prototype : this;
component.foo(); // Works now
...
}
});
```

Obviously, the fix is less than ideal when using it in a larger app. Am I doing something wrong or is this an oversight?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。