All files / app/codeCharta/state/effects/updateFileSettings updateFileSettings.effect.ts

100% Statements 26/26
100% Branches 0/0
100% Functions 5/5
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 481x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x     1x   1x 1x     1x 1x   2x 2x 2x 3x 2x 3x     2x                              
import { Injectable } from "@angular/core"
import { createEffect } from "@ngrx/effects"
import { setState } from "../../store/state.actions"
import { CcState } from "../../../codeCharta.model"
import { map } from "rxjs"
import { getVisibleFiles, isPartialState } from "../../../model/files/files.helper"
import { visibleFileStatesSelector } from "../../selectors/visibleFileStates/visibleFileStates.selector"
import { getMergedEdges } from "./utils/edges.merger"
import { getMergedMarkedPackages } from "./utils/markedPackages.merger"
import { getMergedBlacklist } from "./utils/blacklist.merger"
import { getMergedAttributeTypes } from "./utils/attributeTypes.merger"
import { getMergedAttributeDescriptors } from "./utils/attributeDescriptors.merger"
import { State, Store } from "@ngrx/store"
 
@Injectable()
export class UpdateFileSettingsEffect {
    constructor(
        private store: Store<CcState>,
        private state: State<CcState>
    ) {}
 
    updateFileSettings$ = createEffect(() =>
        this.store.select(visibleFileStatesSelector).pipe(
            map(() => {
                const state = this.state.getValue()
                const visibleFiles = getVisibleFiles(state.files)
                const withUpdatedPath = isPartialState(state.files)
                const allAttributeTypes = visibleFileStatesSelector(state).map(({ file }) => file.settings.fileSettings.attributeTypes)
                const allAttributeDescriptors = visibleFileStatesSelector(state).map(
                    ({ file }) => file.settings.fileSettings.attributeDescriptors
                )
 
                return setState({
                    value: {
                        fileSettings: {
                            edges: getMergedEdges(visibleFiles, withUpdatedPath),
                            markedPackages: getMergedMarkedPackages(visibleFiles, withUpdatedPath),
                            blacklist: getMergedBlacklist(visibleFiles, withUpdatedPath),
                            attributeTypes: getMergedAttributeTypes(allAttributeTypes),
                            attributeDescriptors: getMergedAttributeDescriptors(allAttributeDescriptors)
                        }
                    }
                })
            })
        )
    )
}