patrick-steele-idem / morphdom

Fast and lightweight DOM diffing/patching (no virtual DOM needed)
MIT License
3.18k stars 127 forks source link

Allow to provide custom morphAttrs function #225

Open rosostolato opened 2 years ago

rosostolato commented 2 years ago

I'm setting some metadata as attributes on my elements and I don't want it to be rendered in the template. So the idea is to use a custom morphAttrs function to filter out undesired attributes on the check.

I believe it's easy to update, we just need to export morphAttrs and morphdomFactory on the index.js file.

-- Edit --

Or maybe we can only provide a callback function to filter the attributes of toNode. I just cloned the repo and changed this line in the morphAttrs function and it's working as I wanted.

export default function morphAttrs(fromNode, toNode) {
  var toNodeAttrs = Array.from(toNode.attributes).filter(
    attr => !attr.name.includes('on:') && attr.name !== 'key' // filter out my metadata
  )
  var attr
  ...