Skip to content

Commit

Permalink
fix: restore old behavior to reset state when dispatching undefined
Browse files Browse the repository at this point in the history
ref #3250
  • Loading branch information
shaman-apprentice committed Apr 27, 2023
1 parent 0cb2a02 commit 0b4fe33
Show file tree
Hide file tree
Showing 46 changed files with 130 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createReducer, on } from "@ngrx/store"
import { setAmountOfEdgePreviews } from "./amountOfEdgePreviews.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultAmountOfEdgesPreviews = 1
export const amountOfEdgePreviews = createReducer(
defaultAmountOfEdgesPreviews,
on(setAmountOfEdgePreviews, (_state, action) => action.value)
on(setAmountOfEdgePreviews, setState(defaultAmountOfEdgesPreviews))
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setAmountOfTopLabels } from "./amountOfTopLabels.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultAmountOfTopLabels = 1
export const amountOfTopLabels = createReducer(
defaultAmountOfTopLabels,
on(setAmountOfTopLabels, (_state, action) => action.value)
)
export const amountOfTopLabels = createReducer(defaultAmountOfTopLabels, on(setAmountOfTopLabels, setState(defaultAmountOfTopLabels)))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colorLabels, defaultColorLabels } from "./colorLabels/colorLabels.reducer"
import { colorLabels, defaultColorLabelOptions } from "./colorLabels/colorLabels.reducer"
import { defaultShowMetricLabelNodeName, showMetricLabelNodeName } from "./showMetricLabelNodeName/showMetricLabelNodeName.reducer"
import { defaultShowMetricLabelNameValue, showMetricLabelNameValue } from "./showMetricLabelNameValue/showMetricLabelNameValue.reducer"
import { defaultSortingOrderAscending, sortingOrderAscending } from "./sortingOrderAscending/sortingOrderAscending.reducer"
Expand Down Expand Up @@ -68,7 +68,7 @@ export const appSettings = combineReducers({
})

export const defaultAppSettings = {
colorLabels: defaultColorLabels,
colorLabels: defaultColorLabelOptions,
showMetricLabelNodeName: defaultShowMetricLabelNodeName,
showMetricLabelNameValue: defaultShowMetricLabelNameValue,
sortingOrderAscending: defaultSortingOrderAscending,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colorLabels, defaultColorLabels } from "./colorLabels.reducer"
import { colorLabels, defaultColorLabelOptions } from "./colorLabels.reducer"
import { setColorLabels } from "./colorLabels.actions"

