Skip to content

Commit

Permalink
refactor #23: enable use of DomainSelector functions on LocalCache st…
Browse files Browse the repository at this point in the history
…ate (current DeploymentEntityState). Generalize types for useDeploymentEntityStateQuerySelector, by making the StateType (DeploymentEntityState) a parameter, so that selectors that do not depend on the state type can be used on different state types STEP 2, remove old type uses.
  • Loading branch information
miroir-framework committed Apr 10, 2024
1 parent f56e581 commit 53fab30
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 134 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {
DomainElement,
DomainElementObject,
DomainModelGetEntityDefinitionQueryParams,
DomainModelGetFetchParamJzodSchemaQueryParams,
DomainModelGetSingleSelectQueryJzodSchemaQueryParams,
DomainModelQueryJzodSchemaParams,
JzodElement,
JzodObject,
MiroirSelectorQueryParams
} from "../1_core/preprocessor-generated/miroirFundamentalType";
import { DeploymentEntityState } from "./DeploymentStateInterface";
import { DomainState } from "./DomainControllerInterface";

// ################################################################################################
export type RecordOfJzodElement = Record<string, JzodElement | undefined>;
Expand All @@ -21,51 +22,35 @@ export type QuerySelectorMap<QueryType extends MiroirSelectorQueryParams, StateT
selectByDomainManyQueries: QuerySelector<QueryType, StateType, DomainElementObject>
};

// ################################################################################################
export interface QuerySelectorParams<QueryType extends MiroirSelectorQueryParams, StateType> {
selectorMap?: QuerySelectorMap<QueryType, StateType>
query: QueryType
}

// ################################################################################################
export type QuerySelector<QueryType extends MiroirSelectorQueryParams, StateType, ResultType> = (
domainState: StateType,
params: QuerySelectorParams<QueryType, StateType>
) => ResultType;




