Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parseElementNode(element) {
let { state } = this;
const markups = this._markupsFromElement(element);
if (markups.length && state.text.length && state.section.isMarkerable) {
this._createMarker();
}
state.markups.push(...markups);
forEach(element.childNodes, (node) => {
this.parseNode(node);
});
if (markups.length && state.text.length && state.section.isMarkerable) {
// create the marker started for this node
this._createMarker();
}
// pop the current markups from the stack
state.markups.splice(-markups.length, markups.length);
}
parseElementNode(element) {
let { state } = this;
const markups = this._markupsFromElement(element);
if (markups.length && state.text.length && state.section.isMarkerable) {
this._createMarker();
}
state.markups.push(...markups);
forEach(element.childNodes, (node) => {
this.parseNode(node);
});
if (markups.length && state.text.length && state.section.isMarkerable) {
// create the marker started for this node
this._createMarker();
}
// pop the current markups from the stack
state.markups.splice(-markups.length, markups.length);
}
// section-creating elements
if (this.state.section.isMarkerable && !this.state.text && this.state.section.markers.length === 0) {
this.state.section = null;
} else {
this._closeCurrentSection();
}
this._updateStateFromElement(node);
}
if (this.state.section.isListSection) {
// ensure the list section is closed and added to the sections list.
// _closeCurrentSection handles pushing list items onto the list section
this._closeCurrentSection();
forEach(node.childNodes, (node) => {
this.parseNode(node);
});
return;
}
}
switch (node.nodeType) {
case NODE_TYPES.TEXT:
this.parseTextNode(node);
break;
case NODE_TYPES.ELEMENT:
this.parseElementNode(node);
break;
}
}
function walkDOMUntil(topNode, conditionFn=() => {}) {
if (!topNode) { throw new Error('Cannot call walkDOMUntil without a node'); }
let stack = [topNode];
let currentElement;
while (stack.length) {
currentElement = stack.pop();
if (conditionFn(currentElement)) {
return currentElement;
}
forEach(currentElement.childNodes, el => stack.push(el));
}
}
_trigger(context, type, event) {
forEach(
filter(this._listeners, ([_context, _type]) => {
return _context === context && _type === type;
}),
([context,, listener]) => {
listener.call(context, event);
}
);
}
function validateCards(cards=[]) {
forEach(cards, card => {
assert(
`Card "${card.name}" must define type "dom", has: "${card.type}"`,
card.type === 'dom'
);
assert(
`Card "${card.name}" must define \`render\` method`,
!!card.render
);
});
return cards;
}
function validateAtoms(atoms=[]) {
forEach(atoms, atom => {
assert(
`Atom "${atom.name}" must define type "dom", has: "${atom.type}"`,
atom.type === 'dom'
);
assert(
`Atom "${atom.name}" must define \`render\` method`,
!!atom.render
);
});
return atoms;
}