/
githubmirror
/
preact
Обзор
Документация
Войти
/
githubmirror
/
preact
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
demo/preact.jsx
39 строк
945 B
Jiawen Geng
feat: migrate demo to vite
08 май 2023, 12:49
08 май 2023, 12:49
e4f3522
Код
Авторство
О чём код?
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; } return obj; } export function Component(props, context) { CevicheComponent.call(this, props, context); const render = this.render; this.render = function (props, state, context) { if (props.children) props.children = asArray(normalize(props.children)); return render.call(this, props, state, context); }; } Component.prototype = new CevicheComponent(); export { createElement, createElement as h, cloneElement, render };