【发布时间】:2020-11-11 02:09:58
【问题描述】:
如何使用rxjs-spy 的let() 方法更改可观察多次次的值?
我正在关注该工具的this introduction,当我想到使用 let() 的示例时:
spy.let("people", source => source.mapTo("mallory"));
我被卡住了,因为source 是一个Observable<any>,它没有mapTo() 方法。因此,当粘贴到我的 chrome 控制台时,这条线应该正常工作,但由于 mapTo() 早已不复存在,它会引发异常。
我能想到的唯一方法不起作用。这允许我访问 rxjs 运算符
// In a top level typescript file (I add this file to debug builds only)
// This just lets me use rxjs operators, of, and tag, in the chrome console
import { tag } from 'rxjs-spy/operators/tag';
import { create } from 'rxjs-spy';
import * as operators from 'rxjs/operators';
import { of } from 'rxjs/observable/of';
window['debug'] = {
rxjs: { operators, of },
spy: { tag }
};
const spy = create();
然后我在某处有一个可观察的
myObservable.pipe(
tag("foo")
)
在 chrome 控制台中。 (注意:我也试过不使用管道和标签)
spy.let("foo", fooObservable => window.debug.rxjs
.of(1)
.pipe(
window.debug.spy.tag("foo")
)
);
这仅在我第一次尝试更新值时有效。反正我觉得这工作量太大了。
我不理解的最后一个问题是在使用spy.let(...) 之后我认为spy.undo(1)(用当时正确的任何值替换 1)可能能够帮助我测试多个值,但它会破坏快照,给我类似的东西:
spy.show()
0 snapshot(s) matching /.+/
我在使用该工具时也经常收到此警告
index.js:3551 Cyclic next detected; type = subject; value = [object Object]; subscribed at
Observable._subscribe (http://localhost:4200/vendor.js:291983:33)
Observable.subscribe (http://localhost:4200/vendor.js:291934:22)
http://localhost:4200/vendor.js:291217:44
notify_ (http://localhost:4200/vendor.js:291076:9)
【问题讨论】: