0

ここで見られるようにフェッチを使用しています(redux-observableでajaxの代わりにフェッチを使用します)ノードを使用してサーバー側でフェッチを行います。残念ながら、AjaxObservable はブラウザーでしか機能しないため、サーバーでのフェッチには isomorphic-fetch を使用しています。

私のコードは次のようになります。

            let fetch$ = null;
            if (canUseDOM) {
                fetch$ = AjaxObservable.create({
                    url,
                    method: 'GET',
                    responseType: 'json',
                    ...options
                }).takeUntil(action$.ofType(`${type}_CANCEL`));
            } else {
                fetch$ = Observable.from(fetch(url, options).then(response => {
                    return response.json()
                }).then(response => ({response})));
            }

            return fetch$
                .map(({response: payload}) => ({type, payload}))

ただし、これをサーバー (つまりcanUseDOM == false) で実行すると、次のエラーが発生します。

RangeError: Maximum call stack size exceeded
at SafeSubscriber.Subscription.unsubscribe (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscription.js:79:19)
at SafeSubscriber.Subscriber.unsubscribe (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:122:38)
at SafeSubscriber.__tryOrUnsub (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:226:18)
at SafeSubscriber.next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:172:22)
at Subscriber._next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:125:26)
at Subscriber.next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:89:18)
at SwitchMapSubscriber.notifyNext (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/operator/switchMap.js:77:30)
at InnerSubscriber._next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/InnerSubscriber.js:23:21)
at InnerSubscriber.Subscriber.next (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/Subscriber.js:89:18)
at MergeMapSubscriber.notifyNext (/Users/bmonro/Documents/Code/nui-redux/ext/@concur/nui-middleware/node_modules/rxjs/operator/mergeMap.js:85:30)
4

0 に答える 0