Skip to content

[WIP] Example todo union type embeddable#64131

Closed
ThomThomson wants to merge 5 commits intoelastic:masterfrom
ThomThomson:example/todoUnionTypeEmbeddable
Closed

[WIP] Example todo union type embeddable#64131
ThomThomson wants to merge 5 commits intoelastic:masterfrom
ThomThomson:example/todoUnionTypeEmbeddable

Conversation

@ThomThomson
Copy link
Copy Markdown
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
Copy Markdown
Contributor

💚 Build Succeeded

History

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

@ThomThomson
Copy link
Copy Markdown
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