- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像这样的 Rxjs 轮询效果:
updateProductData$ = createEffect(() =>
this.actions$.pipe(
ofType(fromActions.loadProduct),
switchMap(_) =>
this.http.get('endpoint').pipe(
delay(1000),
repeat(),
switchMap((data) => [
fromActions.updateFoo({foo: data.foo}),
fromActions.updateBar({bar: data.bar}),
])
)
)
);
我如何发货
updateFoo
和
updateBar
仅当
data.foo
或
data.bar
分别改变?
distinctUntilChanged
来改进这一点,如果
data.stuff
,则操作不会触发然而,当任何一个 Action 发生变化时,这两个 Action 仍然会调度。
...
repeat(),
distinctUntileChanged((prev, curr) => prev.foo === curr.foo && prev.bar === curr.bar) // works but it fires both actions when either one changes
switchMap((data) => [
fromActions.updateFoo({foo: data.foo}),
fromActions.updateBar({bar: data.bar}),
])
我要发货
updateFoo
当
data.foo
更改和
updateBar
当
data.bar
变化,知道
data
有许多其他属性会随着时间的推移而改变。
最佳答案
我认为这可能是一种方法:
updateProductData$ = createEffect(() =>
this.actions$.pipe(
ofType(fromActions.loadProduct),
switchMap(_) =>
this.http.get('endpoint').pipe(
delay(1000),
repeat(),
multicast(
new Subject(),
source => merge(
// concerning `foo`
source.pipe(
distinctUntilChanged((prev, crt) => prev.foo === crt.foo),
map(data => fromActions.updateFoo({foo: data.foo})),
),
// concerning `bar`
source.pipe(
distinctUntilChanged((prev, crt) => prev.bar === crt.bar),
map(data => fromActions.updateBar({bar: data.bar})),
),
)
)
)
)
);
source
来自
multicast
的第二个参数是已声明为第一个参数的 Subject 的实例。通过使用
multicast
,我们可以将问题分成 2 个其他较小的问题,而无需冗余订阅源(这就是使用 Subject 的原因)。
关于angular - 仅当 Rxjs 轮询上的某些属性发生更改时才调度 NgRx 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66330734/
我已经建立了这个IStore: export interface IStore { user: IUser; sources: ISourceRedux; } 其中IUser是: export
store.select()发出先前的存储状态。 是否可以订阅从“此刻开始”的更改,而无需获取先前的商店值(value)? 最佳答案 如果您对第一个发出的值不感兴趣,则应该可以使用 skip 运算符:
我已将我的 ngrx 代码更新到版本 8(使用 Action Creator 等),但我现在不知道如何在 NgRx Store DevTools 中使用 Dispatcher。 在我能够发送这样的操作
我正在开发一个新的 angular 4 plus @ngrx 4 项目。 我希望对加载的数据具有搜索功能。 例如,所有联系人信息都已加载到组件中。 联系人列表将过滤与搜索文本匹配的联系人姓名。 Ple
我正在使用 Ngrx 和 Angular2 构建一个移动应用程序。当用户从我的应用程序中注销时,我想清除商店?谁能知道该怎么做? 最佳答案 您应该在每个 reducer 中有一个明确的操作,这将清理商
我看到很多代码示例,其中 store.dispatch() 调用直接发生在 Angular 组件中。让一个愚蠢的 Angular 组件访问整个 Store 不是很糟糕吗?为什么不将所有的 Action
ngrx 的支持者声称 (here for example),您可以并且应该将所有应用程序状态保存在单个 Store 中。这表明 @ngrx/Store 可以用于缓存,因为缓存的内容是一种应用程序状态
我的应用程序在调度某个 Action 时没有调度某些 Action 或某些效果没有被调用,这有问题(请参阅 ngrx effect not being called when action is di
下面的代码片段有什么作用?取自此 file . export const getCollectionLoading = createSelector(getCollectionState, fromC
如果在同一个商店上分派(dispatch)多个操作: store.dispatch(new SomeAction()); store.dispatch(new SomeOtherAction());
我试图了解 typeof 效果在 ngrx 中是如何工作的,如果我在我的应用程序模块中声明: .... @NgModule({ imports: [ EffectsModule
任何人都可以建议在角度应用程序中使用 ngrx 进行状态管理时如何控制台记录状态。我已经浏览了 ngrx-store-logger,但是文档并不清楚如何创建元 reducer 和使用这个库。 最佳答案
我一直在阅读ngrx示例应用程序的代码并找到两个函数调用 createFeatureSelector('auth'); 和 createSelector(selectAuthState,(state:
我正在使用 Angular 8 和 NGRX 8。我有一个操作: export const loadEnvironment = createAction( LicencingActionTypes
我正在使用 Angular 8 和 NGRX 8。我有一个操作: export const loadEnvironment = createAction( LicencingActionTypes
以下示例取自 @ngrx example . 我以这种方式理解这个 observable。第一map函数获取 payload这是要添加的书,再次由mergeMap处理它保存到数据库的位置。 原码:
我目前正在使用 NgRx Data 对我项目中的几个实体执行 CRUD 操作。现在,我必须开发分页。因此,REST API 响应将如下所示: { "page": 1, "per_pag
如何在 NGRX 中访问(读取)另一个 reducer 中的 reducer 状态?这是一个与 this 非常相似的问题.NGRX 是否为此提供任何其他解决方案? 最佳答案 我在考虑做类似的事情时偶然
我正在尝试按属性过滤掉有效负载数据。 //reducer.ts case MessagesActionTypes.LOAD_Message_SUCCESS: { console.lo
我有效果类,我想根据路由器参数 ID 加载详细信息 @Effect() getDetails$ = this.actions$.ofType(DetailActions.GET_DETAILS).
我是一名优秀的程序员,十分优秀!