React15.6源码分析

本文深入探讨React15.6的关键概念,包括Transaction、CallbackQueue和pooledClass。详细分析了路由准备过程,如react router的BrowserRouter和Route的实现。接着阐述了状态更新的流程,从enqueueSetState到ReactUpdates的batchedUpdates。此外,还介绍了组件的快捷引导,涉及组件生命周期的各个重要阶段。
摘要由CSDN通过智能技术生成

重要概念:

Transaction:
在方法的前后加入方法

ReactDefaultBatchingStrategy.batchedUpdates 

var RESET_BATCHED_UPDATES = {
   
  initialize: emptyFunction,
  close: function () {
   
    ReactDefaultBatchingStrategy.isBatchingUpdates = false;
  }
};

var FLUSH_BATCHED_UPDATES = {
   
  initialize: emptyFunction,
  close: ReactUpdates.flushBatchedUpdates.bind(ReactUpdates)
};

ReactReconcileTransaction

var TRANSACTION_WRAPPERS = [SELECTION_RESTORATION, EVENT_SUPPRESSION, ON_DOM_READY_QUEUEING];

var ON_DOM_READY_QUEUEING = {
   
  /**
   * Initializes the internal `onDOMReady` queue.
   */
  initialize: function () {
   
    this.reactMountReady.reset();
  },

  /**
   * After DOM is flushed, invoke all registered `onDOMReady` callbacks.
   */
  close: function () {
   
    this.reactMountReady.notifyAll();
  }
};

ReactUpdatesFlushTransaction

var TRANSACTION_WRAPPERS = [NESTED_UPDATES, UPDATE_QUEUEING];

var NESTED_UPDATES = {
   
  initialize: function () {
   
    this.dirtyComponentsLength = dirtyComponents.length;
  },
  close: function () {
   
    if (this.dirtyComponentsLength !== dirtyComponents.length) {
   
      // Additional updates were enqueued by componentDidUpdate handlers or
      // similar; before our own UPDATE_QUEUEING wrapper closes, we want to run
      // these new updates so that if A's componentDidUpdate calls setState on
      // B, B will update before the callback A's updater provided when calling
      // setState.
      dirtyComponents.splice(0, this.dirtyComponentsLength);
      flushBatchedUpdates();
    } else {
   
      dirtyComponents.length = 0;
    }
  }
};

CallbackQueue
方法执行队列

this.reactMountReady
asapCallbackQueue
ReactUpdatesFlushTransaction.callbackQueue

pooledClass
对象池,将对象存入减少初始耗能

PooledClass.addPoolingTo(ReactUpdatesFlushTransaction);

路由准备

react router 判断 hash 或者 history 或者 memory

react-router-dom的BrowserRouter包

 BrowserRouter.prototype.render = function render() {
   
    return _react2.default.createElement(_Router2.default, {
    history: this.history, children: this.props.children });
  };

React-Rotuer包
Router.js

Router.prototype.render = function render() <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值