当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.from方法代码示例

本文整理汇总了TypeScript中@reactivex/rxjs.Observable.from方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.from方法的具体用法?TypeScript Observable.from怎么用?TypeScript Observable.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@reactivex/rxjs.Observable的用法示例。


在下文中一共展示了Observable.from方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

            this.action$ = this.inStream$.flatMap(v => {
                if (v instanceof Rx.Observable) {
                    return v;

                } else {
                    return Rx.Observable.from([v]);
                }
            }).share();
开发者ID:tomachalek,项目名称:kontext,代码行数:8,代码来源:dispatcher.ts

示例2: Subject

import { Observable, Subject } from '@reactivex/rxjs';

const subject = new Subject();
const tick = Observable.from([1, 2, 3]);
const multicasted = tick.multicast(subject).refCount(); // 引用计数

multicasted.subscribe(v => console.log(`A: ${v}`));
multicasted.subscribe(v => console.log(`B: ${v}`), null, () => console.log('complete'));

// 显式调用
// multicasted.connect();
开发者ID:taochunyu,项目名称:learn,代码行数:11,代码来源:subject.ts

示例3:

import { Observable } from '@reactivex/rxjs'

/*
A ------> |
B ------> | -> E
C -> D -> |
*/

const A$ = Observable.interval(1000)
const B$ = Observable.of(3)
const C$ = Observable.from([5, 6, 7])
const D$ = C$.toArray().map(arr => arr.reduce((acc, val) => acc + val, 0))
const E$ = Observable.combineLatest(A$, B$, D$).map(arr => arr.reduce((acc, val) => acc + val, 0))

E$.subscribe(observer => {
    console.log(observer)
})
开发者ID:taochunyu,项目名称:learn,代码行数:17,代码来源:combe.ts

示例4: Promise

/**
 * @author happygrammer
 */
import * as Rx from "@reactivex/rxjs";

Rx.Observable.from([1, 2, 3]).subscribe(val => console.log(val));
Rx.Observable.from(new Promise(resolve => resolve("Hello!"))).subscribe(val => console.log(val));

const map = new Map();
map.set(1, 'a');
map.set(2, 'b');
Rx.Observable.from(map).subscribe(val => console.log(val));
开发者ID:chun4foryou,项目名称:develop,代码行数:12,代码来源:from.ts

示例5:

/**
 * @author happygrammer
 */
import * as Rx from "@reactivex/rxjs";

const streamData$ = Rx.Observable.from([1, 2, 3, 4, 5]);
const map = streamData$.map(val => val + 10);
const mapSubscribe = map.subscribe(val => console.log(val));
开发者ID:chun4foryou,项目名称:develop,代码行数:8,代码来源:map.ts

示例6:

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) {
    return Rx.Observable.fromPromise(fetch(requestUrl)
      .then(function(response) {
        return response.json();
      }));
  })
开发者ID:skseth,项目名称:tasks,代码行数:31,代码来源:app.ts


注:本文中的@reactivex/rxjs.Observable.from方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。