DirtyState
Class: DirtyState
Defined in: packages/utils/src/dirty.ts:15
Tracks which fields of an object have been modified since the last clear.
Stores the original value of each changed field so that setting a field back to its original value automatically removes it from the dirty set.
Constructors
Constructor
new DirtyState(
parent,fields?):DirtyState
Defined in: packages/utils/src/dirty.ts:22
Parameters
parent
any
the object being tracked
fields?
Set<string> = ...
Initial set of dirty field names
Returns
DirtyState
Methods
add()
add(
field,originalValue?,value?):void
Defined in: packages/utils/src/dirty.ts:56
Records a field change. If the new value matches the original value the field had before any modification, the field is removed from the dirty set (i.e. considered clean again).
Parameters
field
string
Name of the property that changed
originalValue?
any
Value of the property before this assignment
value?
any
New value being assigned If originalValue is undefined and value is undefined, we force the field to be considered dirty
Returns
void
clear()
clear():
void
Defined in: packages/utils/src/dirty.ts:41
Resets the dirty state, marking all fields as clean.
Returns
void
getPatch()
getPatch():
Record<string,any>
Defined in: packages/utils/src/dirty.ts:97
Get a patch object containing the original values of all dirty fields. This can be used to revert changes or send only modified fields to a backend.
Returns
Record<string, any>
A record of field names to their original values
getProperties()
getProperties():
string[]
Defined in: packages/utils/src/dirty.ts:88
Returns the names of all currently dirty fields.
Returns
string[]
array of dirty field names
has()
has(
field):boolean
Defined in: packages/utils/src/dirty.ts:79
Checks if a specific field is currently dirty
Parameters
field
string
the field name to check
Returns
boolean
true if the field is dirty
valueOf()
valueOf():
boolean
Defined in: packages/utils/src/dirty.ts:34
Returns true when at least one field is dirty.
Allows if (dirtyState) boolean coercion.
Returns
boolean
true if any fields are dirty