1. 程式人生 > >react-route中renderProps內部結構與服務端渲染總結

react-route中renderProps內部結構與服務端渲染總結

最新內容請在github閱讀,我會定時更新這部分的內容。給您帶來不便,請見諒~~~~
最近在學習服務端渲染,之前一直不明白match方法中的renderProps,所以現在列印了log,查看了內部的結構

1.match方法

match({ history, routes: getRoutes(store), location: req.originalUrl }, (error, redirectLocation, renderProps) => {})

知道伺服器端渲染的都知道這個match方法,我這裡不再班門弄斧

2.renderProps屬性

首先我給出我自己配置的React-router:

{
   path:"/",
   component : App,
   IndexRoute:{
     component : Home
   },
   childRoutes:[
     {
       component : Home,
       path:"home"
     }
    ]
 }

下面是完整的renderProps屬性,其中renderProps包含routes,params,location,components,router,matchContext屬性。

 { 
    //renderProps包含routes物件
    routes:
    [ { path: '/'
, component: [Function: App], IndexRoute: [Object], childRoutes: [Object] }, { component: [Function: Home], path: 'home' } ], //renderProps包含params物件 params: {}, // renderProps包含location物件 location: { pathname: '/home', search: '', hash: ''
, state: undefined, action: 'POP', key: '34hg49', query: {} }, // renderProps包含components物件 components: [ [Function: App], [Function: Home] ], // renderProps包含router物件 router: { getCurrentLocation: [Function: getCurrentLocation], listenBefore: [Function: listenBefore], listen: [Function: listen], transitionTo: [Function: transitionTo], push: [Function: push], replace: [Function: replace], go: [Function: go], goBack: [Function: goBack], goForward: [Function: goForward], createKey: [Function: createKey], createPath: [Function: createPath], createHref: [Function: createHref], createLocation: [Function: createLocation], canGo: [Function: canGo], unsubscribe: [Function: unsubscribe], setRouteLeaveHook: [Function: listenBeforeLeavingRoute], isActive: [Function: isActive], location: { pathname: '/home', search: '', hash: '', state: undefined, action: 'POP', key: '34hg49', query: {} }, params: {}, routes: [ [Object], [Object] ] }, // renderProps包含matchContext物件 matchContext: { transitionManager: { isActive: [Function: isActive], match: [Function: match], listenBeforeLeavingRoute: [Function: listenBeforeLeavingRoute], listen: [Function: listen] }, router: { getCurrentLocation: [Function: getCurrentLocation], listenBefore: [Function: listenBefore], listen: [Function: listen], transitionTo: [Function: transitionTo], push: [Function: push], replace: [Function: replace], go: [Function: go], goBack: [Function: goBack], goForward: [Function: goForward], createKey: [Function: createKey], createPath: [Function: createPath], createHref: [Function: createHref], createLocation: [Function: createLocation], canGo: [Function: canGo], unsubscribe: [Function: unsubscribe], setRouteLeaveHook: [Function: listenBeforeLeavingRoute], isActive: [Function: isActive], location: [Object], params: {}, routes: [Object] } } }

我相信,當你瞭解了renderProps的內部結構以後,你能夠更好的理解網上的關於react-router伺服器渲染的例子了。如果覺得有用別忘了star哦~~~~

3.renderToString返回的一個內容

<!-- 1.HTML元素最頂級具有data-react-checksum屬性計算hash
 res.send('<!doctype html>\n' +
          renderToString(<Html assets={webpackIsomorphicTools.assets()} component={component} store={store}/>));
      });
 -->
