File

projects/netgrif-components-core/src/lib/task/services/selected-case.service.ts

Description

Holds information about the currently selected Case.

Services that handle various task operations, can use this service to take into consideration changes in frontend data in between backend call and backend response.

This service is used by Tree Case View's TreeTaskContentService.

Index

Properties
Methods
Accessors

Constructor

constructor()

Methods

ngOnDestroy
ngOnDestroy()
Returns : void

Properties

Protected _selectedCase$
Type : BehaviorSubject<Case>

Stores the currently selected Case.

The initial value is undefined.

Beware that setting new values doesn't make copies of the provided Case object, so it is possible that any subscriber could modify the shared object. Subscribed library services don't modify the provided Case, only the owner (TreeTaskContentService) of the Case object performs modifications of it.

Accessors

selectedCase$
getselectedCase$()
selectedCase
getselectedCase()
Returns : Case
setselectedCase(selectedCase: Case)
Parameters :
Name Type Optional Description
selectedCase Case No

the new value, that is emitted into the underlying stream

Returns : void
import {Injectable, OnDestroy} from '@angular/core';
import {Case} from '../../resources/interface/case';
import {BehaviorSubject, Observable} from 'rxjs';

/**
 * Holds information about the currently selected {@link Case}.
 *
 * Services that handle various task operations, can use this service to take into consideration changes in frontend data in
 * between backend call and backend response.
 *
 * This service is used by Tree Case View's {@link TreeTaskContentService}.
 */
@Injectable()
export class SelectedCaseService implements OnDestroy {

    /**
     * Stores the currently selected {@link Case}.
     *
     * The initial value is `undefined`.
     *
     * Beware that setting new values doesn't make copies of the provided {@link Case} object,
     * so it is possible that any subscriber could modify the shared object.
     * Subscribed library services don't modify the provided {@link Case}, only the owner ({@link TreeTaskContentService})
     * of the {@link Case} object performs modifications of it.
     */
    protected _selectedCase$: BehaviorSubject<Case>;

    constructor() {
        this._selectedCase$ = new BehaviorSubject<Case>(undefined);
    }

    ngOnDestroy(): void {
        this._selectedCase$.complete();
    }

    public get selectedCase$(): Observable<Case> {
        return this._selectedCase$.asObservable();
    }

    /**
     * @param selectedCase the new value, that is emitted into the underlying stream
     */
    public set selectedCase(selectedCase: Case) {
        this._selectedCase$.next(selectedCase);
    }

    /**
     * @returns the current value of the underlying stream
     */
    public get selectedCase(): Case {
        return this._selectedCase$.getValue();
    }
}

result-matching ""

    No results matching ""