如何在 Chrome 或 Firefox 开发者工具控制台中使用 RxJS Observable?

How do I use RxJS Observable in Chrome or Firefox developer tools console?

我想快速测试一些与 Observable 相关的功能。在我的 Chrome 开发者工具中(或 Firefox 工具,无所谓)。

在我看来,几天前我能够简单地执行这样的代码:

var test$ = Rx.Observable.from([1,2,3]);

直接在我的 JavaScript 控制台中。我的回忆似乎更加正确,因为我实际上已经从我的开发工具控制台历史中挖掘出这个示例(以及许多其他示例)!


由于某种原因,它不再工作了;我收到此错误:

Uncaught ReferenceError: Rx is not defined

或者如果我只是使用 Observable 而不是 Rx.Observable

Uncaught ReferenceError: Observable is not defined


无法在 Chrome 控制台中使用 import 语句 'as is'。有人有使用浏览器的 Javascript 控制台调试 RxJS 代码的解决方案吗?

Rx Library是在站点加载的时候加载的,可以直接访问reactive.io。这将在那里工作

Rx.Observable.from([1,2,3]);

2020 年 12 月更新:

浏览器控制台中的 RxJS 回来了!

只需转到 https://rxjs.dev/ 并打开 devtools 控制台 :)

 ____           _ ____      
|  _ \ __  __  | / ___|    
| |_) |\ \/ /  | \___ \  
|  _ <  >  < |_| |___) |    
|_| \_\/_/\_\___/|____/ 

started experimenting with RxJS:

type this into the console:

rxjs.interval(500).pipe(rxjs.operators.take(4)).subscribe(console.log)

2018 年 11 月更新:

我刚刚注意到我之前的答案(以及已接受的答案)不再有效。 https://reactive.io site now redirects to https://rxjs-dev.firebaseapp.com/ 并显示:

 ____           _ ____      
|  _ \ __  __  | / ___|    
| |_) |\ \/ /  | \___ \  
|  _ <  >  < |_| |___) |    
|_| \_\/_/\_\___/|____/ 

Open http://stackblitz.com and try this code to get
started experimenting with RxJS:

import { interval } from "rxjs"

import { take } from "rxjs/operators"

const subscription = interval(500).pipe(take(4)).subscribe(console.log)

所以现在 Stackblitz 是“官方”方式。

原文post:

回到 ReactiveX documentation 后,我通过查看底部的内容得到了确认:

Hint: open your DevTools to experiment with RxJS.

我只是忘了只有打开开发工具才能使用此功能 from the reactivex.io/rxjs page itself :