2016-05-29 5 views
0

React.jsの約束事を処理する最良の方法は何ですか?以下のコードは動作します - もっと反応的な方法がありますか?React.js、約束を処理するための構文?

handleFormSubmit(input){ 

    this.setState({ 
     originId: input.originId, 
     destinationId: input.destinationId, 
     radius: input.radius, 
     search: input.search 
    }); 

    var routeSearch = new FindRoutes({ 
     originPlaceId: input.originId, 
     destinationPlaceId: input.destinationId, 
     directionsDisplay: directionsDisplay, 
     directionsService: directionsService, 
     travel_mode: google.maps.TravelMode.DRIVING, 
     search: input.search 
    }); 

    routeSearch.execute() 
    .then(function(){ 
     alert("promise fullfilled!"); 
    }); 

} 
+0

フラックスと呼ばれる手法を使って、あなたの行動からレンダリングロジック(この場合はすなわち約束を)出し分けます。 Reactは、それをどのアーキテクチャーにも結合する必要のないDOM diffingを持つビューエンジンです。 –

答えて

1

これは、実行しようとする内容によって異なります。あなたの行動を構造化し、すべてを整理しておく良い方法を探しているなら。私は最近、私のプロジェクト

http://redux.js.org/

とその華麗にReduxの追加間違いなくそれをチェックアウトをお勧めします。彼らは、コードが細かい

https://facebook.github.io/flux/

+0

チップのおかげで! – matthewalexander

関連する問題