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

时间:2017-05-10 14:37:01

标签: javascript reactjs redux redux-saga admin-on-rest

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

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

1 个答案:

答案 0 :(得分:2)

你是对的,这是一个象征/抽象的呼唤。您可以通过使用restClient初始化observeRequest并使用fetchTyperesourceparams参数相应地调用客户端方法来实现function foo({a = 'asdf', b = 3.5, c = true} = {}) { return a + ' ' + b + ' ' + c; } console.log(foo()); console.log(foo({a: 'qwerty', b: 123, c: false})); console.log(foo({b: 567})); console.log(foo({c: true, a: 'qwerty', b: 789}));

我们目前只在aor-simple-graphql-client客户端

中使用此传奇