如何解决如何使rxjs-spy的let运算符起作用?
如何使用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)
解决方法
弄清楚了-我只是缺少complete
选项。似乎是由于let()
默认将complete
设置为true
引起的。
因此,我仍然有一个在调试版本中使用的文件。这使我可以在chrome控制台中使用rxjs运算符,
// import { tag } from 'rxjs-spy/operators/tag'; You shouldn't need this in the console.
import { create } from 'rxjs-spy';
import * as operators from 'rxjs/operators';
import { of } from 'rxjs/observable/of';
window['debug'] = { rxjs: { operators,of } };
const spy = create();
然后在控制台中,将complete选项设置为false
。根据您所做的操作,此方法可能并不适用,但是我想继续手动更新值以查看更改结果。
// Add { complete: false } to the parameter list.
spy.let("foo",fooObservable => window.debug.rxjs.of(8),{ complete: false });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。