<html lang="en-us" data-reactroot="" data-reactid="1" data-react-checksum="350097657">
 <head data-reactid="2"> 
  <title data-react-helmet="true" data-reactid="3">Widgets</title> 
  <link rel="shortcut icon" href="/favicon.ico" data-reactid="4" /> 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" data-reactid="5" /> 
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Work+Sans:400,500" data-reactid="6" /> 
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/violet/0.0.1/violet.min.css" data-reactid="7" /> 
  <meta name="viewport" content="width=device-width, initial-scale=1" data-reactid="8" /> 
 </head> 
 <body data-reactid="9"> 
  <div id="content" data-reactid="10"> 
  <!--2.我們的Header+Footer+Content的容器具有data-react-checksum的hash值。其渲染的部分為如下的內容:
   <div id="content" dangerouslySetInnerHTML={{__html: content}}/>
  -->
   <div class="container" data-reactroot="" data-reactid="1" data-react-checksum="1912308161"> 
    <div class="header" data-reactid="2"> 
     <nav class="navbar navbar-inverse" data-reactid="3"> 
      <div class="container" data-reactid="4"> 
       <div class="navbar-header" data-reactid="5"> 
        <a href="#" class="navbar-brand" data-reactid="6">React全家桶例項</a> 
        <button type="button" class="navbar-toggle collapsed" data-reactid="7"> <span class="sr-only" data-reactid="8">Toggle navigation</span> <span class="icon-bar" data-reactid="9"></span> <span class="icon-bar" data-reactid="10"></span> <span class="icon-bar" data-reactid="11"></span> </button> 
       </div> 
       <div class="navbar-collapse collapse" data-reactid="12"> 
        <ul class="nav navbar-nav" data-reactid="13"> 
         <li role="presentation" class="" data-reactid="14"> <a href="#" role="button" data-reactid="15">聊天</a> </li> 
         <li role="presentation" class="active" data-reactid="16"> <a href="/widget" action="push" data-reactid="17">Widget</a> </li> 
         <li role="presentation" class="" data-reactid="18"> <a href="#" role="button" data-reactid="19">Survey</a> </li> 
         <li role="presentation" class="" data-reactid="20"> <a href="#" role="button" data-reactid="21">關於我們</a> </li> 
         <li role="presentation" class="" data-reactid="22"> <a href="/login" action="push" data-reactid="23">登入</a> </li> 
         <li role="presentation" class="" data-reactid="24"> <a href="/pagination" action="push" data-reactid="25">分頁</a> </li> 
         <li class="dropdown" data-reactid="26"> <a id="basic-nav-dropdown" role="button" class="dropdown-toggle" aria-haspopup="true" aria-expanded="false" href="#" data-reactid="27">
           <!-- react-text: 28 -->更多
           <!-- /react-text -->
           <!-- react-text: 29 --> 
           <!-- /react-text --><span class="caret" data-reactid="30"></span> </a> 
          <ul role="menu" class="dropdown-menu" aria-labelledby="basic-nav-dropdown" data-reactid="31"> 
           <li role="presentation" class="" data-reactid="32"><a role="menuitem" tabindex="-1" href="#" data-reactid="33">Action</a> </li> 
           <li role="presentation" class="" data-reactid="34"><a role="menuitem" tabindex="-1" href="#" data-reactid="35">Another action</a> </li> 
           <li role="presentation" class="" data-reactid="36"> <a role="menuitem" tabindex="-1" href="#" data-reactid="37">Something else here</a> </li> 
           <li role="separator" class="divider" data-reactid="38"></li>
           <li role="presentation" class="" data-reactid="39"><a role="menuitem" tabindex="-1" href="#" data-reactid="40">Separated link</a></li> 
          </ul> </li> 
        </ul> 
        <ul class="nav navbar-nav navbar-right" data-reactid="41"> 
         <li role="presentation" class="" data-reactid="42"> <a href="#" role="button" data-reactid="43">Link Right</a> </li> 
         <li role="presentation" class="" data-reactid="44"> <a href="#" role="button" data-reactid="45">Link Right</a> </li> 
        </ul> 
       </div> 
      </div> 
     </nav> 
    </div> 
    <div data-reactid="46">
     <!-- react-empty: 47 --> 
     <table class="table table-striped" data-reactid="48"> 
      <thead data-reactid="49"> 
       <tr data-reactid="50"> 
        <th data-reactid="51">ID</th> 
        <th data-reactid="52">顏色</th> 
        <th data-reactid="53">Sprockets</th> 
        <th data-reactid="54">所有者</th> 
        <th data-reactid="55"></th> 
       </tr> 
      </thead> 
      <tbody data-reactid="56"> 
       <tr data-reactid="57"> 
        <td data-reactid="58">1</td> 
        <td data-reactid="59">Red</td> 
        <td data-reactid="60">7</td> 
        <td data-reactid="61">John</td> 
        <td data-reactid="62"> <button class="btn btn-primary" data-reactid="63"> <i class="fa fa-pencil" data-reactid="64"></i>
          <!-- react-text: 65 --> 編輯
          <!-- /react-text --> </button> 
         <div data-reactid="66"> 
          <div style="color:rgba(0, 0, 0, 0.87);background-color:#ffffff;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;box-sizing:border-box;font-family:Roboto, sans-serif;-webkit-tap-highlight-color:rgba(0,0,0,0);box-shadow:0 1px 6px rgba(0, 0, 0, 0.12),
