-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move selected building id into store
which makes custom handling in threeSceneService deprecated. Having only one global state and flow is more maintanable in general and in concrete it facilitates migrating to Angular. refs: #2318
- Loading branch information
1 parent
e9dcf9e
commit dc8ed14
Showing
8 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
visualization/app/codeCharta/state/store/lookUp/lookUp.reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
// Plop: Append reducer import here | ||
import { idToNode } from "./idToNode/idToNode.reducer" | ||
import { idToBuilding } from "./idToBuilding/idToBuilding.reducer" | ||
import { selectedBuildingId } from "./selectedBuildingId/selectedBuildingId.reducer" | ||
import { combineReducers } from "redux" | ||
|
||
const lookUp = combineReducers({ | ||
// Plop: Append sub-reducer here | ||
idToNode, | ||
idToBuilding | ||
idToBuilding, | ||
selectedBuildingId | ||
}) | ||
|
||
export default lookUp |
23 changes: 23 additions & 0 deletions
23
...zation/app/codeCharta/state/store/lookUp/selectedBuildingId/selectedBuildingId.actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Action } from "redux" | ||
import { SetIdToBuildingAction } from "../idToBuilding/idToBuilding.actions" | ||
|
||
export enum SelectedBuildingIdActions { | ||
SET_SELECTED_BUILDING_ID = "SET_SELECTED_BUILDING_ID" | ||
} | ||
|
||
type InferredKeyOfMap<M> = M extends Map<infer K, unknown> ? K : never | ||
export type SetSelectedBuildingIdPayload = InferredKeyOfMap<SetIdToBuildingAction["payload"]> | null | ||
|
||
export interface SetSelectedBuildingIdAction extends Action { | ||
type: SelectedBuildingIdActions.SET_SELECTED_BUILDING_ID | ||
payload: SetSelectedBuildingIdPayload | ||
} | ||
|
||
export const defaultSelectedBuildingId: SetSelectedBuildingIdPayload = null | ||
|
||
export const setSelectedBuildingId = ( | ||
selectedBuilding: SetSelectedBuildingIdPayload = defaultSelectedBuildingId | ||
): SetSelectedBuildingIdAction => ({ | ||
type: SelectedBuildingIdActions.SET_SELECTED_BUILDING_ID, | ||
payload: selectedBuilding | ||
}) |
19 changes: 19 additions & 0 deletions
19
...n/app/codeCharta/state/store/lookUp/selectedBuildingId/selectedBuildingId.reducer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { setSelectedBuildingId } from "./selectedBuildingId.actions" | ||
import { selectedBuildingId } from "./selectedBuildingId.reducer" | ||
|
||
describe("selectedBuildingId", () => { | ||
it("should set default state", () => { | ||
const newState = selectedBuildingId(undefined, { type: "someType" }) | ||
expect(newState).toBe(null) | ||
}) | ||
|
||
it("should update state", () => { | ||
const newState = selectedBuildingId(undefined, setSelectedBuildingId(1)) | ||
expect(newState).toBe(1) | ||
}) | ||
|
||
it("should ignore actions other than its own", () => { | ||
const newState = selectedBuildingId(1, { type: "someType", payload: 2 }) | ||
expect(newState).toBe(1) | ||
}) | ||
}) |
18 changes: 18 additions & 0 deletions
18
...zation/app/codeCharta/state/store/lookUp/selectedBuildingId/selectedBuildingId.reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { | ||
SetSelectedBuildingIdPayload, | ||
SelectedBuildingIdActions, | ||
SetSelectedBuildingIdAction, | ||
setSelectedBuildingId | ||
} from "./selectedBuildingId.actions" | ||
|
||
export const selectedBuildingId = ( | ||
state: SetSelectedBuildingIdPayload = setSelectedBuildingId().payload, | ||
action: Record<string, unknown> | SetSelectedBuildingIdAction | ||
) => { | ||
switch (action.type) { | ||
case SelectedBuildingIdActions.SET_SELECTED_BUILDING_ID: | ||
return (<SetSelectedBuildingIdAction>action).payload | ||
default: | ||
return state | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters