我已经阅读了SO提出的所有先前问题,但是我无法使其正常工作。这就是问题所在:
减速器1:
export interface ApplicationState extends EntityState<Application> {
draftApplication: Application;
}
export const adapter: EntityAdapter<Application> = createEntityAdapter<Application>(
);
export const initialState: ApplicationState = adapter.getInitialState({
draftApplication: null
});
// createReducer...
减速器2:
export interface InvitationState extends EntityState<Invitation> {
loading: boolean;
}
export const adapter: EntityAdapter<Invitation> = createEntityAdapter<Invitation>(
);
export interface State extends fromRoot.State {
invitations: InvitationState;
}
const initialState = adapter.getInitialState(
{loading: false}
);
// createReducer...
我想将它们组合在功能模块中,如下所示:
import {ActionReducerMap} from '@ngrx/store/src/models';
import * as fromInvitation from '../invitation/store/invitation.reducer';
import * as fromApplication from '../application/store/application.reducer';
import * as fromRoot from '../../reducers';
export interface AnnouncementState {
applications: fromApplication.ApplicationState;
invitations: fromInvitation.InvitationState;
}
export const reducers: ActionReducerMap<AnnouncementState> = {
applications: fromApplication.reducer,
invitations: fromInvitation.reducer
};
export interface State extends fromRoot.State {
announcement: AnnouncementState;
}
但是,当我随后在其中一个化简器上触发某些动作时,实体函数却不会,例如添加一个实体。addOne()
例如只是坐在那里,什么也不做。没有错误,没有商店更新。只是应用程序不更新商店。知道为什么吗?
编辑:
尝试了几件事之后,问题似乎出在我从Firebase Firestore分派。我的应用程序中的服务执行以下操作:
.subscribe(
changes => changes.forEach(change => {
console.log('Found invs: ', change.payload.doc.data());
this.store.dispatch({
type: `[ Invitation ] ${change.type}`, <-- Action to trigger
invitation: {
...change.payload.doc.data(),
id: change.payload.doc.id,
}
});
})
);
当我从组分中派出时,效果很好。不是通过服务。