-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[框架] React 动态/精要/生态/源码 #12
Comments
react-bits 一本关于 React 设计模式、技术与技巧的书,涵盖了常见的 React 应用开发中的设计模式、需要规避的反模式、处理 UX 变种、性能调试与样式处理等等。 注:反模式(anti-pattern)指的是在实践中明显出现但又低效或是有待优化的设计模式 |
setState React 源码剖析系列 - 解密 setState setState 可以传入一个回调,在 setSate 完成后触发 ReactComponent.prototype.setState = function(partialState, callback) |
从 ES6 到 ES5// ES6
class Timer extends React.Component {
constructor(props) {
super(props);
this.state = {secondsElapsed: 0};
}
tick() {
this.setState((prevState) => ({
secondsElapsed: prevState.secondsElapsed + 1
}));
}
componentDidMount() {
this.interval = setInterval(() => this.tick(), 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
);
}
}
ReactDOM.render(<Timer />, mountNode);
// babel ES5
"use strict";
var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor)
descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _possibleConstructorReturn(self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: { value: subClass, enumerable: false, writable: true, configurable: true }
});
if (superClass)
Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}
var Timer = function (_React$Component) {
_inherits(Timer, _React$Component);
function Timer(props) {
_classCallCheck(this, Timer);
var _this = _possibleConstructorReturn(this, (Timer.__proto__ || Object.getPrototypeOf(Timer)).call(this, props));
_this.state = { secondsElapsed: 0 };
return _this;
}
_createClass(Timer, [{
key: "tick",
value: function tick() {
this.setState(function (prevState) {
return {
secondsElapsed: prevState.secondsElapsed + 1
};
});
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
var _this2 = this;
this.interval = setInterval(function () {
return _this2.tick();
}, 1000);
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
clearInterval(this.interval);
}
}, {
key: "render",
value: function render() {
return React.createElement("div", null, "Seconds Elapsed: ", this.state.secondsElapsed);
}
}]);
return Timer;
}(React.Component);
ReactDOM.render(React.createElement(Timer, null), mountNode); 基础源码
主要是设置 ref,设置key,合成 props(children、defaultProps),返回 ReactElement 对象
返回 FiberDOMRenderer 由 ReactFiberReconciler 生成,传入 ReactFiberReconciler 的 config 将交给 ReactFiberScheduler 处理。
DOMRenderer.createContainer(container),利用根节点创建容器,createFiberRoot(container) |
React 的合成事件机制 |
Things nobody will tell you about React.js
|
react-fiber-architecture 中四篇文章 React Components, Elements, and Instances 传统面向对象的 UI 编程中,痛点是需要管理实例 在 React 中,组件元素与 DOM 元素可相互混合嵌套,定义 type,props(children、color...),React 屏蔽开发者对于底层 DOM 的操作,完全由框架本身来完成,而 type、props、children 的层层嵌套又转而用JSX 来表达,降低开发者的成本。 在 React 中,更多是做组件的声明,而不需要实例化,因为 React 已经帮你完成了。函数返回的组件没有示例 React 将一颗树转换为另一颗树的算法简化,基于以下两个前提将 O(n^3) 转换为 O(n):
diff 算法
|
virtual dom |
参考书籍:
深入react 技术栈
2017年 React 会议
https://facebook.github.io/react/community/conferences.html
从零到一的 React 学习与实践资料索引
https://zhuanlan.zhihu.com/p/26877549
The text was updated successfully, but these errors were encountered: