Match-id-587601ebdfc3d3ef7e317bb42380ca4a550725bd

This commit is contained in:
* 2022-05-11 14:48:13 +08:00 committed by *
parent e343eab0f2
commit d73ab8fcb0
3 changed files with 12 additions and 7 deletions

View File

@ -5,8 +5,9 @@
import { parseAttr } from '../parser/parseAttr'; import { parseAttr } from '../parser/parseAttr';
import parseTreeRoot from '../parser/parseVNode'; import parseTreeRoot from '../parser/parseVNode';
import { VNode } from './../../../horizon/src/renderer/vnode/VNode'; import { VNode } from '../../../horizon/src/renderer/vnode/VNode';
import { FunctionComponent, ClassComponent } from './../../../horizon/src/renderer/vnode/VNodeTags'; import { FunctionComponent, ClassComponent } from '../../../horizon/src/renderer/vnode/VNodeTags';
import { helper } from '../../../horizon/src/external/devtools';
const mockComponentNames = ['Apple', 'Pear', 'Banana', 'Orange', 'Jenny', 'Kiwi', 'Coconut']; const mockComponentNames = ['Apple', 'Pear', 'Banana', 'Orange', 'Jenny', 'Kiwi', 'Coconut'];
@ -50,7 +51,7 @@ addOneThousandNode(tree);
/** /**
* mock数据转变为 VNode * mock数据转变为 VNode
* *
* @param node * @param node
* @param vNode VNode节点 * @param vNode VNode节点
*/ */
@ -78,7 +79,7 @@ function getMockVNodeTree(node: IMockTree, vNode: VNode) {
const rootVNode = MockVNode(tree.tag); const rootVNode = MockVNode(tree.tag);
getMockVNodeTree(tree, rootVNode); getMockVNodeTree(tree, rootVNode);
export const mockParsedVNodeData = parseTreeRoot(rootVNode); export const mockParsedVNodeData = parseTreeRoot(helper.travelVNodeTree, rootVNode);
const mockState = { const mockState = {
str: 'jenny', str: 'jenny',

View File

@ -17,6 +17,7 @@ function reducer(state, action) {
export default function MockFunctionComponent(props) { export default function MockFunctionComponent(props) {
const [state, dispatch] = useReducer(reducer, initialState); const [state, dispatch] = useReducer(reducer, initialState);
const [age, setAge] = useState(0); const [age, setAge] = useState(0);
const [name, setName] = useState({test: 1});
const domRef = useRef<HTMLDivElement>(); const domRef = useRef<HTMLDivElement>();
const objRef = useRef({ str: 'string' }); const objRef = useRef({ str: 'string' });
const context = useContext(MockContext); const context = useContext(MockContext);
@ -26,6 +27,7 @@ export default function MockFunctionComponent(props) {
return ( return (
<div> <div>
age: {age} age: {age}
name: {name.test}
<button onClick={() => setAge(age + 1)} >update age</button> <button onClick={() => setAge(age + 1)} >update age</button>
count: {props.count} count: {props.count}
<div ref={domRef} /> <div ref={domRef} />
@ -33,4 +35,4 @@ export default function MockFunctionComponent(props) {
<div>{context.ctx}</div> <div>{context.ctx}</div>
</div> </div>
); );
} }

View File

@ -1,4 +1,4 @@
import { render } from 'horizon'; import { render, useState } from 'horizon';
import MockClassComponent from './MockClassComponent'; import MockClassComponent from './MockClassComponent';
import MockFunctionComponent from './MockFunctionComponent'; import MockFunctionComponent from './MockFunctionComponent';
import { MockContext } from './MockContext'; import { MockContext } from './MockContext';
@ -6,11 +6,13 @@ import { MockContext } from './MockContext';
const root = document.createElement('div'); const root = document.createElement('div');
document.body.append(root); document.body.append(root);
function App() { function App() {
const [count, setCount] = useState(12);
return ( return (
<div> <div>
<button onClick={() => (setCount(count + 1))} >add count</button>
<MockContext.Provider value={{ ctx: 'I am ctx' }}> <MockContext.Provider value={{ ctx: 'I am ctx' }}>
<MockClassComponent fruit={'apple'} /> <MockClassComponent fruit={'apple'} />
<MockFunctionComponent /> <MockFunctionComponent count={count}/>
</MockContext.Provider> </MockContext.Provider>
abc abc
</div> </div>