UNPKG

@cycle/dom

Version:

The standard DOM Driver for Cycle.js, based on Snabbdom

66 lines 2.07 kB
function isValidNode(obj) { var ELEM_TYPE = 1; var FRAG_TYPE = 11; return typeof HTMLElement === 'object' ? obj instanceof HTMLElement || obj instanceof DocumentFragment : obj && typeof obj === 'object' && obj !== null && (obj.nodeType === ELEM_TYPE || obj.nodeType === FRAG_TYPE) && typeof obj.nodeName === 'string'; } export function isClassOrId(str) { return str.length > 1 && (str[0] === '.' || str[0] === '#'); } export function isDocFrag(el) { return el.nodeType === 11; } export function checkValidContainer(container) { if (typeof container !== 'string' && !isValidNode(container)) { throw new Error('Given container is not a DOM element neither a selector string.'); } } export function getValidNode(selectors) { var domElement = typeof selectors === 'string' ? document.querySelector(selectors) : selectors; if (typeof selectors === 'string' && domElement === null) { throw new Error("Cannot render into unknown element `" + selectors + "`"); } return domElement; } export function getSelectors(namespace) { var res = ''; for (var i = namespace.length - 1; i >= 0; i--) { if (namespace[i].type !== 'selector') { break; } res = namespace[i].scope + ' ' + res; } return res.trim(); } export function isEqualNamespace(a, b) { if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) { return false; } for (var i = 0; i < a.length; i++) { if (a[i].type !== b[i].type || a[i].scope !== b[i].scope) { return false; } } return true; } export function makeInsert(map) { return function (type, elm, value) { if (map.has(type)) { var innerMap = map.get(type); innerMap.set(elm, value); } else { var innerMap = new Map(); innerMap.set(elm, value); map.set(type, innerMap); } }; } //# sourceMappingURL=utils.js.map