対象となるコードの例
JavaScript
1class ListManager { 2 constructor(url) { 3 this._url = normalize(url); 4 this._data = []; 5 } 6 getRequestObject() { // 差分のみを取得するためのリクエストオブジェクトを返す 7 return {url: `${this._url}?from=${this._data.length}`}; 8 } 9 update(response) { // getRequestObjectを使って帰ってきたデータを展開してデータに追加、データを返す 10 this._data.push(parse(response)); 11 return this.get(); 12 } 13 get() { // データを返す 14 return this._data; 15 } 16} 17 18let list; 19const listfetch = new ListManager("http://api.example.com/v2/list"); 20request(listfetch.getRequestObject(), (err, response) => { // requestはHTTPを扱うライブラリ 21 list = listfetch.update(response); 22});
上記のようなクラスをReduxで使用したいのですが、どのようにlistfetch
のようなクラスインスタンスを扱っていいのかわかりません。Storeの中にそのまま入れておいてもいいのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/12/03 09:54
2018/12/03 22:38
退会済みユーザー
2018/12/05 09:56