У меня проблемы с магазином, потому что в одном магазине я сделал 3 состояния, я использую ngrx store в Angular.
Проблема в том, что все это работает, но у меня есть ошибки в TS
Я отредактировал вопрос из ответа кода @Fartab, он работает, но все еще показывает некоторые ошибки.
Вот код, который я сделал до сих пор.
cluster = Map<string, ClusterItem>();
this.store.select('technicalMatrix').subscribe(state => {
this.cluster = state.technicalCluster;
this.manufactures = state.manufacturer;
this.store.select('technicalMatrix').subscribe(state => {
this.cluster = ([...state.technicalCluster,
...state.costCenter,
...state.manufacturer]);
});
}
// this is for the state [ts] Type 'Map<string, ClusterItem>' is not an array type
// for this.cluster it is showing this error
// Only a void function can be called with the 'new' keyword
Свойство 'set' отсутствует в типе 'any []'.
Вот мои магазины.
export interface ApplicationState {
technicalMatrix: TechnicalMatrixState;
}
export const reducers: ActionReducerMap<ApplicationState> = {
technicalMatrix: technicalMatrixReducer
};
export interface TechnicalMatrixState {
costCenter: Map<string, ClusterItem>;
technicalCluster: Map<string, ClusterItem>;
manufacturer: Map<string, ClusterItem>;
activeMatrixType: string;
expandedTechnicalIds: Set<string>;
filter: Filter;
}
const INITIAL_STATE = {
costCenter: Map<string, ClusterItem>(),
technicalCluster: Map<string, ClusterItem>(),
manufacturer: Map<string, ClusterItem>(),
activeMatrixType: '',
expandedTechnicalIds: Set<string>(),
filter: {name: ''}
};
import { ApplicationState } from '~/shared/store/reducers';
import { createSelector } from '@ngrx/store';
export const selectClusterItemDatabaseState = (state: ApplicationState) => state.technicalMatrix;
export const selectActiveMatrix = createSelector(selectClusterItemDatabaseState, state => state[state.activeMatrixType]);
export const selectActiveMatrixType = createSelector(selectClusterItemDatabaseState, state => state.activeMatrixType);
export const selectCostCenters = createSelector(selectClusterItemDatabaseState, state => state.costCenter);
export const selectTechnicalClusters = createSelector(selectClusterItemDatabaseState, state => state.technicalCluster);
export const selectManufacturers = createSelector(selectClusterItemDatabaseState, state => state.manufacturer);
И я сделал метод здесь, чтобы увидеть, что видно из магазина.
setVisible() {
this.selectedMatrix.forEach(clusterId => {
const matrix = this.cluster.get(clusterId); //here is just one store selected this.cluster referes to the store state.technicalCluster
}
}