Slide 1

Slide 1 text

ΠΧϦϯάʹ͓͚Δ
 γϯάϧϖʔδΞϓϦέʔγϣϯ

Slide 2

Slide 2 text

id:cockscomb Ճ౻ਘथ גࣜձࣾ͸ͯͳ γχΞΞϓϦέʔγϣϯΤϯδχΞ ΠΧϦϯάͷ5FDI-FBE

Slide 3

Slide 3 text

˜/JOUFOEP

Slide 4

Slide 4 text

ΠΧϦϯά w /JOUFOEP4XJUDI0OMJOFΞϓϦ಺෦ͷαʔϏε w 4QMBUPPOͷϓϨΠσʔλΛݟΔ͜ͱ͕Ͱ͖Δ

Slide 5

Slide 5 text

࠾༻ٕज़ w ϑϩϯτΤϯυ͸41" w 5ZQF4DSJQU w 3FBDU3FEVY w ཪଆʹ͸ΦʔέετϨʔγϣϯ૚ͱͯ͠ͷ"1*αʔόʔ w 1FSM w %PDLFSͰಈ͍͍ͯΔ

Slide 6

Slide 6 text

લఏ w ͳΜͰ΋Ͱ͖ΔνʔϜ w 8FCΞϓϦέʔγϣϯ w J04"OESPJEͷωΠςΟϒΞϓϦ w 41"͸ॳΊͯ w σβΠφʔ͕3FBDU$PNQPOFOUΛ৮ΕΔ

Slide 7

Slide 7 text

w ٕज़બఆ w 3FBDUͱ3FEVYʹΑΔεςʔτϑϧΞϓϦέʔγϣϯ w 3FEVY4BHB w 8FCϖʔδͱͯ͠ͷ41"

Slide 8

Slide 8 text

ٕज़બఆ

Slide 9

Slide 9 text

41"ʹ͢Δཧ༝ w /JOUFOEP4XJUDI0OMJOFΞϓϦ಺ͷαʔϏε w ΞϓϦʹظ଴͞ΕΔϦονͳମݧ w J04"OESPJEͷ8FC7JFXͰදࣔͰ͖Ε͹Α͍

Slide 10

Slide 10 text

41"ʹ͢Δཧ༝ w αʔϏεͷಛੑ w ࠶๚͕ଟ͍
 ˠΫϥΠΞϯταΠυΩϟογϡͷޮՌ͕ߴ͍ w 17ηογϣϯൺ͕େ͖͍
 ˠॳճͷಡΈࠐΈ଎౓ΑΓͦͷޙͷମݧΛॏࢹ

Slide 11

Slide 11 text

Ұൠతʹ41"Λ࠾༻Ͱ͖Δ͔ w 41"ʹ͢ΔϢʔβʔϝϦοτͱ։ൃ޻਺ͷఱṝ w ૝ఆ͞ΕΔར༻ύλʔϯ͕41"ʹϚον͢Δ͔ w ηογϣϯ೔ɺ17ηογϣϯ͕ଟ͚Ε͹૬ੑ͕͍͍ w ݕࡧ΍4/4͔ΒͷϏδλʔ͕ଟ͚Ε͹ॳճͷಡΈࠐΈΛૣ͘͢Δ w αϙʔτର৅ͷϒϥ΢β w 4&0ͷॏཁੑ

Slide 12

Slide 12 text

࠷ޙ͸༐ؾ w ͍ͥͬͨʹࣗ෼ͰͳΜͱ͔͢Δܾҙ

Slide 13

Slide 13 text

3FBDUͱ3FEVYʹΑΔ
 εςʔτϑϧΞϓϦέʔγϣϯ

Slide 14

Slide 14 text

εςʔτϑϧΞϓϦέʔγϣϯ w )551ϦΫΤετʹରͯ͠)551ϨεϙϯεΛฦ͢
 ˠεςʔτϨε w σʔλϕʔεͰӬଓԽ w ηογϣϯʹΑͬͯ࿈ଓੑΛอͭ w 41"͸(6*ΞϓϦέʔγϣϯ
 ˠεςʔτϑϧ

