-
Notifications
You must be signed in to change notification settings - Fork 13
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
[MT-4431] Refactor - Type system #36
Conversation
As it's exactly matching the other place where we override it
Instead of defining it as a union of all possible implementations, we now declare it as the most generic Element interface (type + children) and expect all implementations to extend it. We can also now rely on the new `Element.isElementType()` helper to reduce duplication in our own type-guards code.
As there's not much need in it now, after we've inverted the types.
This is considered a temporary solution until we figure out a better way for it. In the longer run, I believe, it's worth to restructure the code so there is no dependencies or assumptions to the common Slate editor types structure. But that's not for now.
As it was duplicating `EmbedNode` interface from @prezly/slate-types
MT-4431 Refactor slate-editor repo types system
While working on MT-4421 we've came to realization that the approach we've took with defining Editor nodes types in the
Our current assumption is that the above can be fixed and improved by:
|
To make it more clear
- to check if value is `ElementNode` - to check if value is `ElementNode` of the given type - to check if value is `ElementNode` of one of the given types
Instead of relying on ambient-definition of `Element.isElement()`
Element
as the most generic shape allowing specific implementations to extend itInlineNode
type and type-guard in favour of runtime-definedEditor.isInline()
checkBlockNode
type and type-guard in favour of runtime-definedEditor.isBlock()
checkElementWithType
and its type-guard, as it's the same as the genericElement
AdditionalCustomTypes
hack and only rely on Slate's stockCustomTypes
declaration mergingCustomTypes
ambient declaration to@prezly/slate-commons
(the plan is to keep it there as a temporary solution until we refactor the code to not depend on it)EmbedElementType
definition in favour ofEmbedNode
defined in@prezly/slate-types
LinkCandidateElementType
toLinkCandidateNode
ImageCandidateElementType
toImageCandidateNode
LoaderElementType
toLoaderNode
DIVIDER_TYPE
constant