How to set/access activeId for Entity Props #49
Replies: 1 comment 2 replies
-
import { propsFactory } from '@ngneat/elf';
const { scenariosEntitiesRef, withScenariosEntities } = entitiesPropsFactory('scenarios');
const {
withScenariosActiveId,
selectScenariosActiveId,
setScenariosActiveId
} = propsFactory('scenariosActiveId', { initialValue: undefined as (undefined | string) });
const {state, config} = createState(
withEntities<AppProject, 'uid'>({idKey: 'uid'}),
withScenariosEntities<AppScenario, 'uid'>({idKey: 'uid'}),
withActiveId(),
withScenariosActiveId(),
withRequestsStatus<`projects` | 'scenarios'>(initializeAsPending(['projects', 'scenarios'])),
);
setActiveProjectId(projectId: AppProject['uid']) {
projectStore.update(setActiveId(projectId));
}
setScenarioId(scenarioId: AppScenario['uid']) {
projectStore.update(setScenariosActiveId(scenarioId));
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Synkretik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have a use case similar to your Angular Product/Cart example: My app has projects and each project has one or more scenario(s): projectStore.
In the projectStore I need to track both the activeProjectId and the activeScenarioId .
I thought one (hackish) way of doing it would be with
setActiveIds([activeProjectId , activeScenarioId])
Since I'm keeping the activeScenarioId on AppProject, I could also just keep track that way.
In the code above, I when I tried replacing, setActiveId() with setActiveIds() I get TS2345: Argument of type 'Reducer<{ activeIds: any[]; }>' is not assignable to parameter of type 'Reducer<{ activeId: any; } & { requestsStatus: Record<"projects", StatusState>; } & { requestsStatus: Record<"scenarios", StatusState>; } & { ...; } & { ...; }>'.
I thought the cleanest way of doing it would be
projectStore.update(setActiveId(scenarioId, {ref: scenariosEntitiesRef}));
to stay coherent.Any suggestions on how best to get this accomplished would be much appreciated!
Beta Was this translation helpful? Give feedback.
All reactions