Slide 15

Slide 15 text

Component Props Component Component Component Component Component Virtual DOM Virtual DOM Virtual DOM Props Props 3FBDU w ΞϓϦέʔγϣϯ͸
 $PNQPOFOUͷू߹ମ w $PNQPOFOU͸ೖྗΛݩʹ
 ৽ͨͳ$PNQPOFOUΛग़ྗ͢Δ
 ؔ਺ͱΈͳͤΔ w ࠷ऴతʹ͸%0.$PNQPOFOUΛ ग़ྗ͢Δ

Slide 16

Slide 16 text

σʔλϑϩʔ w 1SPQT
 ˠ֎෦͔Βͷೖྗ w 4UBUFT
 ˠ$PNQPOFOU಺ͷঢ়ଶ w $POUFYU
 ˠࢠଙ$PNQPOFOUʹ఻ΘΔঢ়ଶ

Slide 17

Slide 17 text

࣌ࠁ import * as React from 'react'; interface TimeProps { time: Date, } export const Time: React.SFC = ({time}) => { return ; };

Slide 18

Slide 18 text

ͭͷ$PNQPOFOU w 4UBUFMFTT'VODUJPOBM$PNQPOFOU w 1VSF$PNQPOFOU w $PNQPOFOU

Slide 19

Slide 19 text

4UBUFMFTT'VODUJPOBM$PNQPOFOU w ؔ਺ w ঢ়ଶΛ࣋ͨͳ͍ Component Props Component Component Props

Slide 20

Slide 20 text

1VSF$PNQPOFOU w Ϋϥε w ঢ়ଶΛ࣋ͭ w 4UBUFT͸JNNVUBCMFͳΦϒδΣΫτ Component Props Component Component Props States

Slide 21

Slide 21 text

$PNQPOFOU w Ϋϥε w ঢ়ଶΛ࣋ͭ w 4UBUFT͸JNNVUBCMFͱ͸ݶΒͳ͍ Component Props Component Component Props States

Slide 22

Slide 22 text

ͭͷ$PNQPOFOU w 4UBUFMFTT'VODUJPOBM$PNQPOFOU͕࠷΋୯७ w 1VSF$PNQPOFOUΛ࢖͏͜ͱ͕ଟ͍

Slide 23

Slide 23 text

*NNVUBCMF w σʔλ͕JNNVUBCMFͰ͋Δํ͕౎߹͕͍͍ w ݹ͍஋ͱ৽͍͠஋͕ಉ͡ͳΒԿ΋͠ͳ͍͍ͯ͘ w *NNVUBCMFͳΦϒδΣΫτ͸===ͰൺֱͰ͖Δ

Slide 24

Slide 24 text

*NNVUBCMF w 0CKFDUBTTJHO
 const newObj = Object.assign({}, oldObj, { key: value }) w 4QSFBE0QFSBUPS
 const newObj = { ...oldObj, key: value } w *NNVUBCMFKT

Slide 25

Slide 25 text

Store Reducer State Action dispatch subscribe 3FEVY w ୯Ұͷ4UPSFʹશͯͷঢ়ଶ w TVCTDSJCFͰมԽΛݕ஌Ͱ͖Δ w 0CTFSWFSύλʔϯ w ঢ়ଶΛม͍͑ͨͱ͖͸
 4UPSFʹ"DUJPOΛૹΔ w 3FEVDFS͕"DUJPOʹԠͯ͡
 ঢ়ଶΛมߋ͢Δ

Slide 26

Slide 26 text

"DUJPO͸ϝιουσΟεύον w "DUJPO͸ϝιουͱύϥϝʔλΛ߹Θͤͨ΋ͷ w "DUJPO$SFBUPSͱݺ͹ΕΔϑΝΫτϦʔؔ਺Ͱ࡞Δ w 3FEVDFS͸4UPSFΛมߋ͢ΔͨΊͷϨγʔό w DPNCJOF3FEVDFSTͰෳ਺ͷ3FEVDFSΛ૊Έ߹Θͤͯ 4UPSFΛ෼ׂ౷࣏͢Δ

