libs/ngx-pfe/pfe-actions/reset-state/reset-state.service.ts
Properties |
|
Public resetState |
Default value : () => {...}
|
import { Injectable, inject } from '@angular/core';
import { JsonPathExpression } from '../../models/jsonpath-expression-type.model';
import { PfeStateService } from './../../services/pfe-state-service/state.service';
import { PfeResetStateActionConfig } from './reset-state.model';
@Injectable()
export class PfeResetStateService {
protected pfeStateService = inject(PfeStateService);
public resetState = async (actionConfig: PfeResetStateActionConfig): Promise<void> => {
const stateToKeepMap = new Map<JsonPathExpression, unknown>();
actionConfig.excludeFromResetExpressions?.forEach((exceptionExpression) => {
const stateValue = this.pfeStateService.getStateValueByExpression(exceptionExpression);
stateToKeepMap.set(exceptionExpression, stateValue);
});
await this.pfeStateService.resetState();
for (const [key, value] of stateToKeepMap.entries()) {
this.pfeStateService.storeValueByExpression(key, value);
}
return;
};
}