redux一些筆記

它是什么

a predictable(可預料的) state container for JavaScript apps.

為什么要

01.It helps you write applications that behave consistently(行為固定) , run in different environments (client, server, and native)(多端運行) , and are easy to test(測試簡單) .
02.On top of that, it provides a great developer experience(開發(fā)體驗), such as live code editing combined with a time traveling debugger.
03.can use Redux together with React, or with any other view library(集成軟件).
04.It is tiny (2kB, including dependencies)(輕量微小).

如何使用

了解概念
If you're brand new to Redux and want to understand the basic concepts, see:
01.The Motivation behind building Redux(了解意圖), the Core Concepts(核心概念), and the Three Principles(三個原則).
02.The basic tutorial in the Redux docs(基礎教程).
03.If you learn best by looking at code and playing with it, check out our list of Redux example applications(示例應用), available as separate projects in the Redux repo, and also as interactive online examples on CodeSandbox.
......

安裝軟件

npm install --save redux

基本架構(gòu)

//導入類庫
import { createStore } from 'redux'

/**
 * This is a reducer, a pure function with (state, action) => state signature.
 * It describes how an action transforms the state into the next state.
 *
 * The shape of the state is up to you: it can be a primitive, an array, an object,
 * or even an Immutable.js data structure. The only important part is that you should
 * not mutate the state object, but return a new object if the state changes.
 *
 * In this example, we use a `switch` statement and strings, but you can use a helper that
 * follows a different convention (such as function maps) if it makes sense for your
 * project.
 */
function counter(state = 0, action) {
  switch (action.type) {
    case 'INCREMENT':
      return state + 1
    case 'DECREMENT':
      return state - 1
    default:
      return state
  }
}
 
//
let store = createStore(counter)

//添加訂閱
store.subscribe(() => console.log(store.getState()))

//發(fā)布消息
store.dispatch({ type: 'INCREMENT' })// 1
store.dispatch({ type: 'INCREMENT' })// 2
store.dispatch({ type: 'DECREMENT' })// 1

官方文檔

01.Introduction(介紹篇)
02.Basics(基礎篇)
03.Advanced(進階篇)
04.Recipes(秘訣篇)
05.FAQ(問答篇)
06.Troubleshooting(問題篇)
07.Glossary(術(shù)語篇)
08.API Reference(接口篇)

一些示例

01.Counter Vanilla: Source
02.Counter: Source | Sandbox
03.Todos: Source | Sandbox
04.Todos with Undo: Source | Sandbox
05.Todos w/ Flow: Source
06.TodoMVC: Source | Sandbox
07.Shopping Cart: Source | Sandbox
08.Tree View: Source | Sandbox
09.Async: Source | Sandbox
10.Universal: Source
11.Real World: Source | Sandbox

特別鳴謝

01.The Elm Architecture for a great intro to modeling state updates with reducers;
02.Turning the database inside-out for blowing my mind;
03.Developing ClojureScript with Figwheel for convincing me that re-evaluation should “just work”;
04.Webpack for Hot Module Replacement;
05.Flummox for teaching me to approach Flux without boilerplate or singletons;
06.disto for a proof of concept of hot reloadable Stores;
07.NuclearJS for proving this architecture can be performant;
08.Om for popularizing the idea of a single state atom;
09.Cycle for showing how often a function is the best tool;
10.React for the pragmatic innovation.

官方圖標

You can find the official logo on GitHub.

更新記錄

01.This project adheres to Semantic Versioning.
02.Every release, along with the migration instructions, is documented on the GitHub Releases page.

其贊助者

01.The work on Redux was funded by the community.
02.Meet some of the outstanding(杰出的) companies that made it possible:
Webflow
Ximedes
03.See the full list of Redux patrons, as well as the always-growing list of people and companies that use Redux.

參考文獻

redux.offical-readme[p].npmjs
redux.source-code.github

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末科吭,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子昼窗,更是在濱河造成了極大的恐慌,老刑警劉巖涛舍,帶你破解...
    沈念sama閱讀 217,734評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件澄惊,死亡現(xiàn)場離奇詭異,居然都是意外死亡富雅,警方通過查閱死者的電腦和手機掸驱,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來没佑,“玉大人毕贼,你說我怎么就攤上這事「蛏荩” “怎么了鬼癣?”我有些...
    開封第一講書人閱讀 164,133評論 0 354
  • 文/不壞的土叔 我叫張陵陶贼,是天一觀的道長。 經(jīng)常有香客問我待秃,道長拜秧,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,532評論 1 293
  • 正文 為了忘掉前任章郁,我火速辦了婚禮枉氮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘暖庄。我一直安慰自己聊替,他們只是感情好,可當我...
    茶點故事閱讀 67,585評論 6 392
  • 文/花漫 我一把揭開白布培廓。 她就那樣靜靜地躺著佃牛,像睡著了一般。 火紅的嫁衣襯著肌膚如雪医舆。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,462評論 1 302
  • 那天象缀,我揣著相機與錄音蔬将,去河邊找鬼。 笑死央星,一個胖子當著我的面吹牛霞怀,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播莉给,決...
    沈念sama閱讀 40,262評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼毙石,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了颓遏?” 一聲冷哼從身側(cè)響起徐矩,我...
    開封第一講書人閱讀 39,153評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎叁幢,沒想到半個月后滤灯,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,587評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡曼玩,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,792評論 3 336
  • 正文 我和宋清朗相戀三年鳞骤,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片黍判。...
    茶點故事閱讀 39,919評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡豫尽,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出顷帖,到底是詐尸還是另有隱情美旧,我是刑警寧澤渤滞,帶...
    沈念sama閱讀 35,635評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站陈症,受9級特大地震影響蔼水,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜录肯,卻給世界環(huán)境...
    茶點故事閱讀 41,237評論 3 329
  • 文/蒙蒙 一趴腋、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧论咏,春花似錦优炬、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至养涮,卻和暖如春葵硕,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背贯吓。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評論 1 269
  • 我被黑心中介騙來泰國打工懈凹, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人悄谐。 一個月前我還...
    沈念sama閱讀 48,048評論 3 370
  • 正文 我出身青樓介评,卻偏偏與公主長得像,于是被迫代替她去往敵國和親爬舰。 傳聞我的和親對象是個殘疾皇子们陆,可洞房花燭夜當晚...
    茶點故事閱讀 44,864評論 2 354

推薦閱讀更多精彩內(nèi)容