How to use the diffhtml.Internals.defaultTasks function in diffhtml

To help you get started, we’ve selected a few diffhtml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tbranyen / diffhtml / packages / diffhtml-render-to-string / index.js View on Github external
const { use, html, Internals, createTree, innerHTML } = require('diffhtml');
const { makeDOMNode } = require('quick-dom-node');
const { keys } = Object;

// Apply a transformation function against the Nodes to produce a string of
// markup.
use({ createNodeHook: vTree => makeDOMNode(vTree) });

// Use the same tasks for every run. Maybe in the future we'll allow for
// passing custom tasks.
const tasks = new Set(Internals.defaultTasks);

// Remove incompatible tasks, and replace them with serialization-compatible
// functions.
tasks.delete(Internals.tasks.reconcileTrees);
tasks.delete(Internals.tasks.syncTrees);
tasks.delete(Internals.tasks.patchNode);
tasks.delete(Internals.tasks.endAsPromise);

// Add a new reconcile trees function to ensure we are diffing against a tree
// instead of DOM Node.
tasks.add(function reconcileTrees(transaction) {
  const { domNode, markup, options } = transaction;

  // If we are in a render transaction where no markup was previously parsed
  // then reconcile trees will attempt to create a tree based on the incoming
  // markup (JSX/html/etc).