Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
attributes,
symbols,
applyProp,
applyAttr,
notifications,
skip,
currentElement
} from 'incremental-dom'
import { getTagName, getCustomElement } from './src/core.js';
// configure incremental-dom attributes
attributes.class = applyAttr
attributes.is = (...args) => (applyAttr(...args), applyProp(...args))
attributes[symbols.default] = applyProp
// track aspects creation
// notifications.nodesCreated = function (nodes) {
// console.log(nodes)
// }
// build vdom
html.h = function h(target, props={}, ...children) {
let use, propsArr = []
let staticProps = []
let is, tag, classes = [], id, constructor
if (typeof target === 'function') {
tag = getTagName(target)
constructor = getCustomElement(target)
// Ref handler.
ref (elem, name, value) {
elem[$ref] = value;
},
// Skip handler.
skip (elem, name, value) {
if (value) {
elem[$skip] = true;
} else {
delete elem[$skip];
}
},
// Default attribute applicator.
[symbols.default] (elem, name, value) {
const ce = customElements.get(elem.localName);
const props = ce && ce.props || {};
const prototype = ce && ce.prototype || {};
// TODO when refactoring properties to not have to workaround the old
// WebKit bug we can remove the "name in props" check below.
//
// NOTE: That the "name in elem" check won't work for polyfilled custom
// elements that set a property that isn't explicitly specified in "props"
// or "prototype" unless it is added to the element explicitly as a
// property prior to passing the prop to the vdom function. For example, if
// it were added in a lifecycle callback because it wouldn't have been
// upgraded yet.
//
// We prefer setting props, so we do this if there's a property matching
// name that was passed. However, certain props on SVG elements are
import {
applyProp,
attributes,
elementClose,
elementOpen as idomElementOpen,
skip as idomSkip,
symbols,
text
} from 'incremental-dom';
import { name as $name, ref as $ref } from '../util/symbols';
import propContext from '../util/prop-context';
import root from '../util/root';
const { customElements, HTMLElement } = root;
const applyDefault = attributes[symbols.default];
// A stack of children that corresponds to the current function helper being
// executed.
const stackChren = [];
const $skip = '__skip';
const $currentEventHandlers = '__events';
const $stackCurrentHelperProps = '__props';
// The current function helper in the stack.
let stackCurrentHelper;
// This is used for the Incremental DOM overrides to keep track of what args
// to pass the main elementOpen() function.
let overrideArgs;
skipNode,
notifications
} from 'incremental-dom'
import domdiff from 'domdiff'
import { isElement, isIterable, paramCase, SPECT_CLASS } from './util'
const _vnode = Symbol('vnode')
attributes.class = applyAttr
attributes.is = (target, name, value) => {
if (target.setAttribute) applyAttr(target, name, value)
return applyProp(target, name, value)
}
attributes[symbols.default] = applyProp
// render vdom into element
export default function html(el, ...args) {
let content
// html`<...>`
// html(...)
if (!args.length || (Array.isArray(el) && el.raw)) {
content = htm.call(h, el, ...args)
el = document.createDocumentFragment()
}
// html(el, ...)`
else {
content = args[0]
// html('.selector', ...)
if (typeof el === 'string') el = document.querySelectorAll(el)
applyProp,
applyAttr,
elementVoid,
currentPointer,
skipNode,
notifications
} from 'incremental-dom'
import { isIterable, paramCase, SPECT_CLASS } from './util'
attributes.class = applyAttr
attributes.is = (target, name, value) => {
if (target.setAttribute) applyAttr(target, name, value)
return applyProp(target, name, value)
}
attributes[symbols.default] = applyProp
notifications.nodesDeleted = function (nodes) {
nodes.forEach((node) => node[_spect] && node[_spect].dispose())
};
const _target = Symbol.for('spect.target')
const _instance = Symbol.for('spect.instance')
const _spect = Symbol.for('spect')
export default function html(...args) {
let el = this[_target] || this
// tpl string: html`<a>`
let vdom
if (args[0].raw) {</a>
function clean_global_state(old) {
notifications.nodesDeleted = old.deleted
attributes[symbols.default] = old.applyAttr
attributes.__stores = old.stores
}
import {
patch,
elementOpen,
elementClose,
text,
attributes,
symbols,
applyProp,
applyAttr
} from 'incremental-dom'
attributes.class = applyAttr
attributes.is = (...args) => (applyAttr(...args), applyProp(...args))
attributes[symbols.default] = applyProp
let html = htm.bind(h)
const aspectsCache = new WeakMap,
depsCache = new WeakMap,
destroyCache = new WeakMap,
observables = new Map,
stateCache = new WeakMap
let fxCount,
currentElement,
currentAspect
function callAspect (el, fn) {