zoukankan      html  css  js  c++  java
  • react源码分析

    ReactMount.render -> ReactMount._renderSubtreeIntoContainer

    -> ReactMount._renderNewRootComponent -> ReactMount.batchedMountComponentIntoNode

    -> ReactReconciler.mountComponent -> ReactDomComponent.mountComponent

    -> ReactDomComponent._createContentMarkup ->ReactMultiChild.mountChildren

    ->  ReactMount._mountImageIntoNode -> ReactMount.setInnerHTML

    ReactMount._mountImageIntoNode负责将virtualdom实际mount到dom上,

    先是用ReactMarkupChecksum.canReuseMarkup检查是不是可以复用的markup

    /**
     * Mounting is the process of initializing a React component by creating its
     * representative DOM elements and inserting them into a supplied `container`.
     * Any prior content inside `container` is destroyed in the process.
     *
     *   ReactMount.render(
     *     component,
     *     document.getElementById('container')
     *   );
     *
     *   <div id="container">                   <-- Supplied `container`.
     *     <div data-reactid=".3">              <-- Rendered reactRoot of React
     *       // ...                                 component.
     *     </div>
     *   </div>
     *
     * Inside of `container`, the first element rendered is the "reactRoot".
     */
        if (transaction.useCreateElement) {
          while (container.lastChild) {
            container.removeChild(container.lastChild);
          }
          container.appendChild(markup);
        } else {
          setInnerHTML(container, markup);
        }

    Transaction

    /*
     * Use cases:
     * - Preserving the input selection ranges before/after reconciliation.
     *   Restoring selection even in the event of an unexpected error.
     * - Deactivating events while rearranging the DOM, preventing blurs/focuses,
     *   while guaranteeing that afterwards, the event system is reactivated.
     * - Flushing a queue of collected DOM mutations to the main UI thread after a
     *   reconciliation takes place in a worker thread.
     * - Invoking any collected `componentDidUpdate` callbacks after rendering new
     *   content.
     * - (Future use case): Wrapping particular flushes of the `ReactWorker` queue
     *   to preserve the `scrollTop` (an automatic scroll aware DOM).
     * - (Future use case): Layout calculations before and after DOM updates.
     *
     * Transactional plugin API:
     * - A module that has an `initialize` method that returns any precomputation.
     * - and a `close` method that accepts the precomputation. `close` is invoked
     *   when the wrapped process is completed, or has failed.
     *
     * @param {Array<TransactionalWrapper>} transactionWrapper Wrapper modules
     * that implement `initialize` and `close`.
     * @return {Transaction} Single transaction for reuse in thread.
     *
     * @class Transaction
     */
  • 相关阅读:
    noip2016组合数问题
    noip2017奶酪
    洛谷1091合唱队形
    洛谷P1075 质因数分解
    洛谷1004方格取数
    POJ2393奶酪工厂
    NOIP2012国王游戏(60分题解)
    洛谷1106删数问题
    洛谷1209修理牛棚
    二维树状数组区间修改+区间查询模版
  • 原文地址:https://www.cnblogs.com/TLightSky/p/4835539.html
Copyright © 2011-2022 走看看