JSPM

@semibran/patch

2.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q15415F
  • License MIT

efficient patch operation for matching HTML elements to vnodes

Package Exports

  • @semibran/patch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@semibran/patch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

patch

efficient patch operation for matching HTML elements to vnodes

let element = document.createElement('h1')
element.innerText = 'hello world'
document.body.appendChild(element)

patch(element, {
  tag: 'h1',
  props: {},
  content: ['goodbye world']
})

usage

npm badge

result = patch(elem, node)

Alters elem to match node and returns result.

  • elem: the HTMLElement to be patched
  • node: a virtual node of the structure { tag, props, content } against which elem is compared

Note that if elem.tagName and node.tag are different, result will be a brand new element. This behavior is caused by a property of the HTMLElement interface that prevents an element's tag from being changed once it is created. If there is a chance of the tag name being altered during runtime, make sure to update your element reference to match result; otherwise, any changes you make to the new element will not be reflected onscreen.