Git Product home page Git Product logo

Comments (7)

DylanPiercey avatar DylanPiercey commented on September 22, 2024

@patrick-steele-idem I created a https://github.com/DylanPiercey/vdo to create a lightweight (html focused) vdom. Would this change make something like that work? What exactly needs to be done to achieve this?

from morphdom.

patrick-steele-idem avatar patrick-steele-idem commented on September 22, 2024

Hey @DylanPiercey, do the virtual DOM nodes created by vdo implement the following properties and methods associated with real DOM nodes?:

  • node.firstChild
  • node.tagName
  • node.nextSibling
  • node.attributes
  • node.nodeType
  • node.nodeValue

If so, then the diffing/patching would work even if the target DOM tree is a tree of virtual vdo nodes. The only thing that would need to change to morphdom is that the virtual DOM nodes would need to be upgraded to real DOM nodes if they need to be moved into the DOM.

from morphdom.

DylanPiercey avatar DylanPiercey commented on September 22, 2024

@patrick-steele-idem currently the vnodes are a bit different but I'd probably switch if things go well with this library.

Do you think that the vnodes should implement something like a #toDOM which would be called by morphdom or are you thinking that morphdom will somehow detect that a node is virtual and manually convert it to a real node?

from morphdom.

AutoSponge avatar AutoSponge commented on September 22, 2024

@DylanPiercey I looked at the virtual-dom docs again.

They have a createElement function which converts vdom to dom. We could have an option property hold the function that upgrades a vdom tree. If we did that for the other methods mentioned above (similar to the hooks virtual-dom uses) we don't need the vdom tree to implement that interface.

A plugin author could create all of the methods needed and mix them in with options passed to morphdom.

Morphdom internal pseudo code:

if !node#nodeType
then options.nodeType(node)
...

from morphdom.

yoshuawuyts avatar yoshuawuyts commented on September 22, 2024

yo-yo and choo make use of a virtual DOM through shama/bel which translates html template strings into raynos/global calls, which creates virtual elements using raynos/min-document and delegating to the related dom-* files in the repo.

In production we use the yo-yoify transform which changes all element creation calls from yo-yo, bel and choo into document.createElement and equivalents. Benchmarks have shown that using yo-yoify would speed up the tested TodoMVC application by 2x, but this was supposedly mostly due to removing the template string creation step.

My concern with morphdom adding virtual dom node creation is that the scope of the package would creep beyond just being good at diffing. I feel like having wrappers such as yo-yo available is great, because they add opinions on top of a core we can share.

@patrick-steele-idem I'm not sure what you've got in mind for this, but I'd be keen to hear. I figured I'd go ahead and explain what we've been building on top of morphdom so far, because it sounds like it's quite similar to what is being proposed in this thread. Thanks! ✨

from morphdom.

patrick-steele-idem avatar patrick-steele-idem commented on September 22, 2024

@yoshuawuyts Rest assured that morphdom will not become any more complex when introducing support for diffing real DOM nodes with virtual DOM nodes 😄

The plan is to require that the virtual DOM nodes be API compatible with real DOM nodes for the minimal subset of API methods and properties required by morphdom. The only extra code that is required to support diffing a real DOM node with a virtual DOM node is that a virtual DOM node must be upgraded to a real DOM node before inserting it into the DOM.

I have just published a virtual DOM implementation that meets morpdom's requirements: marko-vdom

You could use marko-vdom with yo-yo/bel/choo if you would like. The only reason marko-vdom has marko in its name is that marko-vdom was designed as a compilation target for marko (the API is not user friendly, but it is super fast and great for use with compilers/transpilers). marko-vdom has 100% code coverage and we will of course follow semantic versioning.

I will be pushing some new code for morphdom very soon (probably today) and you will see that the changes to support DOM <-> VDOM diffing/patching are minimal.

from morphdom.

patrick-steele-idem avatar patrick-steele-idem commented on September 22, 2024

Fixed by PR #83

from morphdom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.