ある内のサービスのようなものはありません反応する
ここでは選択肢です。
- $ rootscope - >状態にすると、コンポーネント間で共有することができます。 (あなたの哲学が真のデータソースの一つである状態管理のためにreduxを使うことができます)。
- $ q - > Es6 Promise
- $ websocket - > html5 websocket。
サービスに類似しているものは、必要なすべてのサービスをパラメータとして受け取り、エクスポートすることでどこからでも呼び出すことができるクラスまたは関数を記述できることです。
反応のために使用できる類似の実装です。 ES6約束:service.jsで
component.js
で
const myService = (...otherServices) => {
doStuff1();
doStuff2();
return {
...items
}
}
export default myService;
は、あなたはそれが
import myService from './service';
import React from 'react';
class testComponent extends React.Component {
constructor(props){
super(props);
this.data = myService().getData(); //just an example.
}
render(){
return (
<div>{this.data}</div>
);
}
}
Qライブラリをインポートすることができますか? OR反応-q? –
あなたはあなた自身の約束を作成する/ synchronusプログラミング –