Monomorphic signature for `patch`
See original GitHub issueIf and when #242 is merged there will internally be a function toVnode
that converts an element and all of it’s children to a VNode
. From a more general stance of type-safety, I think it’d be even better to have this function publicly exports and be required for the user to make use of, which in turn will allow patch to have a monomorphic type signature. For example
const element = document.querySelector('#root') as Element
const rootVNode: VNode = toVNode(element)
patch(rootVNode, h('div', {}, [ ... ])
Where patch(oldVNode: VNode, vNode: VNode): VNode
is the new type signature of patch.
If anyone agrees with me, this is a breaking change, I think the types can be greatly improved from there as well, but I’ll avoid going into that right now.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Digital Signature Page - Patch Project - Advanced Installer
Digitally sign your Windows Installer patches with Advanced Installer.
Read more >8.7. Other type system extensions - Haskell.org Downloads
The only difference between the two groups is that in the second group len_acc is given a type signature. In the former case,...
Read more >On the adaptive value of monomorphic versus dimorphic ...
Naturally flowering patches experienced severe pollination limitation, showed marked differences in reproductive success and had relatively high ...
Read more >US Patent Application for AUTOMATIC DATA PATCH GENERATION ...
To date, automatic signature generation utilizing program analysis for binary or source code have typically been Monomorphic Execution Path (MEP) signatures ...
Read more >Brugada Syndrome: A Case Report of Monomorphic Ventricular ...
Syncope occurred due to monomorphic VT with left... | Find, read and cite all the research you need on ... Brugada syndrome -...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I honestly think polymorphism in this case is a feature. But, since snabbdom is low-levelish, the less magic the better, so I like the transparency in this:
I would only suggest renaming the “empty” option to
toEmptyVNode
so you can infer both function to the same (turn an element into a vnode) but with different results:toVNode
turn DOM element into vnode.toEmptyVNode
discard children of DOM element and turn into vnode.@TylorS Good ideas! Having more precise types for vnodes would be really nice.
But I don’t see why allowing a DOM node as the first element to
patch
would hinder that? Couldn’t the type be like this?Personally, I would not have a problem with only taking a vnode as the first argument to
patch
. The simpler type is appealing. On the other hand using a DOM node directly can be convenient.One benefit I see to only allowing vnodes is that if we keep
emptyNodeAt
and addtoVNode
then it will be very transparent to users whether or not Snabbdom attempts to patch into the existing dom.The first of the above lines would behave like
patch(elm, vnode)
does now. But I like how it is more explicit about what happens.