如何解决@ngrx/data 如何取消使用 getAll、getWithQuery、getByKey 提供的请求
我在我的应用中使用 ngrx/data。
我有一个非常快的申请。 你可以在 UI 上选择一些东西,我需要更新我的视图。用户可以非常快速地完成此操作,在这种情况下,我不需要来自先前请求的任何先前数据。
但是当我添加 switchMap 时 - 我的请求不会取消。
interface User {
id: number;
name: string;
}
@Component({
selector: 'nrwl-test-root',templateUrl: './app.component.html',styleUrls: ['./app.component.scss'],})
export class AppComponent implements OnInit {
test$ = new Subject();
userEntity: EntityCollectionService<User>;
constructor(private http: HttpClient,entityDeFinition: EntityDeFinitionService,entityServices: EntityServices) {
entityDeFinition.registerMetadataMap({
User: {},});
this.userEntity = entityServices.getEntityCollectionService<User>('User');
}
ngOnInit() {
this.test$.pipe(
switchMap(() => {
// return this.http.get('api/user') // switchMap works here
return this.userEntity.getAll() // switchMap doesn't work here
})
).subscribe();
}
onClick() {
this.test$.next(Math.random());
}
}
我有“@ngrx/data”:^0.10.2
但我在最新版本 11.0.1 上检查它 - 我有相同的行为。
我找到了一种解决方法,只需将 httpClient 用于它,并在成功请求后更新我的 entityCache。但我不喜欢这种方法。
据我所知,实体服务总是返回 AnonymousSubject 而不是 Observable。 这也是我无法取消请求的原因。但也许我可以以正确的方式做到这一点?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。