• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript rx-lite.Observable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中rx-lite.Observable的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable类的具体用法?TypeScript Observable怎么用?TypeScript Observable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_scan

function test_scan() {
	/* Without a seed */
	const source1: Rx.Observable<number> = Rx.Observable.range(1, 3)
		.scan((acc, x, i, source) => acc + x);

	/* With a seed */
	const source2: Rx.Observable<string> = Rx.Observable.range(1, 3)
		.scan((acc, x, i, source) => acc + x, '...');
}
开发者ID:cronon,项目名称:DefinitelyTyped,代码行数:9,代码来源:rx-lite-tests.ts


示例2: getDataObservable

  private getDataObservable() {
    let click = Rx.Observable.fromEvent($("#openFile"), "click");

    // fromCallback() converts a function that takes a callback into a new
    // function that takes all of the original function's arguments except the
    // callback and returns an Observable of the callback's return value.
    let opener = Rx.Observable.fromCallback(dialog.showOpenDialog);
    let reader = Rx.Observable.fromCallback(fs.readFile);
    let isValid: boolean;

    // Pipeline of observables to convert a stream of clicks into a stream of
    // validated file data
    return click
      .flatMap(() => opener({ properties: ["openFile"] }) // returns the selected filename (as one-item array)
        .filter(f => f) // Don't emit event if user didn't select a file
        .flatMap(f => reader(f[0], "utf-8")) // map file name stream to file data stream
        .map(d => d[1]) // Hack: Observable-wrapped readFile returns [null, fileData] (?)
        .do(d => {
          isValid = Parser.validateData(d); // put validity info in outer scope...
          if (!isValid) alert("Invalid data");
        })
        .filter(() => isValid)); // ...so .filter() doesn't have to call validateData() again
  }
开发者ID:Ethan826,项目名称:tablexi-coding-challenge,代码行数:23,代码来源:browser.ts


示例3: test_mergeAll

function test_mergeAll() {
	/* mergeAll example */
	const source = Rx.Observable.range(0, 3)
		.map(x => Rx.Observable.range(x, 3))
		.mergeAll();

	const subscription = source.subscribe(
		x => {
			console.log('Next: %s', x);
		},
		err => {
			console.log('Error: %s', err);
		},
		() => {
			console.log('Completed');
		});
}
开发者ID:cronon,项目名称:DefinitelyTyped,代码行数:17,代码来源:rx-lite-tests.ts


示例4: test_concatAll

function test_concatAll() {
	/* concatAll Example */
	var source = Rx.Observable.range(0, 3)
		.map(function (x) { return Rx.Observable.range(x, 3); })
		.concatAll();

	var subscription = source.subscribe(
		function (x) {
			console.log('Next: %s', x);
		},
		function (err) {
			console.log('Error: %s', err);
		},
		function () {
			console.log('Completed');
		});
}
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:17,代码来源:rx-lite-tests.ts


示例5: test_concatAll

function test_concatAll() {
	/* concatAll Example */
	var source = Rx.Observable.range(0, 3)
		.map(x => Rx.Observable.range(x, 3))
		.concatAll();

	var subscription = source.subscribe(
		x => {
			console.log('Next: %s', x);
		},
		err => {
			console.log('Error: %s', err);
		},
		() => {
			console.log('Completed');
		});
}
开发者ID:Kroisse,项目名称:DefinitelyTyped,代码行数:17,代码来源:rx-lite-tests.ts


示例6: test_publish

// from https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/publish.md
function test_publish() {
	const interval = Rx.Observable.interval(1000);

	const source = interval
		.take(2)
		.doAction(x => {
			console.log('Side effect');
		});

	const published = source.publish();

	published.subscribe(createObserver('SourceA'));
	published.subscribe(createObserver('SourceB'));

	const connection = published.connect();

	function createObserver(tag: string) {
		return Rx.Observer.create(
			x => {
				console.log('Next: ' + tag + x);
			},
			err => {
				console.log('Error: ' + err);
			},
			() => {
				console.log('Completed');
			});
	}

	// => Side effect
	// => Next: SourceA0
	// => Next: SourceB0
	// => Side effect
	// => Next: SourceA1
	// => Next: SourceB1
	// => Completed
	// => Completed
}
开发者ID:cronon,项目名称:DefinitelyTyped,代码行数:39,代码来源:rx-lite-tests.ts


示例7:

		.map(x => Rx.Observable.range(x, 3))
开发者ID:cronon,项目名称:DefinitelyTyped,代码行数:1,代码来源:rx-lite-tests.ts


示例8: fromCallback

	function fromCallback() {
		// 0 arguments
		const func0: (cb: (result: number) => void) => void = () => { };
		obsNum = Rx.Observable.fromCallback(func0)();
		obsNum = Rx.Observable.fromCallback(func0, obsStr)();
		obsNum = Rx.Observable.fromCallback(func0, obsStr, (results: number[]) => results[0])();

		// 1 argument
		const func1: (a: string, cb: (result: number) => void) => number = () => 0;
		obsNum = Rx.Observable.fromCallback(func1)("");
		obsNum = Rx.Observable.fromCallback(func1, {})("");
		obsNum = Rx.Observable.fromCallback(func1, {}, (results: number[]) => results[0])("");

		// 2 arguments
		const func2: (a: number, b: string, cb: (result: string) => number) => Date = () => new Date();
		obsStr = Rx.Observable.fromCallback(func2)(1, "");
		obsStr = Rx.Observable.fromCallback(func2, {})(1, "");
		obsStr = Rx.Observable.fromCallback(func2, {}, (results: string[]) => results[0])(1, "");

		// 3 arguments
		const func3: (a: number, b: string, c: boolean, cb: (result: string) => number) => Date = () => new Date();
		obsStr = Rx.Observable.fromCallback(func3)(1, "", true);
		obsStr = Rx.Observable.fromCallback(func3, {})(1, "", true);
		obsStr = Rx.Observable.fromCallback(func3, {}, (results: string[]) => results[0])(1, "", true);

		// multiple results
		const func0m: (cb: (result1: number, result2: number, result3: number) => void) => void = () => { };
		obsNum = Rx.Observable.fromCallback(func0m, obsStr, (results: number[]) => results[0])();
		const func1m: (a: string, cb: (result1: number, result2: number, result3: number) => void) => void = () => { };
		obsNum = Rx.Observable.fromCallback(func1m, obsStr, (results: number[]) => results[0])("");
		const func2m: (a: string, b: number, cb: (result1: string, result2: string, result3: string) => void) => void = () => { };
		obsStr = Rx.Observable.fromCallback(func2m, obsStr, (results: string[]) => results[0])("", 10);
	}
开发者ID:cronon,项目名称:DefinitelyTyped,代码行数:33,代码来源:rx-lite-tests.ts


示例9:

		.map(function (x) { return Rx.Observable.range(x, 3); })
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:1,代码来源:rx-lite-tests.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript rx-lite.Observer类代码示例发布时间:2022-05-25
下一篇:
TypeScript rx-jupyter.sessions类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap