我有一个多部分的表格,用户可以在每个部分的下方留下评论和关注的地方,每个部分都被称为一门学科。这样做的代码:
getComments(planId: number, disciplineType: DisciplineType): Observable<DisciplineComment[]>
{
let discipline = DisciplineType[disciplineType];
let url = this.odataUrl + "Comments?$expand=resolution&$filter=plan_Id eq " + planId + " and discipline eq '" + discipline + "'";
return this.http
.get<{ value: DisciplineComment[] }>(url)
.pipe(map(businessUnits => businessUnits.value || []));
}
关于上下文,这里是效果
@Effect()
loadPandLComments$: Observable<Action> = this.actions$
.ofType<Load>(PandLCommentActionTypes.Load).pipe(
switchMap(action => this.planService.getComments(action.payload, this.disciplineType)),
map((comments: any) => new LoadSuccess(comments)),
catchError(err => of(new LoadFail(err)))
);
和减速器
case PandLCommentActionTypes.Load: {
return {
...state,
loading: true,
};
}
case PandLCommentActionTypes.LoadSuccess: {
return adapter.addMany(action.payload, {
...state,
loaded: true,
loading: false,
});
}
和状态
export interface State extends EntityState<PandLComment> {
loaded: boolean;
loading: boolean;
}
export function sortByCreatedAt(a: PandLComment, b: PandLComment): number {
return Number(b.createdAt) - Number(a.createdAt);
}
export const adapter: EntityAdapter<PandLComment> = createEntityAdapter<PandLComment>({
selectId: (comment: PandLComment) => comment.id,
sortComparer: sortByCreatedAt,
});
export const initialState: State = adapter.getInitialState({
loaded: false,
loading: false,
});
每当我使用新的ID加载时,我都会以加载的第一个状态结束。无论如何,有没有要它放弃使用平面检查或其他东西的状态?