有人可以告诉我这段代码有什么问题吗?
const field = document.querySelector('.form-field');
const showHistoryButton = document.querySelector('#show-history');
const historyPanel = document.querySelector('#history');
const showHistory$ = Rx.Observable.fromEvent(showHistoryButton, 'click');
Rx.Observable.fromEvent(field, 'keyup')
.debounceTime(200)
.pluck('target', 'value')
.filter(R.compose(R.not, R.isEmpty))
.bufferWhen(() => showHistory$)
.do(history => history.pop())
.subscribe(history => {
let contents = '';
if(history.length > 0) {
for(let item of history) {
contents += '<li>' + item + '</li>';
}
historyPanel.innerHTML = contents;
}
});
我得到的错误是:
rxjs.5.5.2.js:3895 Uncaught TypeError: Invalid event target
at Function.FromEventObservable.setupSubscription (rxjs.5.5.2.js:3895)
at FromEventObservable._subscribe (rxjs.5.5.2.js:3917)
at FromEventObservable.Observable._trySubscribe (rxjs.5.5.2.js:825)
at FromEventObservable.Observable.subscribe (rxjs.5.5.2.js:813)
at subscribeToResult (rxjs.5.5.2.js:2065)
at BufferWhenSubscriber.openBuffer (rxjs.5.5.2.js:7489)
at new BufferWhenSubscriber (rxjs.5.5.2.js:7442)
at BufferWhenOperator.call (rxjs.5.5.2.js:7427)
at Observable.subscribe (rxjs.5.5.2.js:810)
at DoOperator.call (rxjs.5.5.2.js:9862)
当我取消注释代码片段时,即使它是空的,看起来罪魁祸首也是subscribe
方法。我使用的是RxJS 5.5.2,唯一的依赖是Ramda。