UNPKG

@studiohyperdrive/ngx-utils

Version:

A series of abstracts, utils, pipes and services for Angular applications.

87 lines (86 loc) 2.81 kB
import { Observable } from 'rxjs'; import { NgxWindowService } from '@studiohyperdrive/ngx-core'; import { NgxStorage, NgxStorageEvent } from '../../types'; import * as i0 from "@angular/core"; /** * A service that provides a SSR-proof Observable based approach to the session- and localStorage. */ export declare class NgxStorageService { private readonly windowService; /** * A record to hold the properties in the sessionStorage */ private readonly sessionStorageRecord; /** * A record to hold the properties in the localStorage */ private readonly localStorageRecord; /** * A subject to hold the events of the storage */ private readonly storageEventSubject; /** * An observable that emits whenever the session- or the localStorage was updated */ readonly storageEvents$: Observable<NgxStorageEvent>; constructor(windowService: NgxWindowService); /** * A localStorage implementation using observables */ get localStorage(): NgxStorage; /** * A sessionStorage implementation using observables */ get sessionStorage(): NgxStorage; private getItem; /** * Returns an observable version of the storage value * * @param key - The key of the storage value * @param record - The storage record */ private getItemObservable; /** * Sets an item in the storage * * @param key - The key of the item * @param item - The item in the storage * @param storage - The storage in which we want to save the item * @param record - The corresponding storage record */ private setItem; /** * Remove an item from the storage and emit a remove event * * @param key - The key of the item * @param storage - The storage we wish to remove the item from * @param record - The record with the subject * @param type - The type of storage */ private removeItem; /** * Clears the storage, completes all subjects and emits a clear event * * @param storage - The storage we wish to clear * @param record - The record with the subjects * @param type - The type of storage */ private clearStorage; /** * Grabs the existing storage and updates the record * * @private * @param {Storage} storage - The current state of the storage * @param {NgxStorageRecord} record * @memberof NgxStorageService */ private setupStorage; /** * Parses a string value from the storage to an actual value * * @param value - The provided string value */ private parseValue; static ɵfac: i0.ɵɵFactoryDeclaration<NgxStorageService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<NgxStorageService>; }