{"id":1016,"date":"2021-05-04T09:39:00","date_gmt":"2021-05-04T01:39:00","guid":{"rendered":"https:\/\/sora.sound.moe\/?p=1016"},"modified":"2021-05-04T09:39:00","modified_gmt":"2021-05-04T01:39:00","slug":"mobx-state-tree-%e4%bd%bf%e7%94%a8%e6%84%9f%e5%8f%97","status":"publish","type":"post","link":"https:\/\/sora.sound.moe\/?p=1016","title":{"rendered":"mobx-state-tree \u4f7f\u7528\u611f\u53d7"},"content":{"rendered":"\n<!--more-->\n\n\n\n<p>\u5f53React\u9879\u76ee\u7ec4\u7ec7\u590d\u6742\u72b6\u6001\u65f6\uff0c\u6211\u4eec\u603b\u9700\u8981\u5f15\u5165\u4e00\u4e9b\u72b6\u6001\u7ba1\u7406\u5e93\u3002Mobx\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u72b6\u6001\u7ba1\u7406\u5de5\u5177\uff0c\u5b83\u5de7\u5999\u7684\u5c01\u88c5\u8ba9\u72b6\u6001\u7684\u66f4\u65b0\u53d8\u5f97\u66f4\u52a0\u987a\u6ed1\u3002\u4f46\u4f3c\u4e4e\u5728\u66f4\u590d\u6742\u7684\u72b6\u6001\u7ba1\u7406\u4e2d\uff0c\u53ea\u4f7f\u7528Mobx\u8fd8\u4e0d\u591f\u5f97\u52b2\u3002<\/p>\n\n\n\n<p>Mobx-state-tree\u662f\u4e00\u4e2a\u57fa\u4e8eMobx\u7684\u72b6\u6001\u6811\u7ba1\u7406\u5de5\u5177\u3002\u5728\u56fd\u5185\uff0c\u636e\u89c2\u5bdf\uff0c\u8d44\u6599\u6bd4\u8f83\u5c11\uff0c\u7528\u6237\u6570\u91cf\u5e94\u8be5\u4e0d\u5927\u3002<\/p>\n\n\n\n<p>MST\u7684\u601d\u60f3\u662f\u5c06\u72b6\u6001\u7ec4\u4ef6\u5316\uff0c\u590d\u6742\u72b6\u6001\u7531\u66f4\u7b80\u5355\u7684\u5b50\u72b6\u6001\u7ec4\u4ef6\u7ec4\u6210\uff0c\u4e5f\u5c31\u662fTree\u7684\u542b\u4e49\u3002\u6b64\u5916\uff0cMST\u7684\u72b6\u6001\u7ec4\u4ef6\u58f0\u660e\u662f\u51fd\u6570\u5f0f\u7684\uff0c\u5f88\u6709\u610f\u601d\u3002\u7b2c\u4e00\u773c\u770b\u5230MST\u8fd9\u4e2a\u5e93\u7684\u65f6\u5019\uff0c\u89c9\u5f97\u8fd9\u4f3c\u4e4e\u5c31\u662f\u5b8c\u7f8e\u7684\u72b6\u6001\u7ba1\u7406\u65b9\u6848\u4e86\uff0c\u7136\u800c\u5b9e\u9645\u5e94\u7528\u4e86\u4e00\u4e0b\u53d1\u73b0\u8fd8\u662f\u6709\u4e9b\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u8fd9\u95ee\u9898\u4e0d\u662f\u8bf4MST\u672c\u8eab\u8bbe\u8ba1\u7684\u4e0d\u597dor\u4e0d\u591f\u6613\u7528\uff0c\u800c\u662f\u5b9e\u9645\u9879\u76ee\u5f80\u5f80\u4e0d\u5b58\u5728\u8fd9\u4e48\u7406\u60f3\u7684\u73af\u5883\u3002<\/p>\n\n\n\n<p>\u4e00\u662f\u5bf9\u590d\u6742\u7c7b\u578b\u5c24\u5176\u662f\u540e\u7aef\u8fd4\u56de\u6570\u636e\u7684\u5b9a\u4e49\u6bd4\u8f83\u7e41\u7410\uff0c\u6709\u65f6\u5019\u4e0d\u5f97\u4e0d\u4f7f\u7528<code>types.forzen<\/code>\u6765\u5c4f\u853d\u7c7b\u578b\u7ec6\u8282\u3002\u4e8c\u662f\u5f02\u6b65\u7684<code>action<\/code>\u9700\u8981\u4f7f\u7528<code>generator<\/code>\u7684\u5f62\u5f0f+helper function\u6765\u5199\uff0c\u611f\u89c9\u6709\u4e00\u4e9b\u4e0d\u81ea\u7136\uff08\u53ef\u80fd\u662f\u4e2a\u4eba\u559c\u597d\u95ee\u9898\uff09\u3002\u6b64\u5916\u5c31\u662f\u8fd9\u4e2a\u4e00\u957f\u4e32\u7684\u51fd\u6570\u5f0f\u7684\u5b9a\u4e49\u770b\u8d77\u6765\u6709\u70b9\u4e0d\u723d\uff0c\u6709\u79cd\u53c8\u81ed\u53c8\u957f\u7684\u611f\u89c9\uff0c\u5728TypeScript\u4e0b\u66f4\u4e3a\u660e\u663e\uff0c\u5bf9Store\u7684\u7c7b\u578b\u5b9a\u4e49\u6709\u79cd\u91cd\u590d\u5de5\u4f5c\u7684\u611f\u89c9\uff0c\u800c\u4e14\u4e5f\u5931\u53bb\u4e86<code>mobx<\/code>\u7684\u7075\u6d3b\u6613\u7528\u3002<\/p>\n\n\n\n<p>\u6211\u5bf9MST\u7684\u7262\u9a9a\u4e3b\u8981\u8fd8\u662f\u5728\u5b9a\u4e49\u90e8\u5206\uff0c\u4f7f\u7528\u4e0a\u8fd8\u662f\u6ca1\u6709\u4ec0\u4e48\u5947\u602a\u7684\uff0c\u76f4\u63a5\u4ece<code>store<\/code>\u4e0a\u53d6\u503c\u7528\u5c31\u5b8c\u4e8b\u3002\u90a3MST\u7684\u4f18\u70b9\u5462\uff0c\u6211\u770b\u8fd8\u662f\u5728\u8fd9\u4e2a\u6a21\u5757\u5316\u7684\u7ed3\u6784\u4e0a\uff0c\u53ef\u4ee5\u5e2e\u5fd9\u8282\u7701\u4e00\u4e9b\u7ef4\u62a4\u591aStore\u5d4c\u5957\u7684\u590d\u6742\u60c5\u51b5\u7684\u7cbe\u529b\u3002\u81f3\u4e8e\u8fd9\u4e2a\u989d\u5916\u5f15\u5165\u7684\u6982\u5ff5\u548cboilerplate code\u503c\u4e0d\u503c\u5f97\u5462\uff0c\u90a3\u5c31\u5927\u5bb6\u5404\u6709\u60f3\u6cd5\u4e86\uff0c\u8bf4\u5230\u5e95\u8fd8\u662ftrade off\uff0c\u6839\u636e\u9879\u76ee\u5b9e\u9645\u60c5\u51b5\u6765\u5427\u3002\u4e2a\u4eba\u611f\u89c9\u5e26\u6765\u7684\u597d\u5904\u4e0d\u662f\u5f88\u5927\uff0c\u53ef\u80fd\u8fd9\u4e5f\u662fMST\u76ee\u524d\u4e0d\u6e29\u4e0d\u706b\u7684\u539f\u56e0\u5427\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"twentyseventeen-featured-image":false,"twentyseventeen-thumbnail-avatar":false},"uagb_author_info":{"display_name":"Sora","author_link":"https:\/\/sora.sound.moe\/?author=1"},"uagb_comment_info":0,"uagb_excerpt":null,"_links":{"self":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts\/1016"}],"collection":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1016"}],"version-history":[{"count":0,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts\/1016\/revisions"}],"wp:attachment":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}