[1]          0 1px 4px rgba(0, 0, 0, 0.12);border-radius:2px;display:inline-block;min-width:88px;mui-prepared:;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-box-sizing:border-box;" data-reactid="67"> 
           <button style="border:10px;box-sizing:border-box;display:inline-block;font-family:Roboto, sans-serif;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);cursor:pointer;text-decoration:none;margin:0;padding:0;outline:none;font-size:inherit;font-weight:inherit;position:relative;z-index:1;height:36px;line-height:36px;width:100%;border-radius:2px;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;background-color:#ffffff;text-align:center;mui-prepared:;-moz-box-sizing:border-box;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;" tabindex="0" type="button" data-reactid="68"> 
            <div data-reactid="69"> 
             <div style="height:36px;border-radius:2px;background-color:;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;top:0;mui-prepared:;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;" data-reactid="70">
              <span style="position:relative;opacity:1;font-size:14px;letter-spacing:0;text-transform:uppercase;font-weight:500;margin:0;user-select:none;padding-left:16px;padding-right:16px;color:rgba(0, 0, 0, 0.87);mui-prepared:;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;" data-reactid="71">Modal Dialog</span>
             </div>
            </div></button>
          </div>
          <!-- react-empty: 72 -->
         </div></td>
       </tr>
       <tr data-reactid="73">
        <td data-reactid="74">2</td>
        <td data-reactid="75">Taupe</td>
        <td data-reactid="76">1</td>
        <td data-reactid="77">George</td>
        <td data-reactid="78"><button class="btn btn-primary" data-reactid="79"><i class="fa fa-pencil" data-reactid="80"></i>
          <!-- react-text: 81 --> 編輯
          <!-- /react-text --></button>
         <div data-reactid="82">
          <div style="color:rgba(0, 0, 0, 0.87);background-color:#ffffff;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;box-sizing:border-box;font-family:Roboto, sans-serif;-webkit-tap-highlight-color:rgba(0,0,0,0);box-shadow:0 1px 6px rgba(0, 0, 0, 0.12),
