admin-on-rest 如何为自动刷新实现自定义传奇

admin-on-rest how to implement a custom saga for auto-refresh

在aor-realtime提供的例子中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 函数,但无法从该范围访问它,它只是一个 symbolic/abstract 调用吗?

如果我真的想根据一些实时触发器刷新数据,我该如何从这个范围调度数据获取命令?

没错,是 symbolic/abstract 电话。实现 observeRequest 取决于您,例如使用您的 restClient 初始化它,并使用 fetchTyperesourceparams 参数相应地调用客户端方法。

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