You can use DirtyList in OCL to inspect the objects with pending changes in the current ViewModel save scope; this is useful when you need to review, count, or discard work before calling selfVM.Save.
What DirtyList returns
selfVM.DirtyList returns the collection of changed objects that selfVM.Save would save.
An object is included after it has pending changes, for example when you:
- Change an attribute value.
- Add or remove a role connection.
- Create a new object.
For example, if an action changes a customer's name and adds a new order, both changed objects are available through selfVM.DirtyList until the changes are saved or discarded.
Use DirtyList
List the objects that would be saved
Use the expression below when you need the collection of changed objects in the current ViewModel:
selfVM.DirtyList
Count pending changes
Use size to determine how many objects have pending changes:
selfVM.DirtyList->size
For example, an action can use this expression to determine whether the current ViewModel has any objects waiting to be saved.
Discard all pending changes
Call DiscardChanges on the dirty collection to revert all changes made in the ViewModel:
selfVM.DirtyList->DiscardChanges
This reverts the changes represented by the current DirtyList rather than saving them. See Documentation:SelfVM.DirtyList and DiscardChanges for the authoritative behavior.
Choose the right dirty check
| Need | Use | Example |
|---|---|---|
Inspect all objects that selfVM.Save would save
|
selfVM.DirtyList
|
selfVM.DirtyList->size
|
| Check whether one object has changed since the last save | IsDirty | self.isDirty
|
| Check whether one attribute has a pending change | IsDirtyMember | SomeString.IsDirtyMember
|
Scope and save behavior
DirtyList is tied to the current ViewModel. It reports the objects that are pending in that ViewModel and that will be saved by selfVM.Save. Do not treat it as a list of every changed object in the application.
For example, use selfVM.DirtyList when an action needs to inspect the current user's unsaved edits before saving or reverting them. Use self.isDirty instead when the action only needs to test the object represented by self.