// ################################################################################################
export type DeploymentEntityStateQuerySelectorMap<Q extends MiroirSelectorQueryParams> = {
[k: string]: DeploymentEntityStateQuerySelector<Q, any>;
export type JzodSchemaQuerySelectorMap<StateType> = {
selectJzodSchemaByDomainModelQuery: JzodSchemaQuerySelector<DomainModelQueryJzodSchemaParams, StateType>,
selectEntityJzodSchema: JzodSchemaQuerySelector<DomainModelGetEntityDefinitionQueryParams, StateType>,
selectFetchQueryJzodSchema: JzodSchemaQuerySelector<DomainModelGetFetchParamJzodSchemaQueryParams, StateType>,
selectJzodSchemaBySingleSelectQuery: JzodSchemaQuerySelector<DomainModelGetSingleSelectQueryJzodSchemaQueryParams, StateType>,
};

export interface DeploymentEntityStateQuerySelectorParams<Q extends MiroirSelectorQueryParams> {
selectorMap?: DeploymentEntityStateQuerySelectorMap<Q>
query: Q
// ################################################################################################
export interface JzodSchemaQuerySelectorParams<QueryType extends DomainModelQueryJzodSchemaParams, StateType> {
selectorMap: JzodSchemaQuerySelectorMap<StateType>
query: QueryType
}

export type DeploymentEntityStateQuerySelector<Q extends MiroirSelectorQueryParams, T> = (
domainState: DeploymentEntityState,
params: DeploymentEntityStateQuerySelectorParams<Q>
) => T;


// // ################################################################################################
export type DeploymentEntityStateJzodSchemaSelector<Q extends DomainModelQueryJzodSchemaParams> = (
domainState: DeploymentEntityState,
params: DeploymentEntityStateJzodSchemaSelectorParams<Q>
// ################################################################################################
export type JzodSchemaQuerySelector<QueryType extends DomainModelQueryJzodSchemaParams, StateType> = (
domainState: StateType,
params: JzodSchemaQuerySelectorParams<QueryType, StateType>
) => RecordOfJzodElement | JzodElement | undefined;

export type DeploymentEntityStateJzodSchemaSelectorMap = {[k:string]: DeploymentEntityStateJzodSchemaSelector<DomainModelQueryJzodSchemaParams>};

export interface DeploymentEntityStateJzodSchemaSelectorParams<Q extends DomainModelQueryJzodSchemaParams> {
selectorMap: DeploymentEntityStateJzodSchemaSelectorMap
query: Q
}

// // ################################################################################################
// export type DomainStateSelector<P extends MiroirSelectorQueryParams, T> = (
// domainState: DomainState,
// params: P
// ) => T;

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions packages/miroir-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,13 @@ export {
RecordOfJzodObject,
} from './0_interfaces/2_domain/DomainStateQuerySelectorInterface.js';
export {
JzodSchemaQuerySelector,
JzodSchemaQuerySelectorMap,
JzodSchemaQuerySelectorParams,
QuerySelector,
QuerySelectorMap,
QuerySelectorParams,
DeploymentEntityStateQuerySelector,
DeploymentEntityStateQuerySelectorMap,
DeploymentEntityStateQuerySelectorParams,
DeploymentEntityStateJzodSchemaSelector,
DeploymentEntityStateJzodSchemaSelectorMap,
DeploymentEntityStateJzodSchemaSelectorParams,

// RecordOfJzodElement,
// RecordOfJzodObject,
} from './0_interfaces/2_domain/DeploymentEntityStateQuerySelectorInterface.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createSelector } from "@reduxjs/toolkit";
import {
DeploymentEntityState,
DeploymentEntityStateJzodSchemaSelectorMap,
DomainState,
DomainStateJzodSchemaSelectorMap,
DomainStateQuerySelectorMap,
JzodSchemaQuerySelectorMap,
MiroirSelectorQueryParams,
QuerySelectorMap,
selectByDomainManyQueriesFromDeploymentEntityState,
Expand Down Expand Up @@ -74,7 +74,7 @@ export function getMemoizedDeploymentEntityStateSelectorMap(): QuerySelectorMap<
};
}

export function getMemoizedDeploymentEntityStateJzodSchemaSelectorMap(): DeploymentEntityStateJzodSchemaSelectorMap {
export function getMemoizedDeploymentEntityStateJzodSchemaSelectorMap(): JzodSchemaQuerySelectorMap<DeploymentEntityState> {
// return jzodSchemaSelectorMap;
return {
selectJzodSchemaByDomainModelQuery: createSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import { createSelector } from "@reduxjs/toolkit";
import {
DeploymentEntityState,
DeploymentEntityStateJzodSchemaSelectorParams,
DeploymentEntityStateQuerySelector,
DeploymentEntityStateQuerySelectorParams,
DomainElement,
DomainModelQueryJzodSchemaParams,
DomainState,
Expand Down Expand Up @@ -60,15 +57,6 @@ declare type SelectorParamsSelector<QueryType extends MiroirSelectorQueryParams,
params: QuerySelectorParams<QueryType, StateType>
) => QuerySelectorParams<QueryType, StateType>;

declare type DeploymentEntityStateSelectorParamsSelector<Q extends MiroirSelectorQueryParams> = (
reduxState: ReduxStateWithUndoRedo,
params: DeploymentEntityStateQuerySelectorParams<Q>
) => DeploymentEntityStateQuerySelectorParams<Q>;

declare type DeploymentEntityStateJzodSchemaSelectorParamsSelector<Q extends DomainModelQueryJzodSchemaParams> = (
reduxState: ReduxStateWithUndoRedo,
params: DeploymentEntityStateJzodSchemaSelectorParams<Q>
) => DeploymentEntityStateJzodSchemaSelectorParams<Q>;

// ################################################################################################
export const selectCurrentDeploymentEntityStateFromReduxState = (
Expand All @@ -78,10 +66,10 @@ export const selectCurrentDeploymentEntityStateFromReduxState = (
};

// ################################################################################################
export const selectDeploymentEntityStateSelectorParams /*: DomainStateSelectorParamsSelector<Q> */ = <Q extends MiroirSelectorQueryParams>(
export const selectDeploymentEntityStateSelectorParams /*: DomainStateSelectorParamsSelector<Q> */ = <QueryType extends MiroirSelectorQueryParams>(
reduxState: ReduxStateWithUndoRedo,
params: DeploymentEntityStateQuerySelectorParams<Q>
): DeploymentEntityStateQuerySelectorParams<Q> => {
params: QuerySelectorParams<QueryType, DeploymentEntityState>
): QuerySelectorParams<QueryType, DeploymentEntityState> => {
return params;
};

Expand Down Expand Up @@ -159,14 +147,14 @@ export const selectDomainStateJzodSchemaSelectorParams = <Q extends DomainModelQ
// ################################################################################################
// ################################################################################################
export function applyDeploymentEntityStateQuerySelector<QueryType extends MiroirSelectorQueryParams, ResultType>( // TODO: memoize?
deploymentEntityStateQuerySelector: DeploymentEntityStateQuerySelector<QueryType, ResultType>
deploymentEntityStateQuerySelector: QuerySelector<QueryType, DeploymentEntityState, ResultType>
): (
reduxState: ReduxStateWithUndoRedo,
params: DeploymentEntityStateQuerySelectorParams<QueryType>
params: QuerySelectorParams<QueryType, DeploymentEntityState>
) => ResultType {
return createSelector(
// [selectCurrentDeploymentEntityStateFromReduxState, selectDomainStateSelectorParams as DomainStateSelectorParamsSelector<Q>],
[selectCurrentDeploymentEntityStateFromReduxState, selectDeploymentEntityStateSelectorParams as DeploymentEntityStateSelectorParamsSelector<QueryType>],
[selectCurrentDeploymentEntityStateFromReduxState, selectDeploymentEntityStateSelectorParams as SelectorParamsSelector<QueryType, DeploymentEntityState>],
deploymentEntityStateQuerySelector
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { useSelector } from "react-redux";
import {
ApplicationSection,
DeploymentEntityState,
DeploymentEntityStateQuerySelector,
DeploymentEntityStateQuerySelectorParams,
DomainElement,
DomainModelQueryJzodSchemaParams,
DomainStateJzodSchemaSelector,
Expand Down Expand Up @@ -55,16 +53,16 @@ MiroirLoggerFactory.asyncCreateLogger(loggerName).then((value: LoggerInterface)
export type EntityInstanceUuidIndexSelectorParams = LocalCacheEntityInstancesSelectorParams;

// ################################################################################################
export function useDeploymentEntityStateQuerySelector<Q extends MiroirSelectorQueryParams, T >(
deploymentEntityStateQuerySelector:DeploymentEntityStateQuerySelector<Q, T>,
selectorParams:DeploymentEntityStateQuerySelectorParams<Q>,
customQueryInterpreter?: { [k: string]: (query:MiroirSelectorQueryParams) => T }
): T {
export function useDeploymentEntityStateQuerySelector<QueryType extends MiroirSelectorQueryParams, ResultType extends DomainElement>(
deploymentEntityStateQuerySelector:QuerySelector<QueryType, DeploymentEntityState, ResultType>,
selectorParams:QuerySelectorParams<QueryType, DeploymentEntityState>,
customQueryInterpreter?: { [k: string]: (query:MiroirSelectorQueryParams) => ResultType }
): ResultType {
const innerSelector = useMemo(
() => {
return applyDeploymentEntityStateQuerySelector(deploymentEntityStateQuerySelector);
}, [deploymentEntityStateQuerySelector]);
const result: T = useSelector((state: ReduxStateWithUndoRedo) =>
const result: ResultType = useSelector((state: ReduxStateWithUndoRedo) =>
innerSelector(state, selectorParams)
);
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import {
ApplicationDeploymentConfiguration,
ApplicationDeploymentSchema,
DeploymentEntityState,
DeploymentEntityStateQuerySelector,
DeploymentEntityStateQuerySelectorMap,
DeploymentEntityStateQuerySelectorParams,
DomainControllerInterface,
DomainElement,
DomainManyQueriesWithDeploymentUuid,
Expand Down Expand Up @@ -320,7 +317,6 @@ export const ReportSectionListDisplay: React.FC<ReportComponentProps> = (
]
);

// const foreignKeyObjectsFetchQueryParams: DeploymentEntityStateQuerySelectorParams<DomainManyQueriesWithDeploymentUuid> = useMemo(
const foreignKeyObjectsFetchQueryParams: QuerySelectorParams<
DomainManyQueriesWithDeploymentUuid,
DeploymentEntityState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { useMemo } from 'react';
import {
ApplicationDeploymentConfiguration,
ApplicationSection,
DeploymentEntityStateQuerySelectorMap,
DeploymentEntityState,
DomainElementObject,
DomainStateQuerySelectorMap,
Entity,
EntityDefinition,
LoggerInterface,
MiroirLoggerFactory,
MiroirSelectorQueryParams,
QuerySelectorMap,
RecordOfJzodObject,
ReportSection,
RootReportSection,
Expand Down Expand Up @@ -42,7 +42,7 @@ export interface ReportSectionEntityInstanceProps {
paramsAsdomainElements: DomainElementObject,
reportSection: ReportSection,
rootReportSection: RootReportSection,
selectorMap: DeploymentEntityStateQuerySelectorMap<MiroirSelectorQueryParams>
selectorMap: QuerySelectorMap<MiroirSelectorQueryParams, DeploymentEntityState>
}

// ###############################################################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Params } from 'react-router-dom';

import {
ApplicationSection,
DeploymentEntityStateQuerySelectorMap,
DeploymentEntityStateQuerySelectorParams,
DeploymentEntityState,
DomainElementObject,
DomainManyQueriesWithDeploymentUuid,
DomainModelGetFetchParamJzodSchemaQueryParams,
Expand All @@ -13,12 +12,13 @@ import {
LoggerInterface,
MiroirLoggerFactory,
MiroirSelectorQueryParams,
QuerySelectorMap,
QuerySelectorParams,
RecordOfJzodObject,
RootReportSection,
Uuid,
getDeploymentEntityStateSelectorParams,
getLoggerName,
selectFetchQueryJzodSchemaFromDomainStateNew
getLoggerName
} from "miroir-core";


Expand Down Expand Up @@ -77,12 +77,12 @@ export const RootReportSectionView = (props: RootReportSectionEntityInstanceProp
// props.reportSection.fetchQuery
// );

const deploymentEntityStateSelectorMap: DeploymentEntityStateQuerySelectorMap<MiroirSelectorQueryParams> = useMemo(
const deploymentEntityStateSelectorMap: QuerySelectorMap<MiroirSelectorQueryParams, DeploymentEntityState> = useMemo(
() => getMemoizedDeploymentEntityStateSelectorMap(),
[]
)

const deploymentEntityStateFetchQueryParams: DeploymentEntityStateQuerySelectorParams<DomainManyQueriesWithDeploymentUuid> = useMemo(
const deploymentEntityStateFetchQueryParams: QuerySelectorParams<DomainManyQueriesWithDeploymentUuid, DeploymentEntityState> = useMemo(
() =>
props.pageParams.deploymentUuid && props.pageParams.applicationSection && props.pageParams.reportUuid
? getDeploymentEntityStateSelectorParams<DomainManyQueriesWithDeploymentUuid>(
Expand Down
11 changes: 6 additions & 5 deletions packages/miroir-standalone-app/src/miroir-fwk/4_view/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ import { AutoStories } from '@mui/icons-material';
import { Icon } from '@mui/material';
import {
applicationDeploymentMiroir,
DeploymentEntityStateQuerySelectorMap,
DeploymentEntityStateQuerySelectorParams,
DeploymentEntityState,
DomainElementObject,
DomainManyQueriesWithDeploymentUuid,
getDeploymentEntityStateSelectorParams,
getLoggerName,
LoggerInterface,
menuDefaultMiroir,
MiroirLoggerFactory,
MiroirSelectorQueryParams
MiroirSelectorQueryParams,
QuerySelectorMap,
QuerySelectorParams
} from "miroir-core";
import { getMemoizedDeploymentEntityStateSelectorMap } from 'miroir-localcache-redux';
import { useMemo } from 'react';
Expand Down Expand Up @@ -162,12 +163,12 @@ export const Sidebar = (props: {open:boolean, setOpen: (v:boolean)=>void}) => {
// const miroirConfig = context.getMiroirConfig();
// const context = useMiroirContext();

const deploymentEntityStateSelectorMap: DeploymentEntityStateQuerySelectorMap<MiroirSelectorQueryParams> = useMemo(
const deploymentEntityStateSelectorMap: QuerySelectorMap<MiroirSelectorQueryParams, DeploymentEntityState> = useMemo(
() => getMemoizedDeploymentEntityStateSelectorMap(),
[]
)

const deploymentEntityStateFetchQueryParams: DeploymentEntityStateQuerySelectorParams<DomainManyQueriesWithDeploymentUuid> = useMemo(
const deploymentEntityStateFetchQueryParams: QuerySelectorParams<DomainManyQueriesWithDeploymentUuid, DeploymentEntityState> = useMemo(
() =>
getDeploymentEntityStateSelectorParams<DomainManyQueriesWithDeploymentUuid>({
queryType: "DomainManyQueries",
Expand Down

0 comments on commit 53fab30

Please sign in to comment.