Slide 27

Slide 27 text

3FBDU3FEVY Component Component Component Component Virtual DOM Virtual DOM Virtual DOM Props Props Component Component

Slide 28

Slide 28 text

3FBDU3FEVY Connected Provider Connected Component Component Component Component Virtual DOM Virtual DOM Virtual DOM Props Props Component Component

Slide 29

Slide 29 text

3FBDU3FEVY w 1SPWJEFS͕DPOUFYUͰ4UPSFΛࢠଙ$PNQPOFOUʹఏڙ w DPOOFDUؔ਺Ͱ$PNQPOFOUΛ4UPSFͱ઀ଓ w 4UPSFΛTVCTDSJCFͯ͠1SPQTʹม׵͢Δ w ΠϕϯτΛ"DUJPOͱͯ͠4UPSFʹ఻͑Δ w ˠ%*

Slide 30

Slide 30 text

࣌ࠁ import * as React from 'react'; interface TimeProps { time: Date, } export const Time: React.SFC = ({time}) => { return ; };

Slide 31

Slide 31 text

࣌ࠁ import * as React from 'react'; import {connect} from 'react-redux'; interface TimeProps { time: Date, } const Time: React.SFC = ({time}) => { return ; }; export default connect(state => ({ time: state.time }))(Time);

Slide 32

Slide 32 text

3FEVY w ΞϓϦέʔγϣϯશମͷঢ়ଶ w 0CTFSWFSύλʔϯͱ%* w 4UPSFͷઃܭ͕ॏཁ w 3FEVDFSͷ૊Έ߹ΘͤͰ෼ׂ౷࣏ w Կ΋͔΋3FEVYͷ4UPSFʹೖΕΔඞཁ͸ͳ͍

Slide 33

Slide 33 text

8FC"1*ͷϨεϙϯε w 3FEVYͷ4UPSFʹͲ͏อ࣋͢Δͷ͔ w ϦιʔεͷεςʔτϚγϯ w ະऔಘɾ௨৴தɾऔಘࡁΈɾऔಘࣦഊ w RemoteResource

Slide 34

Slide 34 text

3FNPUF3FTPVSDF5 & empty pending resolved failed request succeeded failed reload reload

Slide 35

Slide 35 text

3FNPUF3FTPVSDF5 & w latestValueͱͯ͠࠷ޙͷ஋Λอ͓࣋ͯ͘͠ w Ϧϩʔυதʹ஋͕ফ͑ͳ͍ w औಘʹ੒ޭͨ࣌͠ࠁ΋อ͓࣋ͯ͘͠ͱศར w ߴ֊ؔ਺
 RemoteResource.map((T) -> U) -> RemoteResource

Slide 36

Slide 36 text

3FNPUF3FTPVSDF5 & enum State { EMPTY = "empty", PENDING = "pending", RESOLVED = "resolved", FAILED = "failed", } abstract class RemoteResource { abstract state: State; abstract latestValue: T | null; abstract error: E | null; }

Slide 37

Slide 37 text

3FNPUF3FTPVSDF5 & w ݱࡏͷঢ়ଶʹΑΒͣ࣍ͷঢ়ଶΛද͢࢓૊Έ΋࡞Δ
 RemoteResource.apply(Next) -> RemoteResource w "DUJPOʹ͸Next͚ͩ࣋ͨͤΔ w 3FEVDFS͕apply͢Δ

Slide 38

Slide 38 text

3FEVY4BHB

Slide 39

Slide 39 text

3FEVY w 3FEVY͸ঢ়ଶͷ؅ཧʹಛԽ͍ͯ͠Δ w ࡞༻ w ݱ࣮ͷΞϓϦέʔγϣϯ͸෭࡞༻Λ࣋ͭ

Slide 40

Slide 40 text

