Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Why Redux?

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Why Redux?

社内LT大会用のスライドです。Reduxの紹介。

Avatar for Takanori Maeda

Takanori Maeda

September 30, 2016
Tweet

More Decks by Takanori Maeda

Other Decks in Programming

Transcript

  1. Reduxͱ͸ʁ • WebΞϓϦέʔγϣϯΛߏங͢ΔΞϓϩʔνͷͻͱͭʢঢ়ଶ Λ؅ཧ͢ΔͨΊͷϑϨʔϜϫʔΫʣ • ࡞ऀ͸Dan Abramovࢯ@Facebook • Facebookͷఏএ͢ΔFluxΞʔΩςΫνϟͷӨڹΛड͚͍ͯΔ •

    ࠷ॳ͸FluxϑϨʔϜϫʔΫͷͻͱͭʹ͗͢ͳ͔͕ͬͨɺݱࡏ ͸Ұਓউͪঢ়ଶ • ΫϩεϓϥοτϑΥʔϜʹ΋ରԠʢΫϥΠΞϯτ / αʔόʔ / ωΠςΟϒͰ΋ಈ͘ʣ • Reactͷঢ়ଶΛ؅ཧ͢ΔͨΊʹηοτͰ࢖ΘΕΔ͜ͱ͕ଟ͍ • GitHubͷελʔ਺͸23,663ʢ2016೥9݄30೔ݱࡏʣ
  2. Reduxͷ࢓૊Έ • σʔλ͸Ұํ޲ʹ͔͠ྲྀΕͳ͍ • ActionɺReducerɺStoreͷ3ͭͷ෦෼͔ Βߏ੒͞ΕΔ • Store͸1ͭͷΞϓϦέʔγϣϯʹඞͣ1 ͭ •

    Store͸ΞϓϦέʔγϣϯશମͷঢ়ଶ ʢStateʣΛObjectπϦʔͱͯ͠อ࣋ • ঢ়ଶʢStateʣ͸Immutable • ঢ়ଶΛʢStateʣΛߋ৽͢Δ།Ұͷํ๏ ͸ɺActionΛൃՐͤ͞Δ͜ͱ • Action͸ΞΫγϣϯ໊ͱঢ়ଶͷ஋Λ࣋ ͬͨ୯ͳΔΦϒδΣΫτ • Reducer͸෭࡞༻ͷͳ͍७ਮͳؔ਺ɻ ݱࡏͷঢ়ଶͱActionΛҾ਺ʹͱΔ
  3. Viewͷ࣮૷ • جຊతʹ͸PubSubύλʔϯ • StoreͰ༻ҙ͞Ε͍ͯΔAPIΛ࢖͏ ঢ়ଶʢstateʣ΁ͷΞΫηε ɹɹɹ=> getState()ϝιου ঢ়ଶʢstateʣͷߋ৽ ɹɹɹ=>

    dispatch(action)ϝιου ϦεφʔΛొ࿥ ɹɹɹ=> subscribe(listener)ϝιου Ϧεφʔͷొ࿥ղআ => subscribe(lstener)ϝιου ɹɹɹɹʹΑͬͯฦ͞Εͨؔ਺ // ActionをReducerに伝播 store.dispatch(actionCreators()); // stateの状態を購読。状態に変化が // あったらリスナーを実行 store.subscribe(() => { /* リスナーの処理を書く */ // stateを取得 store.getState(); }); Viewͷ࣮૷ྫ