describe("colorLabels", () => {
Expand All @@ -9,7 +9,7 @@ describe("colorLabels", () => {
}

it("should set new colorLabels", () => {
const result = colorLabels(defaultColorLabels, setColorLabels({ value: otherColorLabelOption }))
const result = colorLabels(defaultColorLabelOptions, setColorLabels({ value: otherColorLabelOption }))

expect(result).toEqual(otherColorLabelOption)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createReducer, on } from "@ngrx/store"
import { setColorLabels } from "./colorLabels.actions"
import { ColorLabelOptions } from "../../../../codeCharta.model"
import { mergeState } from "../../util/setState.reducer.factory"

export const defaultColorLabels: ColorLabelOptions = { positive: false, negative: false, neutral: false }
export const colorLabels = createReducer(
defaultColorLabels,
on(setColorLabels, (state, action) => ({ ...state, ...action.value }))
)
export const defaultColorLabelOptions: ColorLabelOptions = { positive: false, negative: false, neutral: false }
export const colorLabels = createReducer(defaultColorLabelOptions, on(setColorLabels, mergeState(defaultColorLabelOptions)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setEdgeHeight } from "./edgeHeight.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultEdgeHeight = 4
export const edgeHeight = createReducer(
defaultEdgeHeight,
on(setEdgeHeight, (_state, action) => action.value)
)
export const edgeHeight = createReducer(defaultEdgeHeight, on(setEdgeHeight, setState(defaultEdgeHeight)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createReducer, on } from "@ngrx/store"
import { setScreenshotToClipboardEnabled } from "./screenshotToClipboardEnabled.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultScreenshotToClipboardEnabled = false
export const screenshotToClipboardEnabled = createReducer(
defaultScreenshotToClipboardEnabled,
on(setScreenshotToClipboardEnabled, (_state, action) => action.value)
on(setScreenshotToClipboardEnabled, setState(defaultScreenshotToClipboardEnabled))
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createReducer, on } from "@ngrx/store"
import { setExperimentalFeaturesEnabled } from "./experimentalFeaturesEnabled.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultExperimentalFeaturesEnabled = false
export const experimentalFeaturesEnabled = createReducer(
defaultExperimentalFeaturesEnabled,
on(setExperimentalFeaturesEnabled, (_state, action) => action.value)
on(setExperimentalFeaturesEnabled, setState(defaultExperimentalFeaturesEnabled))
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setEnableFloorLabels } from "./enableFloorLabels.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultEnableFloorLabels = true
export const enableFloorLabels = createReducer(
defaultEnableFloorLabels,
on(setEnableFloorLabels, (_state, action) => action.value)
)
export const enableFloorLabels = createReducer(defaultEnableFloorLabels, on(setEnableFloorLabels, setState(defaultEnableFloorLabels)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setHideFlatBuildings } from "./hideFlatBuildings.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultHideFlatBuildings = false
export const hideFlatBuildings = createReducer(
defaultHideFlatBuildings,
on(setHideFlatBuildings, (_state, action) => action.value)
)
export const hideFlatBuildings = createReducer(defaultHideFlatBuildings, on(setHideFlatBuildings, setState(defaultHideFlatBuildings)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setInvertArea } from "./invertArea.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultInvertArea = false
export const invertArea = createReducer(
defaultInvertArea,
on(setInvertArea, (_state, action) => action.value)
)
export const invertArea = createReducer(defaultInvertArea, on(setInvertArea, setState(defaultInvertArea)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setInvertHeight } from "./invertHeight.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultInvertHeight = false
export const invertHeight = createReducer(
defaultInvertHeight,
on(setInvertHeight, (_state, action) => action.value)
)
export const invertHeight = createReducer(defaultInvertHeight, on(setInvertHeight, setState(defaultInvertHeight)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setIsLoadingFile } from "./isLoadingFile.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultIsLoadingFile = true
export const isLoadingFile = createReducer(
defaultIsLoadingFile,
on(setIsLoadingFile, (_state, action) => action.value)
)
export const isLoadingFile = createReducer(defaultIsLoadingFile, on(setIsLoadingFile, setState(defaultIsLoadingFile)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { setState } from "../../util/setState.reducer.factory"
import { setIsLoadingMap } from "./isLoadingMap.actions"
import { createReducer, on } from "@ngrx/store"

export const defaultIsLoadingMap = true
export const isLoadingMap = createReducer(
defaultIsLoadingMap,
on(setIsLoadingMap, (_state, action) => action.value)
)
export const isLoadingMap = createReducer(defaultIsLoadingMap, on(setIsLoadingMap, setState(defaultIsLoadingMap)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setPresentationMode } from "./isPresentationMode.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultIsPresentationMode = false
export const isPresentationMode = createReducer(
defaultIsPresentationMode,
on(setPresentationMode, (_state, action) => action.value)
)
export const isPresentationMode = createReducer(defaultIsPresentationMode, on(setPresentationMode, setState(defaultIsPresentationMode)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setIsWhiteBackground } from "./isWhiteBackground.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultIsWhiteBackground = false
export const isWhiteBackground = createReducer(
defaultIsWhiteBackground,
on(setIsWhiteBackground, (_state, action) => action.value)
)
export const isWhiteBackground = createReducer(defaultIsWhiteBackground, on(setIsWhiteBackground, setState(defaultIsWhiteBackground)))
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createReducer, on } from "@ngrx/store"
import { LayoutAlgorithm } from "../../../../codeCharta.model"
import { setLayoutAlgorithm } from "./layoutAlgorithm.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultLayoutAlgorithm = LayoutAlgorithm.SquarifiedTreeMap
export const layoutAlgorithm = createReducer(
defaultLayoutAlgorithm,
on(setLayoutAlgorithm, (_state, action) => action.value)
)
export const layoutAlgorithm = createReducer(defaultLayoutAlgorithm, on(setLayoutAlgorithm, setState(defaultLayoutAlgorithm)))
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createReducer, on } from "@ngrx/store"
import { MapColors } from "../../../../codeCharta.model"
import { invertColorRange, invertDeltaColors, setMapColors } from "./mapColors.actions"
import { mergeState } from "../../util/setState.reducer.factory"

export const defaultMapColors: MapColors = {
positive: "#69AE40",
Expand All @@ -19,7 +20,7 @@ export const defaultMapColors: MapColors = {

export const mapColors = createReducer(
defaultMapColors,
on(setMapColors, (state, action) => ({ ...state, ...(action.value ?? defaultMapColors) })),
on(setMapColors, mergeState(defaultMapColors)),
on(invertColorRange, state => ({ ...state, positive: state.negative, negative: state.positive })),
on(invertDeltaColors, state => ({ ...state, positiveDelta: state.negativeDelta, negativeDelta: state.positiveDelta }))
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setMaxTreeMapFiles } from "./maxTreeMapFiles.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultMaxTreeMapFiles = 100
export const maxTreeMapFiles = createReducer(
defaultMaxTreeMapFiles,
on(setMaxTreeMapFiles, (_state, action) => action.value)
)
export const maxTreeMapFiles = createReducer(defaultMaxTreeMapFiles, on(setMaxTreeMapFiles, setState(defaultMaxTreeMapFiles)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createReducer, on } from "@ngrx/store"
import { setResetCameraIfNewFileIsLoaded } from "./resetCameraIfNewFileIsLoaded.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultResetCameraIfNewFileIsLoaded = true
export const resetCameraIfNewFileIsLoaded = createReducer(
defaultResetCameraIfNewFileIsLoaded,
on(setResetCameraIfNewFileIsLoaded, (_state, action) => action.value)
on(setResetCameraIfNewFileIsLoaded, setState(defaultResetCameraIfNewFileIsLoaded))
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createReducer, on } from "@ngrx/store"
import { setScaling } from "./scaling.actions"
import { Scaling } from "../../../../codeCharta.model"
import { mergeState } from "../../util/setState.reducer.factory"

export const defaultScaling: Scaling = { x: 1, y: 1, z: 1 }
export const scaling = createReducer(
defaultScaling,
on(setScaling, (state, action) => ({ ...state, ...action.value }))
)
export const scaling = createReducer(defaultScaling, on(setScaling, mergeState(defaultScaling)))
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createReducer, on } from "@ngrx/store"
import { SharpnessMode } from "../../../../codeCharta.model"
import { setSharpnessMode } from "./sharpnessMode.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultSharpnessMode = SharpnessMode.Standard
export const sharpnessMode = createReducer(
defaultSharpnessMode,
on(setSharpnessMode, (_state, action) => action.value)
)
export const sharpnessMode = createReducer(defaultSharpnessMode, on(setSharpnessMode, setState(defaultSharpnessMode)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createReducer, on } from "@ngrx/store"
import { setShowMetricLabelNameValue } from "./showMetricLabelNameValue.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultShowMetricLabelNameValue = false
export const showMetricLabelNameValue = createReducer(
defaultShowMetricLabelNameValue,
on(setShowMetricLabelNameValue, (_state, action) => action.value)
on(setShowMetricLabelNameValue, setState(defaultShowMetricLabelNameValue))
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createReducer, on } from "@ngrx/store"
import { setShowMetricLabelNodeName } from "./showMetricLabelNodeName.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultShowMetricLabelNodeName = true
export const showMetricLabelNodeName = createReducer(
defaultShowMetricLabelNodeName,
on(setShowMetricLabelNodeName, (_state, action) => action.value)
on(setShowMetricLabelNodeName, setState(defaultShowMetricLabelNodeName))
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createReducer, on } from "@ngrx/store"
import { setShowOnlyBuildingsWithEdges } from "./showOnlyBuildingsWithEdges.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultShowOnlyBuildingsWithEdges = false
export const showOnlyBuildingsWithEdges = createReducer(
defaultShowOnlyBuildingsWithEdges,
on(setShowOnlyBuildingsWithEdges, (_state, action) => action.value)
on(setShowOnlyBuildingsWithEdges, setState(defaultShowOnlyBuildingsWithEdges))
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createReducer, on } from "@ngrx/store"
import { setSortingOrderAscending, toggleSortingOrderAscending } from "./sortingOrderAscending.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultSortingOrderAscending = true
export const sortingOrderAscending = createReducer(
defaultSortingOrderAscending,
on(setSortingOrderAscending, (_state, action) => action.value),
on(setSortingOrderAscending, setState(defaultSortingOrderAscending)),
on(toggleSortingOrderAscending, state => !state)
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createReducer, on } from "@ngrx/store"
import { CcState } from "../../../../codeCharta.model"
import { setHoveredNodeId } from "./hoveredNodeId.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultHoveredNodeId: CcState["appStatus"]["hoveredNodeId"] = null
export const hoveredNodeId = createReducer(
defaultHoveredNodeId,
on(setHoveredNodeId, (_state, action) => action.value)
)
export const hoveredNodeId = createReducer(defaultHoveredNodeId, on(setHoveredNodeId, setState(defaultHoveredNodeId)))
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createReducer, on } from "@ngrx/store"
import { CcState } from "../../../../codeCharta.model"
import { setSelectedBuildingId } from "./selectedBuildingId.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultSelectedBuildingId: CcState["appStatus"]["selectedBuildingId"] = null
export const selectedBuildingId = createReducer(
defaultSelectedBuildingId,
on(setSelectedBuildingId, (_state, action) => action.value)
)
export const selectedBuildingId = createReducer(defaultSelectedBuildingId, on(setSelectedBuildingId, setState(defaultSelectedBuildingId)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setAreaMetric } from "./areaMetric.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultAreaMetric: null | string = null
export const areaMetric = createReducer(
defaultAreaMetric,
on(setAreaMetric, (_state, action) => action.value)
)
export const areaMetric = createReducer(defaultAreaMetric, on(setAreaMetric, setState(defaultAreaMetric)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setColorMetric } from "./colorMetric.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultColorMetric: null | string = null
export const colorMetric = createReducer(
defaultColorMetric,
on(setColorMetric, (_state, action) => action.value)
)
export const colorMetric = createReducer(defaultColorMetric, on(setColorMetric, setState(defaultColorMetric)))
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createReducer, on } from "@ngrx/store"
import { ColorMode } from "../../../../codeCharta.model"
import { setColorMode } from "./colorMode.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultColorMode = ColorMode.weightedGradient
export const colorMode = createReducer(
defaultColorMode,
on(setColorMode, (_state, action) => action.value)
)
export const colorMode = createReducer(defaultColorMode, on(setColorMode, setState(defaultColorMode)))
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createReducer, on } from "@ngrx/store"
import { setColorRange } from "./colorRange.actions"
import { ColorRange } from "../../../../codeCharta.model"
import { mergeState } from "../../util/setState.reducer.factory"

export const defaultColorRange: ColorRange = { from: 0, to: 0 }
export const colorRange = createReducer(
defaultColorRange,
on(setColorRange, (state, action) => ({ ...state, ...action.value }))
)
export const colorRange = createReducer(defaultColorRange, on(setColorRange, mergeState(defaultColorRange)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setDistributionMetric } from "./distributionMetric.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultDistributionMetric: null | string = null
export const distributionMetric = createReducer(
defaultDistributionMetric,
on(setDistributionMetric, (_state, action) => action.value)
)
export const distributionMetric = createReducer(defaultDistributionMetric, on(setDistributionMetric, setState(defaultDistributionMetric)))
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createReducer, on } from "@ngrx/store"
import { setEdgeMetric } from "./edgeMetric.actions"
import { setState } from "../../util/setState.reducer.factory"

export const defaultEdgeMetric: null | string = null
export const edgeMetric = createReducer(
defaultEdgeMetric,
on(setEdgeMetric, (_state, action) => action.value)
)
export const edgeMetric = createReducer(defaultEdgeMetric, on(setEdgeMetric, setState(defaultEdgeMetric)))
Loading

0 comments on commit 0b4fe33

Please sign in to comment.