本文整理汇总了TypeScript中@reactivex/rxjs.Observable.fromEvent方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.fromEvent方法的具体用法?TypeScript Observable.fromEvent怎么用?TypeScript Observable.fromEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@reactivex/rxjs.Observable
的用法示例。
在下文中一共展示了Observable.fromEvent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
.mergeMap(() => {
return Rx.Observable.fromEvent($('.more'), 'click')
.do((e)=>{
const target = $(e.currentTarget)
console.log(target.text(), path)
location.href=(path + 'more/' + target.text())
})
})
示例2: next
const createRxSocket = (connection) => {
let messages = Observable.fromEvent(connection, 'message', (message) => JSON.parse(message));
let messageObserver:any = {
next(message){
if(connection.readyState === 1){
connection.send(JSON.stringify(message));
}
}
}
connection.on('close', () => {
connection.streams && connection.streams.forEach(s => s.unsubscribe());
})
return Subject.create(messages, messageObserver);
}
示例3:
var refreshButton = document.querySelector('.refresh') as HTMLButtonElement;
var closeButton1 = document.querySelector('.close1') as HTMLButtonElement;
var closeButton2 = document.querySelector('.close2') as HTMLButtonElement;
var closeButton3 = document.querySelector('.close3') as HTMLButtonElement;
interface ClickEvent {
event: string
}
interface Person {
name: string,
html_url: string,
login: string
}
var refreshClickStream = Rx.Observable.fromEvent<ClickEvent>(refreshButton, 'click');
var close1ClickStream = Rx.Observable.fromEvent<ClickEvent>(closeButton1, 'click');
var close2ClickStream = Rx.Observable.fromEvent<ClickEvent>(closeButton2, 'click');
var close3ClickStream = Rx.Observable.fromEvent<ClickEvent>(closeButton3, 'click');
var startupRequestStream = Rx.Observable.from([url]);
var requestStream = refreshClickStream.startWith({event: 'first click'})
.map(function() {
var randomOffset = Math.floor(Math.random()*500);
return '/api?since=' + randomOffset;
});
var responseStream = requestStream
.flatMap(function(requestUrl) {