this.titleQuery 的赋值逻辑:
class UserProfileService {
constructor(userAccountService, authService, userProfileConnector, eventService, userIdService, query, command) {
this.userAccountService = userAccountService;
this.authService = authService;
this.userProfileConnector = userProfileConnector;
this.eventService = eventService;
this.userIdService = userIdService;
this.query = query;
this.command = command;
this.updateCommand = this.command.create((payload) => this.userIdService.takeUserId(true).pipe(switchMap((uid) => this.userProfileConnector.update(uid, payload.details).pipe(tap(() => {
this.eventService.dispatch({ user: payload.details }, UserAccountChangedEvent);
})))), {
strategy: CommandStrategy.Queue,
});
this.closeCommand = this.command.create(() => this.userIdService
.takeUserId(true)
.pipe(switchMap((uid) => this.userProfileConnector
.remove(uid)
.pipe(tap(() => this.authService.logout())))));
this.titleQuery = this.query.create(() => this.userProfileConnector.getTitles(), {
reloadOn: [LanguageSetEvent],
});
}
get() {
return this.userAccountService.get();
}
类型是 Query,数据类型是 Title[]:
万变不离其宗,还是通过 connector 去取数据:
创建 query 实例时,要传入一个箭头函数作为 Loaderfactory:
在执行 query create 方法时,通过 switchMapTo,触发这个 loaderFactory 的执行:
最后通过传统的 HTTP client 去读取数据:
更多Jerry的原创文章,尽在:"汪子熙":
网友评论