internalCopy method
- covariant UnorderedListItemComponentViewModel viewModel
Given a subclassInstance of TextComponentViewModel, copies all base-level text
properties from this TextComponentViewModel into the given subclassInstance.
Every view model must implement the ability to copy. Without this method, every subclass would have to repeat the same mapping of properties between the original view model to the copied view model. Originally, that's what Super Editor did, but it became very tedious, and it was error prone because it was easy to accidentally miss a property.
From a copy perspective, mutability of view models is important because TextComponentViewModel doesn't have a constructor, and because every subclass has different constructors. Therefore, the one approach to consistently support copy is to mutate the parts of a view model that a given class knows about, such as what you see in the implementation of this method.
Implementation
@override
UnorderedListItemComponentViewModel internalCopy(UnorderedListItemComponentViewModel viewModel) {
final copy = super.internalCopy(viewModel) as UnorderedListItemComponentViewModel;
copy
..indent = indent
..dotStyle = dotStyle.copyWith();
return copy;
}