[1]          0 1px 4px rgba(0, 0, 0, 0.12);border-radius:2px;display:inline-block;min-width:88px;mui-prepared:;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-box-sizing:border-box;" data-reactid="83">
           <button style="border:10px;box-sizing:border-box;display:inline-block;font-family:Roboto, sans-serif;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);cursor:pointer;text-decoration:none;margin:0;padding:0;outline:none;font-size:inherit;font-weight:inherit;position:relative;z-index:1;height:36px;line-height:36px;width:100%;border-radius:2px;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;background-color:#ffffff;text-align:center;mui-prepared:;-moz-box-sizing:border-box;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;" tabindex="0" type="button" data-reactid="84">
            <div data-reactid="85">
             <div style="height:36px;border-radius:2px;background-color:;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;top:0;mui-prepared:;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;" data-reactid="86">
              <span style="position:relative;opacity:1;font-size:14px;letter-spacing:0;text-transform:uppercase;font-weight:500;margin:0;user-select:none;padding-left:16px;padding-right:16px;color:rgba(0, 0, 0, 0.87);mui-prepared:;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;" data-reactid="87">Modal Dialog</span>
             </div>
            </div></button>
          </div>
          <!-- react-empty: 88 -->
         </div></td>
       </tr>
       <tr data-reactid="89">
        <td data-reactid="90">3</td>
        <td data-reactid="91">Green</td>
        <td data-reactid="92">8</td>
        <td data-reactid="93">Ringo</td>
        <td data-reactid="94"><button class="btn btn-primary" data-reactid="95"><i class="fa fa-pencil" data-reactid="96"></i>
          <!-- react-text: 97 --> 編輯
          <!-- /react-text --></button>
         <div data-reactid="98">
          <div style="color:rgba(0, 0, 0, 0.87);background-color:#ffffff;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;box-sizing:border-box;font-family:Roboto, sans-serif;-webkit-tap-highlight-color:rgba(0,0,0,0);box-shadow:0 1px 6px rgba(0, 0, 0, 0.12),
[1]          0 1px 4px rgba(0, 0, 0, 0.12);border-radius:2px;display:inline-block;min-width:88px;mui-prepared:;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-box-sizing:border-box;" data-reactid="99">
           <button style="border:10px;box-sizing:border-box;display:inline-block;font-family:Roboto, sans-serif;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);cursor:pointer;text-decoration:none;margin:0;padding:0;outline:none;font-size:inherit;font-weight:inherit;position:relative;z-index:1;height:36px;line-height:36px;width:100%;border-radius:2px;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;background-color:#ffffff;text-align:center;mui-prepared:;-moz-box-sizing:border-box;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;" tabindex="0" type="button" data-reactid="100">
            <div data-reactid="101">
             <div style="height:36px;border-radius:2px;background-color:;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;top:0;mui-prepared:;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;" data-reactid="102">
              <span style="position:relative;opacity:1;font-size:14px;letter-spacing:0;text-transform:uppercase;font-weight:500;margin:0;user-select:none;padding-left:16px;padding-right:16px;color:rgba(0, 0, 0, 0.87);mui-prepared:;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;" data-reactid="103">Modal Dialog</span>
             </div>
            </div></button>
          </div>
          <!-- react-empty: 104 -->
         </div></td>
       </tr>
       <tr data-reactid="105">
        <td data-reactid="106">4</td>
        <td data-reactid="107">Blue</td>
        <td data-reactid="108">2</td>
        <td data-reactid="109">Paul</td>
        <td data-reactid="110"><button class="btn btn-primary" data-reactid="111"><i class="fa fa-pencil" data-reactid="112"></i>
          <!-- react-text: 113 --> 編輯
          <!-- /react-text --></button>
         <div data-reactid="114">
          <div style="color:rgba(0, 0, 0, 0.87);background-color:#ffffff;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;box-sizing:border-box;font-family:Roboto, sans-serif;-webkit-tap-highlight-color:rgba(0,0,0,0);box-shadow:0 1px 6px rgba(0, 0, 0, 0.12),
