2

在 aor-realtime自述文件中提供的示例中

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提到了函数,但不能从该范围访问它,它只是一个符号/抽象调用吗?

如果我真的想根据一些实时触发器刷新数据,我怎么能从这个范围分派数据获取命令?

4

1 回答 1

2

你是对的,这是一个象征性/抽象的调用。由您来实现observeRequest,例如使用您的 restClient 初始化它并使用fetchType,resourceparams参数相应地调用客户端方法。

我们目前仅将此 saga 与aor-simple-graphql-client客户端一起使用

于 2017-05-11T09:45:53.920 回答