在实时实时readme中提供的示例中

import realtimeSaga from 'aor-realtime';

const observeRequest = (fetchType, resource, params) => {
    // Use your apollo client methods here or sockets or whatever else including the following very naive polling mechanism
    return {
        subscribe(observer) {
            const intervalId = setInterval(() => {
                fetchData(fetchType, resource, params)
                    .then(results => observer.next(results)) // New data received, notify the observer
                    .catch(error => observer.error(error)); // Ouch, an error occured, notify the observer
            }, 5000);

            const subscription = {
                unsubscribe() {
                    // Clean up after ourselves
                    clearInterval(intervalId);
                    // Notify the saga that we cleaned up everything
                    observer.complete();
                }
            };

            return subscription;
        },
    };
};

const customSaga = realtimeSaga(observeRequest);


提到了fetchData函数,但是不能从该范围访问它,这仅仅是符号/抽象调用吗?

如果我真的想基于某个实时触发器刷新数据,该如何从该范围调度数据提取命令?

最佳答案

没错,这是象征性/抽象性的电话。您可以实现observeRequest的方法,例如,使用restClient初始化fetchType并使用resourceparams和参数相应地调用客户端方法。

我们目前仅在aor-simple-graphql-client客户端上使用此传奇

09-25 16:22