feat: init preact-css, ref: https://github.com/preactjs/preact/issues/1898
This commit is contained in:
parent
cd867140d3
commit
10caee7380
|
@ -1,11 +1,13 @@
|
|||
import { render, h } from 'preact'
|
||||
import './preact-css'
|
||||
|
||||
|
||||
function Counter() {
|
||||
|
||||
|
||||
return (
|
||||
|
||||
<div>Hello Preact X</div>
|
||||
|
||||
<div>Hello Preact X</div>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import { options } from 'preact'
|
||||
|
||||
|
||||
let componentNode;
|
||||
|
||||
// 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) {
|
||||
// component is the component instance
|
||||
//component.css;
|
||||
component._styleId = 'abcef';
|
||||
// example: assign component's unique CSS ID:
|
||||
(vnode.props || (vnode.props = {}))[component._styleId] = '';
|
||||
}
|
||||
if (old) old(vnode);
|
||||
};
|
||||
|
Loading…
Reference in New Issue