这个仓库的目的是帮助自己理解react的内部运行原理。
目前包含下面几部分:
这个项目是手写react的核心功能,包含:
- vdom
- render
- patch
- Component
详见这里
来自这篇文章
- 在React中,
setState
函数会把有参数或状态改变的组件标记为dirty
,并推入一个专门的集合中:
//ReactUpdates.js - enqueueUpdate(component) function
dirtyComponents.push(component);
- 接下来是更新vdom,使用比较算法做调整,更新dom
Render is where the Virtual DOM gets re-build and the diffing happends
理解有困难,弃。
来自这篇文章
Babel的设置
Option 1:
//.babelrc
{ "plugins": [
["transform-react-jsx", { "pragma": "h" }]
]
}
Option 2:
//Add the below comment as the 1st line in every JSX file
/** @jsx h */
这几行代码解释了/** @jsx createElement */
。
默认Babel使用React.createElement
来转换JSX,上面这两种方式都是用来改变默认函数的。
h VNode render buildComponentFromVNode
这个要看下。
When our app loads for the first time, the library ends up creating a VNode with children and attributes for the main FilteredList component. Note that this doesn’t create VNode for sub-components (that’s a different loop).
这里的sub-components
指的是谁...明白了!指的的是自定义组件,此处不会对这类sub-components
进行渲染。