[1]          0 1px 4px rgba(0, 0, 0, 0.12);border-radius:2px;display:inline-block;min-width:88px;mui-prepared:;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-box-sizing:border-box;" data-reactid="115">
           <button style="border:10px;box-sizing:border-box;display:inline-block;font-family:Roboto, sans-serif;-webkit-tap-highlight-color:rgba(0, 0, 0, 0);cursor:pointer;text-decoration:none;margin:0;padding:0;outline:none;font-size:inherit;font-weight:inherit;position:relative;z-index:1;height:36px;line-height:36px;width:100%;border-radius:2px;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;background-color:#ffffff;text-align:center;mui-prepared:;-moz-box-sizing:border-box;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;" tabindex="0" type="button" data-reactid="116">
            <div data-reactid="117">
             <div style="height:36px;border-radius:2px;background-color:;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;top:0;mui-prepared:;-webkit-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;-moz-transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;" data-reactid="118">
              <span style="position:relative;opacity:1;font-size:14px;letter-spacing:0;text-transform:uppercase;font-weight:500;margin:0;user-select:none;padding-left:16px;padding-right:16px;color:rgba(0, 0, 0, 0.87);mui-prepared:;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;" data-reactid="119">Modal Dialog</span>
             </div>
            </div></button>
          </div>
          <!-- react-empty: 120 -->
         </div></td>
       </tr>
      </tbody>
     </table>
     <button data-reactid="121">載入widget</button>
    </div>
    <div class="footer" data-reactid="122">
     Footer
    </div>
   </div>
  </div>
  <script charset="UTF-8" data-reactid="11">
   window.__data = {
    //routing來自於combineReducer的react-router
    "routing": {
        "locationBeforeTransitions": {
            "pathname": "\u002Fwidget",
            "search": "",
            "hash": "",
            "action": "POP",
            "key": null,
            "query": {}
        }
    },
     //reduxAsyncConnect來自於combineReducer
    "reduxAsyncConnect": {
        "loaded": true
    },
    //auth來自於combineReducer
    "auth": {
        "loaded": true,
        "loading": false,
        "user": null
    },
    //form來自於combineReducer中的redux-form
    "form": {},
    //multireducer來自於combineReducer
    "multireducer": {
        "counter1": {
            "count": 0
        },
        "counter2": {
            "count": 0
        },
        "counter3": {
            "count": 0
        }
    },
   //info來自於combineReducer
    "info": {
        "loaded": true,
        "loading": false,
        "data": {
            "message": "This came from the api server",
            "time": 1496386316261
        }
    },
     //connect來自於combineReducer
    "connect": {
        "connected": false
    },
    //recipeGrid來自於combineReducer的violet-paginator
    "recipeGrid": {
        "removing": [],
        "loadError": null,
        "sortReverse": false,
        "updating": [],
        "requestId": null,
        "totalCount": 0,
        "page": 1,
        "pageSize": 15,
        "isLoading": false,
        "initialized": false,
        "results": [],
        "stale": false,
        "massUpdating": [],
        "filters": {},
        "sort": ""
    },
     //widgets來自於combineReducer
    "widgets": {
        "loaded": true,
        "editing": {},
        "saveError": {},
        "loading": false,
        "data": [{
            "id": 1,
            "color": "Red",
            "sprocketCount": 7,
            "owner": "John"
        },
        {
            "id": 2,
            "color": "Taupe",
            "sprocketCount": 1,
            "owner": "George"
        },
        {
            "id": 3,
            "color": "Green",
            "sprocketCount": 8,
            "owner": "Ringo"
        },
        {
            "id": 4,
            "color": "Blue",
            "sprocketCount": 2,
            "owner": "Paul"
        }],
        "error": null
    }
};
  </script>
  <script src="http://localhost:8091/dist/main-3dbb874c116423a8ee43.js" charset="UTF-8" data-reactid="12"></script> 
 </body>
</html>

你可以檢視react-universal-bucket這個例子。上面是renderToString輸出的內容,你要學會關注data-react-checksumdata-reactidwindow.__data

4.renderToString的真實作用

4.1 renderToString本身是靜態的

之所以說renderToString是靜態的,是因為其如果僅僅是呼叫它來渲染元件樹那麼其只是一個模版語言而已。React提供了一個API用於將虛擬DOM樹在服務端環境下進行渲染,這個API是ReactDom/server中的renderToString。這個方法接受一個虛擬DOM樹,並返回一個渲染後的HTML字串,例如我有一個根級元件Root,我便可以使用下列語句得到結果:

import {renderToString} from 'ReactDom/server';
const markup = renderToString(
    <Root />
);

markup即為渲染後的結果。renderToString這個方法是服務端渲染的基礎,但如果只是單純這樣使用,那麼基本等於將React作為一個複雜很多的模板語言來寫而已,因為這個渲染並不會理會任何的ajax請求(沒有請求也就是說在渲染我們元件之前無法自定義元件需要的資料,這是硬傷!!可以使用下文的redux的Provider將store中的資料傳遞給我們的元件來解決),同時也不會根據url來做任何路由,它只會在第一次render方法呼叫後結束。這也就是說render方法之後的所有生命週期函式都不會被觸發,在一次服務端渲染中,只有constructor、componentWillMount和render會被各觸發一次,並且在期間使用setState也是沒有意義的

這顯然不是我們期望的,為了愉快得滿足我們的須有,這裡有兩個問題需要解決:

(1)路由(使用react-router來監聽location變化從而重新渲染元件,此處不做講解)。
(2)ajax請求(而不是將React作為一個模板語言,先發送ajax請求獲取到store狀態再渲染元件樹,redux-async-connect完成或者中介軟體自己處理)。

相關推薦

react-routerenderProps內部結構服務渲染總結

最新內容請在github閱讀,我會定時更新這部分的內容。給您帶來不便,請見諒~~~~ 最近在學習服務端渲染,之前一直不明白match方法中的renderProps,所以現在列印了log,查看了內部的結構 1.match方法 match({ histor

react+laravel服務渲染的思考

1、首先 controller 幾乎不寫程式碼是不可能的。我現在就是 react.js 和 laravel 一起用,前後端完全分離的。 用 react.js 搭建前端檢視,然後用 ajax 或者 fe

React Native的DeviceEventEmitter.addListenerDeviceEventEmitter.emit

ice navigator 訂閱 shu reac 如何 沒有 解釋 http   官方文檔沒有對這兩個方法做很好的解釋,需要自己找資料研究。看了幾篇文章,總結是和訂閱發布模式差不多,用來事件監聽發送的。 React Native學習之DeviceEventEmitter傳

在Object-C學習資料結構演算法之排序演算法

筆者在學習資料結構與演算法時,嘗試著將排序演算法以動畫的形式呈現出來更加方便理解記憶,本文配合Demo 在Object-C中學習資料結構與演算法之排序演算法閱讀更佳。 目錄 選擇排序 氣泡排序 插入排序 快速排序 雙路快速排序 三路快速排序 堆排序 總結與收穫

Linuxtelnet客戶服務的安裝配置

Telnet服務的配置步驟如下: 一、安裝telnet軟體包(通常要兩個)。   1、 telnet-client (或 telnet),這個軟體包提供的是 telnet 客戶端程式;   2、是 telnet-server 軟體包,這個才是真正的 Telnet ser

【Scala】Vector內部結構記憶體共享原理

Scala不可變集合 Scala不可變集合的設計目標是提供高效又安全的實現。這些集合中的大部分都是用高階技巧來在集合的不同版本之間“共享”記憶體。其中較長使用到的是Vector和List。 在一般的程式設計任務中,不可變集合有很多超出可變集合的優點。尤其重要

Java使用socket實現客戶服務互動

Socket解釋: 網路上的兩個程式通過一個雙向的通訊連線實現資料的交換,這個連線的一端稱為一個socket。 Socket的英文原義是“孔”或“插座”。作為BSD UNIX的程序通訊機制,取後一種意思。通常也稱作"套接字",用於描述IP地址和埠,是一個通訊鏈的控制代碼,可以用來實現不同虛擬機器或不同計

node.jsnet網路模組TCP服務客戶的使用

node.js中net模組為我們提供了TCP伺服器和客戶端通訊的各種介面。   一、建立伺服器並監聽埠 const net = require('net'); //建立一個tcp服務 //引數一表示建立服務的一些配置 //引數二表示 事件 'connection' 監聽回撥函式

React NativeNavigator的安裝使用

一、安裝Navigator 1.安裝react-native-deprecated-custom-components npm install react-native-deprecated-custom-components --save 2.若npm安裝報錯,則

C語言內部函式外部函式

內部函式:   如果一個函式只能被本檔案中其它函式所呼叫,它稱為內部函式。在定義內部函式時,在函式名和函式型別的前面加static。即   static 型別識別符號 函式名 (形參表) 如: static int fun (int a, int b) 內部函式又稱靜態函

antd promock資料服務互動詳解

說明一下:我用的antd pro腳手架是2.0版本的。 說mock之前預設新建頁面,路由等基礎功能你已經掌握。 1、頁面需要什麼格式的資料 我用一個antd pro裡面的表格元件作為演示: impor

React學習筆記——Router(有待完善類比學習、頁面路由服務路由部分)

React-router 基本概念 import { Router, Route, Link } from 'react-router' BrowserRouter:容器元件,在其內配置Route為真正的路由方面的東西; Route:它最基本的職

Linuxtelnet客戶服務的安裝配置(yum安裝)

Telnet服務的配置步驟如下: 一、安裝telnet軟體包(通常要兩個)。   1、 telnet-client (或 telnet),這個軟體包提供的是 telnet 客戶端程式;   2、是 telnet-server 軟體包,這個才是真正的 Telnet

Web應用瀏覽器服務的編碼和解碼

【1】基本概念 有資訊交換就會產生編碼、傳輸、解碼三個過程。編碼是資訊從一種形式轉變成另一種形式的過程,正如人類的語言通過聲帶編碼,轉換成聲波。解碼是編碼的逆函式,耳膜接收聲波,通過腦神經解碼成人類文化所能理解的資訊。 字符集是一種文化上下文下的所有文字元號集合

徹底理解android內部儲存外部儲存

我們先來考慮這樣一個問題: 開啟手機設定,選擇應用管理,選擇任意一個App,然後你會看到兩個按鈕,一個是清除快取,另一個是清除資料,那麼當我們點選清除快取的時候清除的是哪裡的資料?當我們點選清除資料的時候又是清除的哪裡的資料?讀完本文相信你會有答案。 在android開發中

HashMap的資料結構get,put原始碼解析

HashMap 執行流程: 首先構造方法: public HashMap() {         this.loadFactor =DEFAULT_LOAD_FACTOR;// all otherfields defaulted     } public HashMap(

Python socket編程客戶服務通信

eve sock 系統 con conn 綁定 idt 註意 服務 [本文出自天外歸雲的博客園] 目標:實現客戶端與服務端的socket通信,消息傳輸。 客戶端 客戶端代碼: from socket import socket,AF_INET,SOCK_STRE

Server-Side Rendering(服務渲染)的優點缺點

spa 性能 ide 渲染 額外 優點 一定的 size 壓力 優點 1. SEO 客戶端渲染,頁面中只有初始的幾個html容器,js生成內容填充到容器中,爬蟲只能識別到初始的html容器,js生成的內容一般不會被識別,而服務端渲染直接給出html,爬蟲可以識別到所有內容

Netty入門之客戶服務通信(二)

ktr 數據格式 lis boot ride owa 參數 val cef Netty入門之客戶端與服務端通信(二) 一.簡介   在上一篇博文中筆者寫了關於Netty入門級的Hello World程序。書接上回,本博文是關於客戶端與服務端的通信,感覺也沒什麽好說的了,直接

Android BLE終端通信(三)——client服務通信過程以及實現數據通信

.sh 沒有 indexof 實例 解析 rip listview filter @override Android BLE與終端通信(三)——client與服務端通信過程以及實現數據通信 前面的終究僅僅是小知識點。上不了臺面,也僅僅能算是起