2017-12-30 54 views
1

単純なMobxストアをReact Nativeで操作して、なぜこれを動作させることができないのかを解明しようとしています。私は、データベース・リスナーをinatlizeする別の関数を呼び出したい機能他の関数内の関数をMobxで呼び出す

その非常に単純

class Store { 
@action FirstFunction(){ 
    this.SecondFunction(); 
    // I also tried: 
    SecondFunction(); 
    //neither worked 
} 

@action SecondFunction(){ 
    console.log("Second Function!"); 
} 

} 

任意のアイデアを持っていますか?これはmobxで可能ですか? は、なぜそうでないのかわからない場合があります。

答えて

0

thisを使用していますが、値がthisであることを確認してください。

例(JSBin

class Store { 
@action firstFunction() { 
    console.log("First Function!") 
    this.secondFunction(); 
} 

@action secondFunction(){ 
    console.log("Second Function!"); 
} 
} 

const store = new Store(); 

console.log("This works:"); 
store.firstFunction(); 

console.log("This will throw an error:"); 
setTimeout(store.firstFunction, 1000); 
関連する問題