Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// store a reference to the "current component" vnode
let oldDiff = options._diff || options.__b
options._diff = options.__b = vnode => {
componentNode = vnode
if (oldDiff) oldDiff(vnode)
}
// reset component reference at end of diffing:
let oldDiffed = options.diffed
options.diffed = vnode => {
if (componentNode === vnode) componentNode = null
if (oldDiffed) oldDiffed(vnode)
}
// our vnode hook looks up the associated component
let old = options.vnode
options.vnode = vnode => {
const component = componentNode && (componentNode._component || componentNode.__c)
if (component) {
if(component.constructor.css){
const styleId = getStyleId(component.constructor)
appendStyle(component.constructor.css, styleId);
(vnode.props || (vnode.props = {}))[styleId] = ''
}
}
if (old) old(vnode)
}
if (!roots.has(root)) roots.add(root);
});
onCommitUnmount = catchErrors(vnode => {
hook.onCommitFiberUnmount(rid, vnode);
});
})();
// Store (possible) previous hooks so that we don't overwrite them
let prevVNodeHook = options.vnode;
let prevCommitRoot = options._commit;
let prevBeforeUnmount = options.unmount;
let prevBeforeDiff = options._diff;
let prevAfterDiff = options.diffed;
options.vnode = vnode => {
// Tiny performance improvement by initializing fields as doubles
// from the start. `performance.now()` will always return a double.
// See https://github.com/facebook/react/issues/14365
// and https://slidr.io/bmeurer/javascript-engine-fundamentals-the-good-the-bad-and-the-ugly
vnode.startTime = NaN;
vnode.endTime = NaN;
vnode.startTime = 0;
vnode.endTime = -1;
if (prevVNodeHook) prevVNodeHook(vnode);
};
options._diff = vnode => {
vnode.startTime = now();
if (prevBeforeDiff != null) prevBeforeDiff(vnode);
};
/* istanbul ignore next */
set(v) {
this['UNSAFE_' + key] = v;
}
});
}
}
let classNameDescriptor = {
configurable: true,
get() {
return this.class;
}
};
let oldVNodeHook = options.vnode;
options.vnode = vnode => {
vnode.$$typeof = REACT_ELEMENT_TYPE;
let type = vnode.type;
let props = vnode.props;
// Apply DOM VNode compat
if (typeof type != 'function') {
// Apply defaultValue to value
if (props.defaultValue) {
if (!props.value && props.value !== 0) {
props.value = props.defaultValue;
}
delete props.defaultValue;
}
onCommitRoot = catchErrors(root => {
// Empty root
if (root.type === Fragment && root._children.length == 0) return;
let roots = hook.getFiberRoots(rid);
root = helpers.handleCommitFiberRoot(root);
if (!roots.has(root)) roots.add(root);
});
onCommitUnmount = catchErrors(vnode => {
hook.onCommitFiberUnmount(rid, vnode);
});
})();
// Store (possible) previous hooks so that we don't overwrite them
let prevVNodeHook = options.vnode;
let prevCommitRoot = options._commit;
let prevBeforeUnmount = options.unmount;
let prevBeforeDiff = options._diff;
let prevAfterDiff = options.diffed;
options.vnode = vnode => {
// Tiny performance improvement by initializing fields as doubles
// from the start. `performance.now()` will always return a double.
// See https://github.com/facebook/react/issues/14365
// and https://slidr.io/bmeurer/javascript-engine-fundamentals-the-good-the-bad-and-the-ugly
vnode.startTime = NaN;
vnode.endTime = NaN;
vnode.startTime = 0;
vnode.endTime = -1;
if (prevVNodeHook) prevVNodeHook(vnode);
function installShallowRenderHook() {
if (shallowRenderHookInstalled) {
return;
}
const prevHook = options.vnode;
options.vnode = vnode => {
if (shallowRenderActive) {
shallowRenderVNode(vnode as VNodeExtensions);
}
if (prevHook) {
prevHook(vnode);
}
};
shallowRenderHookInstalled = true;
}
import { options } from 'preact';
const classNameDescriptor = {
enumerable: false,
configurable: true,
get () {
return this.class;
},
set (value) {
this.class = value;
}
};
const old = options.vnode;
options.vnode = vnode => {
const a = vnode.attributes;
if (a != null) {
if ('className' in a) {
a.class = a.className;
}
if ('class' in a) {
Object.defineProperty(a, 'className', classNameDescriptor);
}
}
if (old != null) old(vnode);
};
if (oldDiffed) oldDiffed(vnode);
};
options._diff = vnode => {
if (isPossibleOwner(vnode)) {
renderStack.push(vnode);
}
if (oldDiff) oldDiff(vnode);
};
options._root = (vnode, parent) => {
ownerStack = [];
if (oldRoot) oldRoot(vnode, parent);
};
options.vnode = vnode => {
vnode._owner =
ownerStack.length > 0 ? ownerStack[ownerStack.length - 1] : null;
if (oldVNode) oldVNode(vnode);
};
options._render = vnode => {
if (isPossibleOwner(vnode)) {
ownerStack.push(vnode);
}
if (oldRender) oldRender(vnode);
};
}
},
set(v) {
this.attributes = v;
},
configurable: true
});
let oldEventHook = options.event;
options.event = e => {
if (oldEventHook) e = oldEventHook(e);
e.persist = Object;
e.nativeEvent = e;
return e;
};
let oldVnodeHook = options.vnode;
options.vnode = vnode => {
if (!vnode.preactCompatUpgraded) {
vnode.preactCompatUpgraded = true;
let tag = vnode.nodeName,
attrs = (vnode.attributes = vnode.attributes == null ? {} : extend({}, vnode.attributes));
if (typeof tag === 'function') {
if (tag[COMPONENT_WRAPPER_KEY] === true || (tag.prototype && 'isReactComponent' in tag.prototype)) {
if (vnode.children && String(vnode.children) === '') vnode.children = undefined;
if (vnode.children) attrs.children = vnode.children;
if (!vnode.preactCompatNormalized) {
normalizeVNode(vnode);
}
handleComponentVNode(vnode);
import { options } from 'preact';
const classNameDescriptor = {
enumerable: false,
configurable: true,
get () {
return this.class;
},
set (value) {
this.class = value;
}
};
const old = options.vnode;
options.vnode = vnode => {
const a = vnode.attributes;
if (a != null) {
if ('className' in a) {
a.class = a.className;
}
if ('class' in a) {
Object.defineProperty(a, 'className', classNameDescriptor);
}
}
if (old != null) old(vnode);
};
import {
options,
createElement,
cloneElement,
Component as CevicheComponent,
render
} from 'preact';
options.vnode = vnode => {
vnode.nodeName = vnode.type;
vnode.attributes = vnode.props;
vnode.children = vnode._children || [].concat(vnode.props.children || []);
};
function asArray(arr) {
return Array.isArray(arr) ? arr : [arr];
}
function normalize(obj) {
if (Array.isArray(obj)) {
return obj.map(normalize);
}
if ('type' in obj && !('attributes' in obj)) {
obj.attributes = obj.props;
}