question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Monomorphic signature for `patch`

See original GitHub issue

If 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:open
  • Created 7 years ago
  • Reactions:3
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
acstllcommented, Feb 9, 2017

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:

patch(emptNodeAt(elm), vnode);
patch(toVNode(elm), vnode);

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.
3reactions
paldepindcommented, Feb 8, 2017

@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?

function patch(oldVnode: ElementVNode | Element, vnode: VNode): ElementVNode

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 add toVNode then it will be very transparent to users whether or not Snabbdom attempts to patch into the existing dom.

patch(emptNodeAt(elm), vnode); // Obviously does not respect any existing children in `elm`
patch(toVNode(elm), vnode); // Does base patches on the existing structure

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found