3FEVY4BHB w 3FEVYNJEEMFXBSF w ෭࡞༻΍ඇಉظੑΛղܾ͢Δ w (FOFSBUPSGVODUJPO

Slide 41

Slide 41 text

࣌ࠁ const updateTime = createAction('UPDATE_TIME',
 (time: Date) => ({ time: time })); const timeReducer = handleAction(updateTime,
 (state, action) => action.payload!.time, new Date() ); function * ticktack() { while (true) { yield put(updateTime(new Date())); yield delay(1000); } } function * rootSaga() { yield all([ fork(ticktack), ]); }

Slide 42

Slide 42 text

࣌ࠁ const sagaMiddleware = createSagaMiddleware(); const store = createStore( combineReducers({ time: timeReducer, }), applyMiddleware(sagaMiddleware) ); sagaMiddleware.run(rootSaga);

Slide 43

Slide 43 text

࣌ࠁ import * as React from 'react'; import {connect} from 'react-redux'; interface TimeProps { time: Date, } const Time: React.SFC = ({time}) => { return ; }; export default connect(state => ({ time: state.time }))(Time);

Slide 44

Slide 44 text

3FEVY4BHB w 8FC"1*΁ͷΞΫηε w takeF⒎FDUͰGetSomeRequested"DUJPOΛ଴ͭ w ϦΫΤετ͢Δ w putF⒎FDUͰSomeRecieved"DUJPOΛ౤͛Δ

Slide 45

Slide 45 text

8FCϖʔδͱͯ͠ͷ41"

Slide 46

Slide 46 text

8FCϖʔδͱͯ͠ͷ41" w 41"͸8FCϒϥ΢βͰಈ࡞͢Δ w 8FCϒϥ΢βʹ͸8FCಛ༗ͷࣄ৘͕͋Δ w 63- w )JTUPSZ

Slide 47

Slide 47 text

63- w 3FBDU3PVUFSW w શͯͷϖʔδʹ63-ΛׂΓৼΔ w MPDBUJPOͷมԽʹԠͯ͡$PNQPOFOUΛ੾Γସ͑Δ w ։ൃதʹϦϩʔυͰ͖ͯศར w (PPHMF"OBMZUJDTͳͲͱ΋૬ੑ͕Α͍

Slide 48

Slide 48 text

)JTUPSZ w ϒϥ΢βͷʮ໭Δʯ͸௚લͷ৔ॴʹ໭Δ w φϏήʔγϣϯͷʮ໭ΔʯϘλϯ w ҙຯ্ͷ্Ґ֊૚ʹ໭ͬͯ΄͍͠ w ͦ͜Ͱ͞Βʹϒϥ΢βͷʮ໭ΔʯΛԡͨ͠Βʁ ໭Δ

Slide 49

Slide 49 text

)JTUPSZ w ʮ໭Δʯઌ͕௚લͷϖʔδͳΒ
 window.history.back() w ʮ໭Δʯઌ͕௚લͷϖʔδͰͳ͚Ε͹
 window.history.replaceState() A1 A2 A3 B1 B2 C1 C2 A1 A2 B2

Slide 50

Slide 50 text

)JTUPSZ w MPDBUJPOʹIJTUPSZTUBUF΋ؚΊΔ w QVTI4UBUFͰIJTUPSZTUBUFʹ௚લ ͷMPDBUJPOΛอଘ͢Δ w IJTUPSZTUBUF͸ʮ໭ΔʯʮਐΉʯ Ͱ෮ݩ͞ΕΔ w ৗʹ௚લͷϖʔδ͕ಘΒΕΔ export interface Location { pathname: Pathname; search: Search; state: LocationState; hash: Hash; key: LocationKey; } window.history.pushState({ lastLocation: location, }, "A2", "/a/2");

Slide 51

Slide 51 text

·ͱΊ

Slide 52

Slide 52 text

w 41"͸(6*ΞϓϦέʔγϣϯ w ঢ়ଶͷ؅ཧ͕ॏཁ w 3FBDU 3FEVYͳͲΛ͏·͘࢖͏ w ߴ౓ͳϢʔβʔΠϯλʔϑΣʔεΛ࣮ݱͰ͖Δ