Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Example todo union type embeddable #64131

Closed

Conversation

ThomThomson
Copy link
Contributor

@ThomThomson ThomThomson commented Apr 21, 2020

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

  1. There is only one embeddable to maintain
    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.

Screen Shot 2020-04-21 at 6 34 33 PM

For maintainers

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@ThomThomson
Copy link
Contributor Author

Closing in favor of #68719

@ThomThomson ThomThomson closed this Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants