當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Observable.fromEvent方法代碼示例

本文整理匯總了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())
     })
 })
開發者ID:gatinul,項目名稱:blog,代碼行數:8,代碼來源:blogList.ts

示例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);
}
開發者ID:LongLiveCHIEF,項目名稱:aim,代碼行數:14,代碼來源:stock_server.ts

示例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) {
開發者ID:skseth,項目名稱:tasks,代碼行數:31,代碼來源:app.ts


注:本文中的@reactivex/rxjs.Observable.fromEvent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。