《Redux》

  • Redux is a predictable state container for JavaScript apps.

  • Keep your state flat.

  • Redux Flow


  • mutation and asynchronicity

  • Redux attempts to make state mutations predictable by imposing certain restrictions on how and when updates can happen.

  • To change something in the state, you need to dispatch an action. An action is a plain JavaScript object (notice how we don’t introduce any magic?) that describes what happened.

  • Finally, to tie state and actions together, we write a function called a reducer. Again, nothing magical about it—it’s just a function that takes state and action as arguments, and returns the next state of the app.

  • Three Principles

    1. Single source of truth (The state of your whole application is stored in an object tree within a single store.)
    2. State is read-only (The only way to change the state is to emit an action, an object describing what happened.)
    3. Changes are made with pure functions (To specify how the state tree is transformed by actions, you write pure reducers.)
  • Reducers are just pure functions that take the previous state and an action, and return the next state. Remember to return new state objects, instead of mutating the previous state.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 愛夜 夜是黑色的舞臺(tái) 臺(tái)上有鮮花 綠草 黑色的告白 臺(tái)上有星星 月亮 黑色的云海 ...
    與美同行閱讀 218評(píng)論 0 2
  • 清晨 我看到門前最美的野花 我撐著傘 迎著那微風(fēng)攜帶的雨 嘴角皺起的皮膚 藏不住我內(nèi)心的歡樂 我望著那不遠(yuǎn)處的枯藤...
    我想一個(gè)人走閱讀 244評(píng)論 1 0
  • 也許我不應(yīng)該這樣海投一切我覺得有可能的,招應(yīng)屆生的工作。我不知道我這樣的想法是不是對(duì),但是我喜歡接觸人的工作,喜歡...
    喜糖閱讀 193評(píng)論 0 1
  • 有些人口若懸河的說,實(shí)事卻不見一件!有一次從南京回來,我?guī)Я它c(diǎn)貨準(zhǔn)備回來,可是覺得少了點(diǎn),所以又通過找貨軟件,還準(zhǔn)...
    人生如若如初見閱讀 222評(píng)論 1 3

友情鏈接更多精彩內(nèi)容