File

src/modules/generic-search/classes/abstract-form-component.ts

Description

Abstract class defining the source model to bind to form components in Stark (i.e. AbstractStarkSearchComponent) as well as methods to manipulate it.

Index

Properties
Methods

Constructor

Protected constructor(logger: StarkLoggingService)

Class constructor

Parameters :
Name Type Optional Description
logger StarkLoggingService No
  • The StarkLoggingService instance of the application.

Methods

Protected isDirty
isDirty()

Check whether the working copy is exactly the same as the original copy. Performs a deep comparison between the two objects to determine if they are equivalent.

Returns : boolean
Protected reset
reset()

Revert the form's working copy back to the original copy (a deep clone copy)

Returns : void
Protected setOriginalCopy
setOriginalCopy(originalCopy: CriteriaType)

Set the form's original copy to the object passed as parameter (a deep cloned copy).

Default: {} (empty object)

Parameters :
Name Type Optional Default value Description
originalCopy CriteriaType No <any>{}
  • The object to be set as the form's original copy
Returns : void

Properties

Public logger
Type : StarkLoggingService
- The `StarkLoggingService` instance of the application.
Public originalCopy
Type : CriteriaType

The form's original copy (the initial model when the form is pristine)

Public workingCopy
Type : CriteriaType

The form's working copy (the current model with the latest changes)

import { StarkLoggingService } from "@nationalbankbelgium/stark-core";
import cloneDeep from "lodash-es/cloneDeep";
import isEqual from "lodash-es/isEqual";
import { Directive } from "@angular/core";

/**
 * Abstract class defining the source model to bind to form components in Stark (i.e. {@link AbstractStarkSearchComponent})
 * as well as methods to manipulate it.
 */
@Directive({})
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export abstract class AbstractStarkFormComponent<CriteriaType> {
	/**
	 * The form's original copy (the initial model when the form is pristine)
	 */
	public originalCopy!: CriteriaType;

	/**
	 * The form's working copy (the current model with the latest changes)
	 */
	public workingCopy!: CriteriaType;

	/**
	 * Class constructor
	 * @param logger - The `StarkLoggingService` instance of the application.
	 */
	protected constructor(public logger: StarkLoggingService) {}

	/**
	 * Set the form's original copy to the object passed as parameter (a deep cloned copy).
	 *
	 * Default: `{}` (empty object)
	 * @param originalCopy - The object to be set as the form's original copy
	 */
	protected setOriginalCopy(originalCopy: CriteriaType = <any>{}): void {
		this.originalCopy = originalCopy;
		this.workingCopy = cloneDeep(this.originalCopy);
	}

	/**
	 * Revert the form's working copy back to the original copy (a deep clone copy)
	 */
	protected reset(): void {
		this.workingCopy = cloneDeep(this.originalCopy);
	}

	/**
	 * Check whether the working copy is exactly the same as the original copy.
	 * Performs a deep comparison between the two objects to determine if they are equivalent.
	 */
	protected isDirty(): boolean {
		return !isEqual(this.workingCopy, this.originalCopy);
	}
}

results matching ""

    No results matching ""