angular - 如何在操作文件中使用 entityActionFactory 来自定义 ngrx/data 中的操作?
问题描述
我看到我们可以在ngrx/data中自定义我们的操作,如下所示
https://ngrx.io/guide/data/entity-actions#tagging-the-entityaction
因此,我的问题是如何在正常的***.actions.ts文件中创建这些自定义操作(示例)
import { createAction, props } from '@ngrx/store';
export const normalFooAction = createAction(
‘[Foo] foo’,
props<{ foo: string }>()
);
¿¿¿
export const customizedNRGXDataAction = createAction(
———
this.entityActionFactory.create<Hero>(
'Hero',
EntityOp.QUERY_ALL,
null,
{ tag: 'Load Heroes On Start' }
);
———
???
通过我之前写的entityActionFactory然后在效果中使用它?(示例)
@Injectable()
export class FooEffects {
***
¿¿¿
loadCustomizedNRGXDataAction$ = createEffect(() => this.actions$.pipe(
ofType(FooActions.customizedNGRXDataAction),
???
***
))
)
);
那可能吗?
提前谢谢了
解决方案
您可以将其创建为商店中的对象,然后通过useValue
模块化服务将其提供到您的模块中。
export const myEntityActionFactory = new EntityActionFactory();
// to avoid duplicates you need to assign it to window.myEntityActionFactory and create a getter function.
// use it somewhere.
@NgModule({
imports: [
EntityDataModule.forRoot(...),
],
provides: [
{
provide: EntityActionFactory,
useValue: myEntityActionFactory,
},
],
})
推荐阅读
- c# - c# Lambda AWS SNS(Notifications) - 无法将消息发布到 AWS SNS
- git - 当文件是新文件时,Git 将文件标记为副本
- java - Spring boot jpa查询无法更新字段
- crystal-lang - Crystal 构建失败并出现错误 - 找不到 -levent
- html - 带有绝对定位的图像上的文本
- spring - Swagger - 定义多部分文件请求的最大大小限制
- node.js - Reactjs 没有建立到 Peerjs 服务器的连接
- python - 获取满足条件的列名
- java - 后退按钮工具栏中的触摸区工作不正常
- security - Apps 脚本库安全性