Skip to content

Instantly share code, notes, and snippets.

@nxta
nxta / vdom.js
Created January 8, 2020 22:41
Helper function for Flarum to traverse a Mithril Virtual DOM using basic CSS selector syntax
/**
* // Desired usage:
* import vdom from 'flarum/helpers/vdom';
* import {find, vdom} from 'flarum/helpers/vdom';
*
* // Supports tagname, class and id selectors
* vdom('.container ul#logo li.item.item-one a') // Returns array of vnodes
* find('.username') // Returns array of objects containing the vnode and more information {vnode, parent, index}
*
* // Example:
/**
* Helpers for Flarum
*
* Allows you to do the following
* setDeep(vdom, 'attrs.style.borderColor', '#f00')
* mergeDeep(this.props, {className: 'Class', params: {q: null}})
*/
// https://stackoverflow.com/questions/27936772/how-to-deep-merge-instead-of-shallow-merge
/**