我有一个每 2 秒执行一次 HTTP 请求并更新视图的应用程序。问题是,我必须做一些用户触发的 CSS 动画,这些动画大约需要一秒钟并且经常被破坏,因为 Angular 在动画运行时更新 DOM。
我使用Akita商店并像这样检索 observables:
this.dosingVessels$ = this.dosingVesselsQuery.selectAll().pipe(*needs rxjs operator magic*);
Run Code Online (Sandbox Code Playgroud)
然后像这样在组件中显示它们:
<app-solving-vessel *ngFor="let vessel of solvingVessels$ | async"
[vessel]="vessel"
[ngClass]="{'animation-class': hoverId === vessel.id}">
</app-solving-vessel>
Run Code Online (Sandbox Code Playgroud)
在动画进行时我怎么能做到这一点:
animate(event, vessel) {
this.updateView.next(false); // prevent from updating
this.hoverId = vessel.id; // triggers animation
timer(1000).subscribe(tick => this.updateView.next(true)); // allow normal updating
}
Run Code Online (Sandbox Code Playgroud)
视图没有更新。
我发现了 delayWhen 运算符,但所有示例都带有计时器,我不确定这是否是正确的方法。
由于缺乏文档(守卫,解析器,路由几乎没有记录),我在秋田状态管理和使用 Angular 解析器方面苦苦挣扎,到目前为止我一直在路由中使用它(不使用状态管理时)。
我正在查看以下Gist,其中作者确实在组件内订阅,我正在尝试将其移动到解析器。
我尝试了多种变体,包括在解析器中包含以下几行并进行订阅,但没有任何效果:
this.productsService.get().subscribe();
this.loading$ = this.productsQuery.selectLoading();
this.products$ = this.search.valueChanges.pipe(
startWith(''),
switchMap(value => this.productsQuery.selectAll({
filterBy: entity => entity.title.toLowerCase().includes(value)
}))
);
Run Code Online (Sandbox Code Playgroud) 我正在学习 Akita 以向 Angular 应用程序添加状态管理。在查看Akita 文档中的架构图和Akita GitHub 存储库中的示例(例如此示例)时,我看到 Query 是直接在组件中访问的。我很惊讶地看到这一点,因为我预计应用程序的状态管理部分将隐藏在服务后面,并从消费者(即组件)中抽象出来。与 Query 不同的是,Store 隐藏在 Service 后面,不能直接在组件中访问。在我看来,如果 Query 隐藏在 Service 后面,就像 Store 隐藏在 Service 后面一样,那么消费者只需要为每个数据源导入一件事,即服务。
所以我的问题是为什么 Akita 希望我们直接在组件中访问 Query 而不是 Store?将 Query 隐藏在服务背后是否有不利之处?
我想在我的 angular8 应用程序中使用状态管理,在此之前我研究了状态管理库似乎是 NGRX、NGXS 和 akita。
但是我不知道该选择哪一个!
NGRS 最常用。
NGXS 有更多的可能性并且易于学习。
AKITA 使用较少,下载较少,根据 npm 下载历史和 github forked 和 issue,但它基于面向对象,易于学习。
你的选择是什么?请说出你的理由!
我有一个CollectionService()
关于akita-ng-fire
模块中可用方法的查询。我创建了一个扩展 CollectionService() 的服务,并使用 syncCollection 来维护 Firestore 文档和我的 Web 客户端之间的同步。这是服务定义的样子:
@Injectable({providedIn: 'root'})
@CollectionConfig({path: 'someDoc/:customId/anotherDoc'})
export class MyService extends CollectionService<WorkspaceState> {
constructor(store: WorkspaceStore) {
super(store);
this.store.setHasCache(true, {restartTTL: true});
}
// service methods ......
}
Run Code Online (Sandbox Code Playgroud)
我onInit
在组件的指令中使用它来初始化同步。
ngOnInit() {
this.sub = this.myService.syncCollection().pipe(
concatMap(_ => this.query.myDoc$.pipe(
tap(d => this.myService.markActive(d.customId)),
tap(d => this.customId = d.customId),
)),
tap(d => this.router.navigate(['somePlace', d. customId])),
).subscribe();
}
Run Code Online (Sandbox Code Playgroud)
但是,我看到此同步每分钟读取约 5 次。有没有办法减少这种情况?我觉得这对我来说很昂贵,因为我们将此服务作为核心服务,用于保持与业务关键文档的同步。
来自社区的任何建议都会有所帮助