<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 三大原則 Redux 可以被描述成三大基礎原則: ### 單一數據源 **整個應用的 [state](#) 被儲存在一棵 object tree 中,它只有一個單一的 [store](#) 。** 這讓同構應用開發變得非常容易。來自服務端的 state 可以輕而易舉地被序列化并融合到沒有額外代碼影響的客戶端上。由于是單一的 state tree ,調試也變得非常容易。你也可以把應用的 state 保存下來加快開發速度。此外,受益于單一的 state tree ,以前難以實現的像“撤銷/重做”這類的功能也變得輕而易舉。 ~~~ console.log(store.getState()); { visibilityFilter: 'SHOW_ALL', todos: [{ text: 'Consider using Redux', completed: true, }, { text: 'Keep all state in a single tree', completed: false }] } ~~~ ### State 是只讀的 **惟一改變 state 的辦法就是觸發 [action](#),action 是一個描述要發生什么的對象。** 這讓視圖和網絡請求不能直接修改 state,相反只能表達出需要修改的意圖。因為所有的修改都被集中化處理,且嚴格按照順序一個接一個執行,因此沒有模棱兩可的情況需要提防。 Action 就是普通對象而已,因此它們可以被日志打印、序列化、儲存、后期調試或測試時回放出來。 ~~~ store.dispatch({ type: 'COMPLETE_TODO', index: 1 }); store.dispatch({ type: 'SET_VISIBILITY_FILTER', filter: 'SHOW_COMPLETED' }); ~~~ ### 純函數的形式來執行修改 **為了描述 action 如何改變 state tree ,你需要編寫 [reducers](#)。** Reducer 只是一些純函數,它接收之前的 state 和 action,并返回新的 state。剛開始你可以只有一個 reducer,隨著應用變大,你可以把它拆成多個小的 reducers,分別獨立地操作 state tree 的不同部分,因為 reducer 只是普通函數,你可以控制它們被調用的順序,傳入附加數據,甚至編寫可復用的 reducer 來做一些通用任務,如分頁器。 ~~~ function visibilityFilter(state = 'SHOW_ALL', action) { switch (action.type) { case 'SET_VISIBILITY_FILTER': return action.filter; default: return state; } } function todos(state = [], action) { switch (action.type) { case 'ADD_TODO': return [...state, { text: action.text, completed: false }]; case 'COMPLETE_TODO': return [ ...state.slice(0, action.index), Object.assign({}, state[action.index], { completed: true }), ...state.slice(action.index + 1) ] default: return state; } } import { combineReducers, createStore } from 'redux'; let reducer = combineReducers({ visibilityFilter, todos }); let store = createStore(reducer); ~~~ 就是這樣,現在你已經明白 Redux 是怎么回事了。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看