[WIP] Example todo union type embeddable #64131
Closed
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.
Summary
This is a quick & dirty example of using a union type and type guards to allow an embeddable to work seamlessly with either value or reference types without sacrificing typing.
#62698 is a similar (better) example of an embeddable that works with either reference of value, but it uses optional parameters for attributes and the savedObjectId. This PR instead uses a union type e.g.
export type TodoComboInput = TodoComboValInput | TodoComboRefInput;
to ensure that the input is either by value or by reference, with nothing in between.Pros of this approach
2: Embeddables can define their own loading states
3: Helps to decouple embeddables from savedObjects
Adding a new embeddable of type "Todo (by reference or value)" using the add panel option in the dynamically adding children example will randomly create an instance of the embeddable by value or by reference.
For maintainers