[WIP] Example todo union type embeddable#64131
Closed
ThomThomson wants to merge 5 commits intoelastic:masterfrom
Closed
[WIP] Example todo union type embeddable#64131ThomThomson wants to merge 5 commits intoelastic:masterfrom
ThomThomson wants to merge 5 commits intoelastic:masterfrom
Conversation
… with both by reference and by value inputs without sacrificing typing
…nionTypeEmbeddable
Contributor
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
7 tasks
Contributor
Author
|
Closing in favor of #68719 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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