本文整理匯總了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) {