createSelector - 我做错了
createSelector - I'm doing it wrong
我认为这是正确的,但它不起作用:
selectClaimTypeById: ((any) => MemoizedSelector<any, ClaimType[]>) = (props: any) => createSelector (
this.claimtypeSelector,
(claimTypes: ClaimType[]) => claimTypes
.filter ((claimType: ClaimType) => (claimType.claimType === props.claimType)
))
select(this.claimtypeSelector) 正确 return 是一组 ClaimType。我认为上面的代码被调用为 select(selectClaimTypeById, {claimId: id}), 会 return 一个 claimType 的过滤数组。
它return是一个记忆函数
this.store
.pipe (
select (this.selectors.selectClaimTypeById, {claimType: id}),
take (1))
.subscribe (data => record = data);
记录 = 函数记忆
我显然漏掉了什么
有什么帮助吗?
您声明的方法 returns 选择器具有:
selectClaimTypeById: ... = (props: any) => createSelector(
大概应该是这样的:
selectClaimTypeById: ... = createSelector(
这是您在文档中的用例:https://ngrx.io/guide/store/selectors#using-selectors-with-props
选择器被定义为一个函数,因此您必须调用它:
this.store
.pipe (
select (this.selectors.selectClaimTypeById(id)),
take (1))
.subscribe (data => record = data);
有关更多示例和解释,请参阅 Parameterized selectors
我认为这是正确的,但它不起作用:
selectClaimTypeById: ((any) => MemoizedSelector<any, ClaimType[]>) = (props: any) => createSelector (
this.claimtypeSelector,
(claimTypes: ClaimType[]) => claimTypes
.filter ((claimType: ClaimType) => (claimType.claimType === props.claimType)
))
select(this.claimtypeSelector) 正确 return 是一组 ClaimType。我认为上面的代码被调用为 select(selectClaimTypeById, {claimId: id}), 会 return 一个 claimType 的过滤数组。
它return是一个记忆函数
this.store
.pipe (
select (this.selectors.selectClaimTypeById, {claimType: id}),
take (1))
.subscribe (data => record = data);
记录 = 函数记忆
我显然漏掉了什么
有什么帮助吗?
您声明的方法 returns 选择器具有:
selectClaimTypeById: ... = (props: any) => createSelector(
大概应该是这样的:
selectClaimTypeById: ... = createSelector(
这是您在文档中的用例:https://ngrx.io/guide/store/selectors#using-selectors-with-props
选择器被定义为一个函数,因此您必须调用它:
this.store
.pipe (
select (this.selectors.selectClaimTypeById(id)),
take (1))
.subscribe (data => record = data);
有关更多示例和解释,请参阅 Parameterized selectors