2016å¹´ã®èª²é¡ã¯ç¶æ é·ç§»ã®ç®¡çã ã£ãã¨æãã
ãã®ã¢ã³ãµã¼ã¨ãã¦ã
- Fluxã®ãããªå®è£ ã«ãããStoreç¸å½ã«ã¢ããªã±ã¼ã·ã§ã³ã®ç¶æ ãã»ã¼ãã¹ã¦ç®¡çããã
- Reactã®ãããªVirtual DOMãæè¼ãããã¥ã¼ã®å®è£ ãééçãªã¦ã¼ã¶ã¼ã¤ã³ã¿ã¼ãã§ã¼ã¹ã¨ãã¦æ±ã
ãã®2ã¤ã®çµã¿åããã«ãããã¢ããªã±ã¼ã·ã§ã³ã®ç¶æ ã¨æç»ãããç»é¢ã (ã»ã¼) åç §ééçã«ãªããã¨ããã®ãFluxã¨React以éã®ãã©ãã¤ã ã ã¨æã (çè«ã¨ãã¦) ã
ãã®ãã©ãã¤ã ãªããã¨ã©ã¼ã®çºçæã«ã¢ããªã±ã¼ã·ã§ã³ã®ç¶æ ã表ç¾ããJSONãã¨ã©ã¼åéãµã¼ãã¹ã«éãããã«ãã¦ãç°¡åã«ãã°ãåç¾ãããã§ããããç¶æ ã®é·ç§»ããã¹ããã¦ãããã¨ã§ãã¯ã©ãã·ã¥ãããããªãã°ã®ãã¡å¤§åãæ¤åºã§ããã
Fluxã®åé¡
ããã§åé¡ãåºãã®ããAction(Creator) ã¨Reducer (Store#reduce())ã®2è¦ç´ éã®ã«ã¼ãã ãã§ã¯ãç¾ç¶ããããã±ã¼ã¹ã«å¯¾å¿ã§ããªããã¨ããããã¨ã ã
ä¾ãã°ãã¦ã¼ã¶ã¼å ¥åãèµ·ç¹ã¨ããæéã®ãããããã¯ã°ã©ã¦ã³ãå¦çãè¡ããªãããã¦ã¼ã¶ã¼ã«ã¯ãã¼ãã£ã³ã°è¡¨ç¤ºãªã©ã§é²æããã®æ¨ãä¼ããå¦çã®å®äºæã«çµæãç¨ãã¦ç»é¢ãæ´æ°ããããªã©ã®ã±ã¼ã¹ã§ããã
ãã®å ´åãReducerããActionãå¼ã°ãªããã°ãªããªããªã£ã¦ãã¾ããããã¯Fluxã®ã«ã¼ã«ã«åããéã«ãããç ´ãã°ãFluxããåããããã¡ãªããã®å¤§é¨åã失ã£ã¦ãã¾ãã
éåæçå¦çãåé¡ãªã®ã§ã¯ãªã
ããã«å¯¾ããã¢ã³ãµã¼ãredux-sagaãredux-thunkãredux-observableã®ã¯ãã§ããããã¯ãéåæçå¦çãReduxã§ãã¾ãæ±ããããã®ãã®ã§ã¯ãªã (ãããã¯åããããªãã®ãªã®ã§ã以éã¯redux-sagaãä¾ã«ããã¦è©±ã) ã
ä¸è¨ã®ä¾ã¯åæçãªå¦çã§ãåãåé¡ããããã¦ã¼ã¶ã¼å ¥åããããã¸ãã¹ãã¸ãã¯ã¨ç»é¢åæ ã¸ã®æç¶ãçãªå¦çã®é£ç¶ã«ã¤ãã¦ããã¹ã¦ãReducerã®ä¸ã§ã§ããããããªãã
ããããFluxã¯ãã¼ã¿ããã¼ã§ãã£ã¦ãã³ã³ããã¼ã«ããã¼ãã¢ããªã±ã¼ã·ã§ã³ã¢ã¼ããã¯ãã£ã§ã¯ãªãããããªåéãã¯ãã£ãã¨æ¨ã¦ãã¹ãã ã¨æãã
redux-sagaã«ããã¢ã³ãµã¼
ã¤ã¾ãã¨ãããå è¿°ã®ãããªãã¦ã¼ã¶ã¼å ¥åããè²ããªå¦çãè¡ããç»é¢åæ ããããè¡ããããéã«ãã層ããå¿ è¦ãªããã (以éãããã便å®ä¸ã¦ã¼ã¹ã±ã¼ã¹å±¤ã¨å¼ã¶) ã
redux-sagaã¯ãããReduxã®ããã«ã¦ã§ã¢ã¨ãã¦å®è£ ãã¦ãããsagaã¨å¼ã°ããã¦ã¼ã¹ã±ã¼ã¹å±¤ãç¬èªçãªDSLã«ãã£ã¦ãæç¶ãçãªå¦çã宣è¨çã«æ¸ãã¦ããã
(èµ·ç¹ãActionã§ãsagaã®ã³ã³ããã¼ã«ããã¼ã§ç»é¢åæ ã®ããã«Reducerã«ãã£ã¹ãããããã®ãActionãªã®ã§ãããæ°æã¡æªãæãã¯ããã)
ä»ã®ã¢ããã¼ã
ä½ãWebã¢ããªã±ã¼ã·ã§ã³ã®è¦æ¨¡ãä¸å®ä»¥ä¸ã«ãªã£ã¦ãããªãããã¡ãã¨ããWebã¢ããªã±ã¼ã·ã§ã³ã¢ã¼ããã¯ãã£ãæ§ç¯ããæ¹ãããã
ã¢ããªã±ã¼ã·ã§ã³å ã§ã®å¤ã®ãã¡æ¦å¿µåã§ãããã®ã¯ã¨ã³ãã£ãã£ã¯ã©ã¹ã«ããã¹ãã ããå¤çã¨ã®ããåãã«ã¯ã¢ãã¯ãå¯è½ãªããã«ãµã¼ãã¹ã¯ã©ã¹ã®ãããªãã®ãè¨ããæ¹ãããã
åãããã«ãã¢ããªã±ã¼ã·ã§ã³ã®æ©è½ãã¦ã¼ã¶ã¼ã®ç®ç·ã§ä½ç³»åããã°ãèªç¶ã¨ã¦ã¼ã¹ã±ã¼ã¹å±¤ãå¿ è¦ã«ãªãããã®ä¸ã§å¤çã¨ã®ããåããPromiseã§è¡ããç»é¢åæ ã®ããã«Reducerã«Actionããã£ã¹ãããããã®ã§ãããã
ã¾ã¨ã
Reactã¯ééçã¦ã¼ã¶ã¼ã¤ã³ã¿ã¼ãã§ã¼ã¹ã§ãFluxã¯æéãªã¼ãããã³ã®ããã«èããã¨ãä¸ç¨®ã®ãã©ãã¤ã ã·ããã®ãããªãã®ãæããã
Reduxã¨redux-sagaã¯åãé¢ããªããã®ã§ã¯ãªãããä¸è¦æ¨¡ä»¥ä¸ã®Webã¢ããªã±ã¼ã·ã§ã³ã«ã¯redux-sagaãªã©ã¯æ£ç´ä¸åãã ã¨æãã
ãéåæå¦çãã©ãããããã«æ³¨ç®ãã¦ãã¾ãã¨å ¨ä½ãè¦ããªããªããã¡ã ãã©ãã¤ã¾ãã¨ãããã¦ã¼ã¹ã±ã¼ã¹å±¤ãã®ãããªãã®ã¯å¿ è¦ã§ããããã¨ãªãã¯ããªãã ãã©ãã©ãããããã話ãããã£ã¦ããªãã®ã§çæã¨ãã¦æ¸ããã