Skip to content

Commit

Permalink
refactor: WIP fix initial color reset
Browse files Browse the repository at this point in the history
ref #3250
  • Loading branch information
shaman-apprentice committed Mar 31, 2023
1 parent 90692ae commit 4554f17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { setColorRange } from "./colorRange.actions"
import { ColorRange } from "../../../../codeCharta.model"

export const colorRange = createReducer(
// TODO this PR maybe 0, 0 better default?
{ from: null, to: null } as ColorRange,
on(setColorRange, (state, payload) => ({ ...state, ...payload.value }))
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from "@angular/core"
import { Store } from "@ngrx/store"
import { Actions, createEffect, ofType } from "@ngrx/effects"
import { map, withLatestFrom } from "rxjs"
import { map, skip, switchMap, take } from "rxjs"
import { selectedColorMetricDataSelector } from "../../../selectors/accumulatedData/metricData/selectedColorMetricData.selector"
import { calculateInitialColorRange } from "./calculateInitialColorRange"
import { setColorRange } from "./colorRange.actions"
Expand All @@ -10,22 +10,15 @@ import { State } from "../../../../codeCharta.model"

@Injectable()
export class ResetColorRangeEffect {
private resetActions$ = this.actions$.pipe(
ofType(...fileActions)
// TODO or case
// filter action =>
// isActionOfType(action.type, FilesSelectionActions) ||
// (isAction<SetColorRangeAction>(action, ColorRangeActions.SET_COLOR_RANGE) &&
// action.payload.from === null &&
// action.payload.to === null)
)

constructor(private actions$: Actions, private store: Store<State>) {}

resetColorRange$ = createEffect(() =>
this.resetActions$.pipe(
withLatestFrom(this.store.select(selectedColorMetricDataSelector)),
map(([, selectedColorMetricData]) => setColorRange({ value: calculateInitialColorRange(selectedColorMetricData) }))
this.actions$.pipe(
ofType(...fileActions),
switchMap(() => this.store.select(selectedColorMetricDataSelector).pipe(skip(1), take(1))),
map(selectedColorMetricData => setColorRange({ value: calculateInitialColorRange(selectedColorMetricData) }))
)
)

// todo { from: null, to: null } := reset
}

0 comments on commit 4554f17

Please sign in to comment.