当前位置: 首页>>代码示例>>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;未经允许,请勿转载。