Coder Social home page Coder Social logo

react-demo's People

Watchers

 avatar  avatar

react-demo's Issues

react分享

react

        A JavaScript library for building user interfaces
  1. 虚拟DOM层:描述逻辑和结构:
  • 组件类型:type为类或者函数,产生组件实例
  • 元素类型:type为标签名,生成DOM节点
  1. 内部组件层: setState,ReactDom.render,forceUpdate,负责组件的更新
  2. 底层渲染层: 不同的显示介质有不同的渲染方法

JSX

class Hello extends React.Component {
 render() {
    return (
       <div>
           Hello {this.props.name}
       </div>
    );
  }
}
const Hello = (props) => <div>Hello{props.name}</div>
return React.createElement('div', {className: 'shopping-list'},
    React.createElement('h1', /* ... h1 children ... */),
    React.createElement('ul', /* ... ul children ... */)
);

组件挂载

事件系统

  1. 事件注册
<Component onClick={this.handleClick}/>
target.addEventListener(type, listener[, options]); 
target.attachEvent(eventNameWithOn, callback)

事件系统

  1. 事件储存
EventPluginHub    
  1. 事件分发
  2. 事件处理

事务

<pre>
 *                       wrappers (injected at creation time)
 *                                      +        +
 *                                      |        |
 *                    +-----------------|--------|--------------+
 *                    |                 v        |              |
 *                    |      +---------------+   |              |
 *                    |   +--|    wrapper1   |---|----+         |
 *                    |   |  +---------------+   v    |         |
 *                    |   |          +-------------+  |         |
 *                    |   |     +----|   wrapper2  |--------+   |
 *                    |   |     |    +-------------+  |     |   |
 *                    |   |     |                     |     |   |
 *                    |   v     v                     v     v   | wrapper
 *                    | +---+ +---+   +---------+   +---+ +---+ | invariants
 * perform(anyMethod) | |   | |   |   |         |   |   | |   | | maintained
 * +----------------->|-|---|-|---|-->|anyMethod|---|---|-|---|-|-------->
 *                    | |   | |   |   |         |   |   | |   | |
 *                    | |   | |   |   |         |   |   | |   | |
 *                    | |   | |   |   |         |   |   | |   | |
 *                    | +---+ +---+   +---------+   +---+ +---+ |
 *                    |  initialize                    close    |
 *                    +-----------------------------------------+
 * </pre>

####批更新

虚拟dom

html:

<ul id='list'>
  <li class='item'>Item 1</li>
  <li class='item'>Item 2</li>
  <li class='item'>Item 3</li>
</ul>

DOM对象

var element = {
    tagName: 'ul', // 节点标签名
    props: { // DOM的属性,用一个对象存储键值对
        id: 'list'
    },
    children: [ // 该节点的子节点
         { tagName: 'li', props: {class: 'item'}, children: ["Item 1"] },
         { tagName: 'li', props: {class: 'item'}, children: ["Item 2"] },
         { tagName: 'li', props: {class: 'item'}, children: ["Item 3"] },
     ]
}

diff

深度优先,层级对比:

Fiber

// 一个Fiber对象作用于一个组件
export type Fiber = {|  
// 标记fiber类型tag.  
    ag: TypeOfWork,  
// fiber对应的function/class/module类型组件名.  
   type: any,  
// fiber所在组件树的根组件FiberRoot对象  
   stateNode: any,  
// 返回当前fiber所在fiber树的父级fiber实例  
   return: Fiber | null,  
// fiber树结构相关链接  
   child: Fiber | null,  sibling: Fiber | null,  index: number,  
   ...
|};

异步渲染

将虚拟DOM转换为Fiber节点,首先它规定一个时间段内,然后在这个时间段能转换多少个FiberNode,就更新多少个。可以中断DOM的渲染,去渲染优先级更高的DOM树。

  1. requestAnimationFrame
  2. requestIdleCallback
  3. web worker
  4. IntersectionObserver

新生命周期

前端分享

前端分享

不是前端入门,因为可能没用门,但确实有坎
.

HTML

结构层:不是编程语言,只是标记语言

CSS

表现层:样式表,扩展有less、sass、scss

JS

行为层

JS

学习路线

包管理器

npm或者yarn: 管理第三方库

构建工具

  • 代码校验工具(linter): ESLint、JSLint、JSHint和JSCS。目前ESLint是最受欢迎的
  • 任务管理工具(task runner):npm script、gulp、Grunt等
  • 打包工具(bundlers):Webpack、Rollup、Browserify

now

  1. create-react-app (typescript)
  2. components:组件
  3. router: 路由
  4. redux (hooks only for react16.7.0-alpha): 状态
  5. axios: 请求
  6. webpack: 构建
  • es6 + babel => es5
  • sass + sass-loader => css
  • optimization.splitChunks + optimization.runtimeChunk + MiniCssExtractPlugin + UglifyJsPlugin => bundle.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.