[2.x] Add toSnapshot
early return
#1017
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes objects need native toString() and toArray() methods that are different from what you want to snapshot.
This adds an explicit toSnapshot() method that will be called first (when set) allowing for better snapshot values than the generic methods offer.
What:
Description:
I have a number of objects in my project that already contain
toString()
andtoArray()
methods for different reasons than snapshotting. For example a user object that may downcast to a string by rendering the full name or to an array by returning the raw DB attributes.But for snapshotting I want a mixture of both. I want the attributes with some computed fields and even some hidden fields. I'd like to include a user's "token" field in the snapshot, even though it's hidden from API responses so I can have confidence that the token logic isn't changing.
This adds an explicit
->toSnapshot()
method call above the more abstract methods allowing consumers to customize exactly what data is snapshotted.