当我在承诺模式下尝试使用Chrome控制台时,thirdPartyApiWithCallbackSubscription
不断返回新数据。现在我想将它移动到Observable并继续全局订阅。但是在Observable模式下,它只返回一次数据。我应该如何重构代码,以便在有新数据通过时继续接收数据?
Observable.create(observer => {
thirdPartyApiWithCallbackSubscription(data => {
observer.next(data);
});
})
.pipe(
map(data => {
return { type: 'DATA_CHANGED', payload: data };
})
);
刚刚验证thirdPartyApiWithCallbackSubscription
有问题,上面的方法符合我的预期。谢谢。