{"id":1553,"date":"2021-08-06T14:19:18","date_gmt":"2021-08-06T05:19:18","guid":{"rendered":"http:\/\/www.agile-software.site\/?p=1553"},"modified":"2022-07-17T08:08:57","modified_gmt":"2022-07-16T23:08:57","slug":"redux%e3%81%a8%e3%81%af","status":"publish","type":"post","link":"https:\/\/agile-software.net\/?p=1553","title":{"rendered":"Redux\u3068\u306f"},"content":{"rendered":"\n<p>Redux\u3068\u306f\u3001React.js\u3067\u4f7f\u7528\u3059\u308bstate\u3064\u307e\u308a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u72b6\u614b\u3092\u7ba1\u7406\u3059\u308b\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"reducer\u306b\u3088\u3063\u3066store\u5185\u306estate\u3092\u66f4\u65b0\u3059\u308b\">\u30d5\u30ed\u30fc\u56f3<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"460\" src=\"http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/08\/1-1-1024x460.png\" alt=\"\" class=\"wp-image-1554\" srcset=\"https:\/\/agile-software.net\/wp-content\/uploads\/2021\/08\/1-1-1024x460.png 1024w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/08\/1-1-300x135.png 300w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/08\/1-1-768x345.png 768w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/08\/1-1-1536x691.png 1536w, https:\/\/agile-software.net\/wp-content\/uploads\/2021\/08\/1-1.png 1766w, http:\/\/www.agile-software.site\/wp-content\/uploads\/2021\/08\/1-1-1024x460.png 856w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"redux%E3%81%A8%E3%81%AF\">Redux\u3068\u306f<\/h2>\n\n\n\n<p>Redux\uff08\u30ea\u30c0\u30c3\u30af\u30b9\uff09\u3068\u306f2015\u5e74\u306bDan Abramov\u6c0f\u3068Andrew Clark\u6c0f\u306b\u3088\u3063\u3066\u4f5c\u6210\u3055\u308c\u305f\u72b6\u614b\u7ba1\u7406\u30e9\u30a4\u30d6\u30e9\u30ea\u3002\u5f8c\u8ff0\u3059\u308b<strong>Flux\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3<\/strong>\u306e\u5f71\u97ff\u3092\u53d7\u3051\u3066\u304a\u308a\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3067\u306e\u30c7\u30fc\u30bf\u7ba1\u7406\u3092\u5bb9\u6613\u304b\u3064\u5805\u7262\u306a\u3082\u306e\u306b\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>Redux\u81ea\u4f53\u306f\u7d14\u7c8b\u306aJS\u3067\u66f8\u304b\u308c\u3066\u3044\u308b\u305f\u3081\u3001Vanila JS\u3084jQuery\u3067\u4f7f\u3048\u308b\u306e\u306f\u3082\u3061\u308d\u3093\u3001React\u5c02\u7528\u306eAPI\u304c\u7528\u610f\u3055\u308c\u305f\u300ereact-redux\u300f\u3082\u5b58\u5728\u3057\u3001\u5e45\u5e83\u3044\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u4e0a\u3067\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"flux%E3%81%A8%E3%81%AF\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#flux%E3%81%A8%E3%81%AF\"><\/a>Flux\u3068\u306f<\/h2>\n\n\n\n<p>FaceBook\u793e\u304c\u63d0\u5531\u3057\u3066\u3044\u308b\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u4e0a\u3067\u306e\u30c7\u30fc\u30bf\u30d5\u30ed\u30fc\u7ba1\u7406\u306e\u305f\u3081\u306e\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u30d1\u30bf\u30fc\u30f3\u3002<\/p>\n\n\n\n<p>View, Action, Dispatcher, Store\u306e4\u3064\u306e\u8981\u7d20\u3067\u69cb\u6210\u3055\u308c\u3001<strong>\u5358\u65b9\u5411\u3078\u30c7\u30fc\u30bf\u304c\u6d41\u308c\u3066\u3044\u304f\u3053\u3068\u3067\u30c7\u30fc\u30bf\u306e\u6d41\u308c\u3092\u8ffd\u3044\u3084\u3059\u304f\u306a\u308b<\/strong>\u3068\u3044\u3046\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"redux%E3%81%AE%E4%BD%95%E3%81%8C%E3%81%84%E3%81%84%E3%81%AE%E3%81%8B\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#redux%E3%81%AE%E4%BD%95%E3%81%8C%E3%81%84%E3%81%84%E3%81%AE%E3%81%8B\"><\/a>Redux\u306e\u4f55\u304c\u3044\u3044\u306e\u304b<\/h2>\n\n\n\n<p>\u6c42\u3081\u3089\u308c\u308b\u8981\u4ef6\u304c\u8907\u96d1\u3067\u3042\u308c\u3070\u3042\u308b\u7a0b\u3001Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u72b6\u614b\u7ba1\u7406\u3082\u96e3\u3057\u304f\u306a\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u5c0f\u4e2d\u898f\u6a21\u306eWeb\u30b5\u30a4\u30c8\u306a\u3089\u6bd4\u8f03\u7684\u5c11\u306a\u3044state\u7ba1\u7406\u3067\u6e08\u307f\u307e\u3059\u304c\u3001\u591a\u304f\u306e\u6a5f\u80fd\u3092\u60f3\u5b9a\u3057\u305fWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306a\u3089\u6570\u591a\u304f\u306eState\u3092\u62b1\u3048\u308b\u3053\u3068\u306b\u306a\u308a\u3001\u7ba1\u7406\u304c\u5927\u5909\u304b\u3064\u7169\u96d1\u306b\u306a\u308a\u304c\u3061\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u3053\u3067Redux\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3067\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u4e0a\u3067\u306estate\u7ba1\u7406\u3092\u7c21\u7d20\u306a\u3082\u306e\u306b\u3057\u3001\u5805\u7262\u6545\u306b\u30d0\u30b0\u3082\u767a\u751f\u3057\u306b\u304f\u304f\u306a\u308b\u306a\u3069\u591a\u304f\u306e\u30e1\u30ea\u30c3\u30c8\u3092\u3082\u305f\u3089\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"redux%E3%81%AE%E3%82%B3%E3%82%A2%E3%82%B3%E3%83%B3%E3%82%BB%E3%83%97%E3%83%88\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#redux%E3%81%AE%E3%82%B3%E3%82%A2%E3%82%B3%E3%83%B3%E3%82%BB%E3%83%97%E3%83%88\"><\/a>Redux\u306e\u30b3\u30a2\u30b3\u30f3\u30bb\u30d7\u30c8<\/h3>\n\n\n\n<p>Redux\u306f\u305d\u306e\u8907\u96d1\u5316\u3057\u3066\u3044\u304f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b89\u5168\u306b\u7ba1\u7406\u3059\u308b\u305f\u3081\u306e\u4e09\u5927\u539f\u5247\u3092\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u3002<br><a href=\"https:\/\/redux.js.org\/understanding\/thinking-in-redux\/three-principles\">Core Concepts | Redux<\/a><\/p>\n\n\n\n<p>\u4e00\u3064\u76ee\u306f<strong>\u4fe1\u983c\u3067\u304d\u308b\u552f\u4e00\u306e\u60c5\u5831\u6e90<\/strong>\u3067\u3042\u308b\u3053\u3068\u3002<br>Redux\u3067\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u72b6\u614b\u3092state\u3068\u547c\u3070\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30c4\u30ea\u30fc\u3068\u3057\u3066\u7ba1\u7406\u3057\u3001Store\u5185\u306b\u683c\u7d0d\u3057\u307e\u3059\u3002state\u306f\u5ba3\u8a00\u7684\u3067\u3042\u308a\u3001\u53ef\u8996\u5316\u3055\u308c\u308b\u306e\u3067\u3069\u306e\u3088\u3046\u306a\u30c7\u30fc\u30bf\u304c\u5b58\u5728\u3057\u3001\u3069\u306e\u3088\u3046\u306b\u4f7f\u7528\u3055\u308c\u3066\u3044\u308b\u304b\u5bb9\u6613\u306b\u628a\u63e1\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>state = {\n  menuState: true,\n  modalState: false,\n  count: 0\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u4e8c\u3064\u76ee\u306f<strong>\u72b6\u614b\u306fRead Only\uff08\u8aad\u307f\u53d6\u308a\u5c02\u7528\uff09<\/strong>&nbsp;\u3067\u3042\u308b\u3053\u3068\u3002<br>\u57fa\u672c\u7684\u306bstate\u306b\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3057\u3066\u5024\u3092\u66f8\u304d\u63db\u3048\u308b\u3053\u3068\u306f\u8a31\u53ef\u3055\u308c\u3066\u304a\u3089\u305a\u3001\u5909\u66f4\u3059\u308b\u306b\u306fAction\u3068\u547c\u3070\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u767a\u884c\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u5024\u306e\u5909\u66f4\u65b9\u6cd5\u306f\u4e00\u5143\u5316\u3055\u308c\u3001\u3044\u305f\u305a\u3089\u306b\u4e0d\u5177\u5408\u304c\u8d77\u304d\u308b\u53ef\u80fd\u6027\u304c\u5c11\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>Action = {\n  type: &#39;ACTION_TYPE_NAME&#39;\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u6700\u5f8c\u306b<strong>\u72b6\u614b\u306e\u5909\u66f4\u306f\u7d14\u7c8b\u95a2\u6570\u3067\u884c\u308f\u308c\u308b<\/strong>\u3053\u3068\u3067\u3059\u3002<br>state\u3092\u3069\u306e\u3088\u3046\u306b\u5909\u66f4\u3059\u308b\u304b\u306fReducer\u3068\u3044\u3046\u7d14\u7c8b\u95a2\u6570\uff08\u5024\u306e\u5165\u51fa\u529b\u306e\u904e\u7a0b\u3067\u4e00\u5207\u306e\u5909\u5316\u3092\u4e0e\u3048\u306a\u3044\u5024\u4e0d\u5909\u306e\u95a2\u6570\uff09\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002Reducer\u306b\u5f15\u304d\u6e21\u3055\u308c\u305fAction\u3068Store\u5185\u306b\u4fdd\u6301\u3057\u3066\u3044\u308bstate\u3092\u4f7f\u7528\u3057\u3001<strong>\u65b0\u3057\u3044state\u3092\u751f\u6210<\/strong>\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n<\/code><\/pre>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>reducer = function(state, action){\n  switch (action.type) {\n    case &#39;ACTION_TYPE_NAME&#39;:\n      return {\n          ...state,\n          value: &#39;CHANGE_VALUE&#39;\n      }\n    default:\n      return state;\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E3%83%87%E3%83%BC%E3%82%BF%E3%83%95%E3%83%AD%E3%83%BC%E3%82%92%E7%90%86%E8%A7%A3%E3%81%99%E3%82%8B\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#%E3%83%87%E3%83%BC%E3%82%BF%E3%83%95%E3%83%AD%E3%83%BC%E3%82%92%E7%90%86%E8%A7%A3%E3%81%99%E3%82%8B\"><\/a>\u30c7\u30fc\u30bf\u30d5\u30ed\u30fc\u3092\u7406\u89e3\u3059\u308b<\/h2>\n\n\n\n<p>Redux\u306b\u767b\u5834\u3059\u308b\u4e3b\u306a\u8981\u7d20\u306f\u4ee5\u4e0b\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Store<\/strong>\uff08state\u3092\u4fdd\u5b58\u3057\u3066\u304a\u304f\u8981\u7d20\u3001\u5185\u90e8\u306bReducer\u3092\u4fdd\u6301\u3059\u308b\uff09<\/li><li><strong>Reducer<\/strong>\uff08Action\u3092\u53d7\u3051\u53d6\u308a\u3001\u65e2\u5b58\u306estate\u3068Action\u3092\u5229\u7528\u3057\u3066\u65b0\u305f\u306astate\u3092\u4f5c\u6210\u3059\u308b\u8981\u7d20\uff09<\/li><li><strong>Dispatch<\/strong>\uff08View\u306a\u3069\u304b\u3089Action\u3092\u53d7\u3051\u53d6\u308a\u3001Store\uff08\u6b63\u3057\u304f\u306f\u5185\u90e8\u306eReducer\uff09\u3078\u9001\u4fe1\u3059\u308b\u8981\u7d20\uff09<\/li><li><strong>Action<\/strong>\uff08\u5909\u66f4\u5185\u5bb9\u3092\u5185\u90e8\u306b\u542b\u3080\u8981\u7d20\u3067\u3042\u308a\u3001Dispatch\u306b\u3088\u3063\u3066\u9001\u4fe1\u3055\u308c\u308b\u3002\u57fa\u672c\u7684\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5f62\u5f0f\uff09<\/li><li><strong>state<\/strong>\uff08Store\u5185\u3067\u4fdd\u6301\u3055\u308c\u308b\u8981\u7d20\u3002\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u72b6\u614b\u3092\u6a21\u3057\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066\u6271\u308f\u308c\u308b\uff09<\/li><\/ul>\n\n\n\n<p>\u305d\u308c\u305e\u308c\u306e\u8981\u7d20\u304c\u5f79\u5272\u3092\u6301\u3061\u3001<strong>\u5358\u65b9\u5411\u306e\u30c7\u30fc\u30bf\u30d5\u30ed\u30fc\u3092\u5f62\u6210<\/strong>\u3057\u3066\u3044\u307e\u3059\u3002<br>store\u306b\u79c1\u306e\u9280\u884c\u6b8b\u9ad8\u60c5\u5831\u306e<code>state<\/code>\u304c\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>{\n  userName: &quot;\u307f\u3093\u3061\u3083\u3093&quot;,\n  id: &quot;abcd123&quot;,\n  money: 0,\n}<\/code><\/pre><\/div>\n\n\n\n<p>state\u3092\u5909\u66f4\u3057\u305f\u3044\u306a\u3089\u3001\u307e\u305aaction\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305aView\u3084API\u306a\u3069\u304b\u3089\u5909\u66f4\u5185\u5bb9\u3092\u8a18\u3057\u305fAction(ActionCreators\u306b\u3088\u3063\u3066\u751f\u6210)\u304c\u767a\u884c\u3055\u308c\u3001Dispatch\u306b\u5f15\u304d\u6e21\u3055\u308c\u307e\u3059\u3002\uff08Action\u306fReducer\u306e\u51e6\u7406\u306b\u4f7f\u7528\u3059\u308btype\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4fdd\u6301\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4eca\u6b8b\u9ad8\u304c0\u3067\u3059\u304c\u300110\u00a5\u3092\u5165\u91d1\u3057\u305f\u3044\u3067\u3059\u3002\u305d\u306e\u305f\u3081\u306b\u306fmoney\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u306d\u3002\u3053\u308c\u3092action\u306b\u8a18\u8ff0\u3057\u305f\u3089\u3053\u3046\u306a\u308b\u3067\u3057\u3087\u3046\u3002type\u306faction\u306e\u540d\u524d\u3067\u3001\u4f55\u3092\u3059\u308b\u304b\u3092\u66f8\u304d\u307e\u3059\u3002\u4eca\u56de\u306f\u5165\u91d1\u3059\u308b\u306e\u3067DEPOSIT_MONEY\u306b\u3057\u307e\u3057\u305f\u3002\u91d1\u984d\u306f10\u3067\u3059\u3002<\/code><\/pre>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>{\n  type: &quot;DEPOSIT_MONEY&quot;,\n  payload: 10,\n}<\/code><\/pre><\/div>\n\n\n\n<p><code>dispatch<\/code>\u306f<code>action<\/code>\u3092<code>reducer<\/code>\u307e\u3067\u9001\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>Action\u3092\u53d7\u3051\u53d6\u3063\u305fStore\u306f\u5185\u90e8\u306eReducer\u306bAction\u3092\u5f15\u304d\u6e21\u3057\u3001Action\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306etype\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u3088\u3063\u3066\u5909\u66f4\u3059\u308b\u5024\u3092\u6c7a\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-jin-gb-block-box-with-headline kaisetsu-box1\"><div class=\"kaisetsu-box1-title\">Reducer\u3068\u306f<\/div>\n<p>Action\u3092\u5143\u306bState\u3092\u66f4\u65b0\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3002<br><code>reducer<\/code>\u306f<code>action<\/code>\u3092\u7406\u89e3\u3057\u3001<code>store<\/code>\u306b\u3042\u308b<code>state<\/code>\u3092\u66f4\u65b0\u3059\u308b\u306e\u3067<code>action<\/code>\u3068<code>state<\/code>\u3092\u5f15\u6570\u3067\u6e21\u3055\u308c\u307e\u3059\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const reducer = (state, action) =&gt; {\n  switch (action.type) {\n    case &quot;DEPOSIT_MONEY&quot;:\n      return {\n        ...state,\n\tmoney: action.payload,\n      }\n  }\n};<\/code><\/pre><\/div>\n\n\n\n<p>\u305d\u3046\u3057\u3066\u5909\u66f4\u3055\u308c\u305fstate\u306f<code>store.getState()<\/code>\u306b\u3088\u3063\u3066\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001store\u3067\u5909\u66f4\u304c\u8d77\u304d\u305f\u969b\u306b\u901a\u77e5\u3092\u884c\u3046<code>store.subscribe()<\/code>\u3092\u4f75\u7528\u3059\u308b\u3053\u3068\u3067\u5e38\u306b\u6700\u65b0\u306estate\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"createstore%E9%96%A2%E6%95%B0%E3%82%92%E8%A6%97%E3%81%84%E3%81%A6%E3%81%BF%E3%82%8B\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#createstore%E9%96%A2%E6%95%B0%E3%82%92%E8%A6%97%E3%81%84%E3%81%A6%E3%81%BF%E3%82%8B\"><\/a>createStore\u95a2\u6570\u3092\u8997\u3044\u3066\u307f\u308b<\/h2>\n\n\n\n<p>Redux\u306e\u51e6\u7406\u306e\u30b3\u30a2\u90e8\u5206\u306e\u307b\u3068\u3093\u3069\u304ccreateStore\u95a2\u6570\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u6211\u3005\u304cRedux\u3092\u4f7f\u7528\u3059\u308b\u969b\u306b\u306f\u3053\u306ecreateStore\u95a2\u6570\u306e\u5f15\u6570\u306breducer\u3001\u521d\u671fstate\u3001\u30df\u30c9\u30eb\u30a6\u30a7\u30a2\u3092\u6307\u5b9a\uff08reducer\u4ee5\u5916\u306f\u7701\u7565\u53ef\u80fd\uff09\u3057\u3066Store\u3092\u751f\u6210\u3059\u308b\u306e\u3067\u3059\u304c\u3001\u4e2d\u8eab\u3092\u8997\u304f\u3053\u3068\u3067\u7406\u89e3\u304c\u6df1\u307e\u308b\u3068\u601d\u3046\u306e\u3067\u5b9f\u969b\u306b\u30b3\u30fc\u30c9\u3092\u51e6\u7406\u30d6\u30ed\u30c3\u30af\u3054\u3068\u306b\u5207\u308a\u5206\u3051\u306a\u304c\u3089\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"%E5%BC%95%E6%95%B0%E3%83%81%E3%82%A7%E3%83%83%E3%82%AF%E3%81%A8%E5%A4%89%E6%95%B0%E3%81%B8%E3%81%AE%E4%BB%A3%E5%85%A5\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#%E5%BC%95%E6%95%B0%E3%83%81%E3%82%A7%E3%83%83%E3%82%AF%E3%81%A8%E5%A4%89%E6%95%B0%E3%81%B8%E3%81%AE%E4%BB%A3%E5%85%A5\"><\/a>\u5f15\u6570\u30c1\u30a7\u30c3\u30af\u3068\u5909\u6570\u3078\u306e\u4ee3\u5165<\/h3>\n\n\n\n<p>\u3053\u3053\u3067\u306f\u5f15\u6570\u306b\u6307\u5b9a\u3055\u308c\u305f\u5024\u304c\u51e6\u7406\u306b\u9069\u3057\u305f\u578b\u3067\u3042\u308b\u304b\u306e\u30c1\u30a7\u30c3\u30af\u3084\u7701\u7565\u3055\u308c\u305f\u5f15\u6570\u306e\u9806\u5e8f\u306e\u5165\u308c\u66ff\u3048\u3001\u5909\u6570\u3078\u306e\u4ee3\u5165\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5f15\u6570\u306e\u3046\u3061\u3001reducer\u3068preloadedState\u306f\u305d\u306e\u307e\u307e\u5909\u6570\u306b\u4ee3\u5165\u3055\u308c\u307e\u3059\u304c\u3001enhancer\u306b\u95a2\u6570\u3092\u6307\u5b9a\u3059\u308b\u3068createStore\u3092\u30e9\u30c3\u30d7\u3057\u305f\u95a2\u6570\u304c\u8fd4\u5374\u3055\u308c\u3001\u305d\u306e\u307e\u307e\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u969b\u3001enhancer\u306b\u6307\u5b9a\u3055\u308c\u308b\u95a2\u6570\u306f\u623b\u308a\u5024\u304c\u95a2\u6570\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u4f7f\u7528\u3059\u308b\u969b\u306f\u5927\u62b5Redux\u30e9\u30a4\u30d6\u30e9\u30ea\u5185\u90e8\u306e<code>applyMiddleWare()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u306e\u3067\u81ea\u5206\u3067\u95a2\u6570\u3092\u66f8\u304f\u3053\u3068\u306f\u3042\u307e\u308a\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n<\/code><\/pre>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>function createStore(reducer, preloadedState, enhancer) {\n    var _ref2;\n  \n    if (typeof preloadedState === &#39;function&#39; && typeof enhancer === &#39;function&#39; || typeof enhancer === &#39;function&#39; && typeof arguments<img decoding=\"async\" class=\"ranking-number\" src=\"https:\/\/agile-software.net\/wp-content\/themes\/jin\/img\/rank03.png\" \/> === &#39;function&#39;) {\n      throw new Error(&#39;It looks like you are passing several store enhancers to &#39; + &#39;createStore(). This is not supported. Instead, compose them &#39; + &#39;together to a single function.&#39;);\n    }\n  \n    if (typeof preloadedState === &#39;function&#39; && typeof enhancer === &#39;undefined&#39;) {\n      enhancer = preloadedState;\n      preloadedState = undefined;\n    }\n  \n    if (typeof enhancer !== &#39;undefined&#39;) {\n      if (typeof enhancer !== &#39;function&#39;) {\n        throw new Error(&#39;Expected the enhancer to be a function.&#39;);\n      }\n  \n      return enhancer(createStore)(reducer, preloadedState);\n    }\n  \n    if (typeof reducer !== &#39;function&#39;) {\n      throw new Error(&#39;Expected the reducer to be a function.&#39;);\n    }\n  \n    var currentReducer = reducer;\n    var currentState = preloadedState;\n    var currentListeners = [];\n    var nextListeners = currentListeners;\n    var isDispatching = false;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"getstate%E9%96%A2%E6%95%B0\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#getstate%E9%96%A2%E6%95%B0\"><\/a>getState\u95a2\u6570<\/h3>\n\n\n\n<p>getState\u95a2\u6570\u306b\u3088\u3063\u3066store\u5185\u90e8\u306estate\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002currentState\u5909\u6570\u306b\u683c\u7d0d\u3055\u308c\u305f\u5024\u3092\u305d\u306e\u307e\u307e\u8fd4\u5374\u3057\u3066\u3044\u308b\u3060\u3051\u306e\u5358\u7d14\u306a\u51e6\u7406\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>function getState() {\n      if (isDispatching) {\n        throw new Error(&#39;You may not call store.getState() while the reducer is executing. &#39; + &#39;The reducer has already received the state as an argument. &#39; + &#39;Pass it down from the top reducer instead of reading it from the store.&#39;);\n      }\n  \n      return currentState;\n    }<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"subscribe%E9%96%A2%E6%95%B0\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#subscribe%E9%96%A2%E6%95%B0\"><\/a>subscribe\u95a2\u6570<\/h3>\n\n\n\n<p>subscribe\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066state\u304c\u5909\u66f4\u3055\u308c\u305f\u969b\u306b\u3001<strong>\u5f15\u6570\u306b\u6307\u5b9a\u3057\u305flistener\uff08\u95a2\u6570\uff09\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd<\/strong>\u3067\u3059\u3002<\/p>\n\n\n\n<p><code>ensureCanMutateNextListeners()<\/code>\u306b\u3088\u3063\u3066nextListener\u5909\u6570\u306bcurrentListener\u5909\u6570\u306e\u30b7\u30e3\u30ed\u30fc\u30b3\u30d4\u30fc\u304c\u4ee3\u5165\u3055\u308c\u3001\u5f15\u6570\u306b\u6307\u5b9a\u3055\u308c\u305flistener\u3092nextListener\u5909\u6570\u306b\u4ee3\u5165\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u4fdd\u6301\u3057\u305flistener\u3092unsubscribe\u3067\u524a\u9664\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>function ensureCanMutateNextListeners() {\n      if (nextListeners === currentListeners) {\n        nextListeners = currentListeners.slice();\n      }\n    }\n\nfunction subscribe(listener) {\n      if (typeof listener !== &#39;function&#39;) {\n        throw new Error(&#39;Expected the listener to be a function.&#39;);\n      }\n  \n      if (isDispatching) {\n        throw new Error(&#39;You may not call store.subscribe() while the reducer is executing. &#39; + &#39;If you would like to be notified after the store has been updated, subscribe from a &#39; + &#39;component and invoke store.getState() in the callback to access the latest state. &#39; + &#39;See https:\/\/redux.js.org\/api-reference\/store#subscribelistener for more details.&#39;);\n      }\n  \n      var isSubscribed = true;\n      ensureCanMutateNextListeners();\n      nextListeners.push(listener);\n      return function unsubscribe() {\n        if (!isSubscribed) {\n          return;\n        }\n  \n        if (isDispatching) {\n          throw new Error(&#39;You may not unsubscribe from a store listener while the reducer is executing. &#39; + &#39;See https:\/\/redux.js.org\/api-reference\/store#subscribelistener for more details.&#39;);\n        }\n  \n        isSubscribed = false;\n        ensureCanMutateNextListeners();\n        var index = nextListeners.indexOf(listener);\n        nextListeners.splice(index, 1);\n        currentListeners = null;\n      };\n    }<\/code><\/pre><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>\n   <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"dispatch%E9%96%A2%E6%95%B0\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#dispatch%E9%96%A2%E6%95%B0\"><\/a>dispatch\u95a2\u6570<\/h3>\n\n\n\n<p>dispatch\u95a2\u6570\u306fstate\u3092\u5909\u66f4\u3067\u304d\u308b\u552f\u4e00\u306e\u95a2\u6570\u3067\u3059\u3002<strong>action\u3092\u5f15\u6570\u306b\u3068\u308a\u3001currentReducer\u5909\u6570\u306bcurrentState\u3068action\u3092\u6e21\u3057\u3066\u65b0\u3057\u3044state\u3092\u751f\u6210<\/strong>\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001<code>store.subscribe()<\/code>\u3067listener\u304c\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306flistener\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><\/code><\/pre>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>function dispatch(action) {\n      if (!isPlainObject(action)) {\n        throw new Error(&#39;Actions must be plain objects. &#39; + &#39;Use custom middleware for async actions.&#39;);\n      }\n  \n      if (typeof action.type === &#39;undefined&#39;) {\n        throw new Error(&#39;Actions may not have an undefined &quot;type&quot; property. &#39; + &#39;Have you misspelled a constant?&#39;);\n      }\n  \n      if (isDispatching) {\n        throw new Error(&#39;Reducers may not dispatch actions.&#39;);\n      }\n  \n      try {\n        isDispatching = true;\n        currentState = currentReducer(currentState, action);\n      } finally {\n        isDispatching = false;\n      }\n  \n      var listeners = currentListeners = nextListeners;\n  \n      for (var i = 0; i &lt; listeners.length; i++) {\n        var listener = listeners[i];\n        listener();\n      }\n  \n      return action;\n    }<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"replacereducer%E9%96%A2%E6%95%B0\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#replacereducer%E9%96%A2%E6%95%B0\"><\/a>replaceReducer\u95a2\u6570<\/h3>\n\n\n\n<p>\u3053\u3061\u3089\u306f\u3068\u3066\u3082\u5358\u7d14\u306a\u95a2\u6570\u3067\u3001<strong>\u73fe\u5728\u306ereducer\u3092\u5f15\u6570\u306b\u6307\u5b9a\u3057\u305freducer\u306b\u7f6e\u304d\u63db\u3048\u308b<\/strong>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002\u3042\u307e\u308a\u4f7f\u3046\u6a5f\u4f1a\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n<\/code><\/pre>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>if (typeof nextReducer !== &#39;function&#39;) {\n\tthrow new Error(&#39;Expected the nextReducer to be a function.&#39;);\n}\n  \ncurrentReducer = nextReducer;\n  \ndispatch({type: ActionTypes.REPLACE});<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"%E5%90%84%E9%96%A2%E6%95%B0%E3%82%92%E3%81%BE%E3%81%A8%E3%82%81%E3%81%9F%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%82%92%E8%BF%94%E5%8D%B4\"><a href=\"https:\/\/zenn.dev\/ryotarohada\/articles\/9a677d6f7fdc8e#%E5%90%84%E9%96%A2%E6%95%B0%E3%82%92%E3%81%BE%E3%81%A8%E3%82%81%E3%81%9F%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%82%92%E8%BF%94%E5%8D%B4\"><\/a>\u5404\u95a2\u6570\u3092\u307e\u3068\u3081\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u5374<\/h3>\n\n\n\n<p><code>createStore()<\/code>\u3092\u5b9f\u884c\u3057\u3066\u8fd4\u5374\u3055\u308c\u308b\u306e\u304c\u3053\u3061\u3089\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002<br>\u3053\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\u3057\u3066store\u5185\u306e\u5024\u3092\u5229\u7528\u3059\u308b\u308f\u3051\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>return _ref2 = {\n  dispatch: dispatch,\n  subscribe: subscribe,\n  getState: getState,\n  replaceReducer: replaceReducer\n};<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Redux\u3068\u306f\u3001React.js\u3067\u4f7f\u7528\u3059\u308bstate\u3064\u307e\u308a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u72b6\u614b\u3092\u7ba1\u7406\u3059\u308b\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002 \u30d5\u30ed\u30fc\u56f3 Redux\u3068\u306f Redux\uff08\u30ea\u30c0\u30c3\u30af\u30b9\uff09\u3068\u306f2015\u5e74\u306bDan Abramov\u6c0f\u3068Andrew C<\/p>\n","protected":false},"author":1,"featured_media":1555,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react"],"_links":{"self":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/1553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1553"}],"version-history":[{"count":3,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/1553\/revisions"}],"predecessor-version":[{"id":2066,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/1553\/revisions\/2066"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/media\/1555"}],"wp:attachment":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}