【问题标题】:How do I use RxJS Observable in Chrome or Firefox developer tools console?如何在 Chrome 或 Firefox 开发者工具控制台中使用 RxJS Observable?
【发布时间】:2018-08-15 20:04:46
【问题描述】:

我想快速测试一些 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 语句。有人有使用浏览器的 Javascript 控制台调试 RxJS 代码的解决方案吗?

【问题讨论】:

  • 我刚刚创建了一个名为rxjs.rxplayground.com 的网站。它支持大多数主要的 Rxjs 版本,具有自动完成功能,您可以使用停止按钮停止失控的订阅。

标签: javascript rxjs google-chrome-devtools firefox-developer-tools


【解决方案1】:

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 站点现在重定向到 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 是“官方”方式。

原帖:

回到ReactiveX documentation后,我在底部看到了这个确认:

提示:打开您的 DevTools 来试验 RxJS。

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

【讨论】:

  • 嗯,是的 - 那里有很多很多 JavaScript 库和包,但您的浏览器没有附带它们
  • @AndrewKoper 当然,但在这种情况下,这个网站已经加载了这个事实非常方便
【解决方案2】:

网站加载时会加载Rx库,可以直接访问reactive.io。这将在那里工作

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

【讨论】:

  • 还有效吗? > Rx.Observable.from([1,2,3]); > VM238:1 Uncaught ReferenceError: Rx is not defined at :1:1
  • 他们的网站似乎有问题。它抛出 503。我正在尝试的网址是 rxjs-dev.firebaseapp.com
猜你喜欢
  • 2018-06-02
  • 2016-10-03
  • 2017-06-10
  • 2016-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多