{"id":3530,"date":"2024-11-10T08:23:36","date_gmt":"2024-11-10T00:23:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3530\/"},"modified":"2024-11-10T08:23:36","modified_gmt":"2024-11-10T00:23:36","slug":"%e5%a6%82%e4%bd%95%e8%bd%bb%e6%9d%be%e5%88%9b%e5%bb%ba%e5%8f%af%e6%89%a9%e5%b1%95%e7%9a%84%e3%80%81%e5%9f%ba%e4%ba%8e%e6%a8%a1%e5%9d%97%e7%9a%84%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3530\/","title":{"rendered":"\u5982\u4f55\u8f7b\u677e\u521b\u5efa\u53ef\u6269\u5c55\u7684\u3001\u57fa\u4e8e\u6a21\u5757\u7684\u5e94\u7528\u7a0b\u5e8f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173105228517878.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u8f7b\u677e\u521b\u5efa\u53ef\u6269\u5c55\u7684\u3001\u57fa\u4e8e\u6a21\u5757\u7684\u5e94\u7528\u7a0b\u5e8f\u63d2\u56fe\" alt=\"\u5982\u4f55\u8f7b\u677e\u521b\u5efa\u53ef\u6269\u5c55\u7684\u3001\u57fa\u4e8e\u6a21\u5757\u7684\u5e94\u7528\u7a0b\u5e8f\u63d2\u56fe\" \/><\/p>\n<p>\u73b0\u4ee3\u5e94\u7528\u7a0b\u5e8f\u5728\u6a21\u5757\u5316\u67b6\u6784\u4e0a\u84ec\u52c3\u53d1\u5c55\uff0c\u65e0\u7f1d\u9002\u5e94\u4e0d\u65ad\u53d8\u5316\u7684\u4e1a\u52a1\u9700\u6c42\u3002\u7136\u800c\uff0c\u8981\u5b9e\u73b0<strong>\u771f\u6b63\u7684\u6a21\u5757\u5316<\/strong>\uff0c\u60a8\u9700\u8981\u7684\u4e0d\u4ec5\u4ec5\u662f\u72ec\u7acb\u7684\u7ec4\u4ef6 &#8211; \u60a8\u9700\u8981\u4e00\u79cd<strong>\u9ad8\u6548<\/strong>\u65b9\u5f0f\u5c06\u5b83\u4eec\u7ec4\u5408\u5728\u4e00\u8d77\u3002\u8fd9\u610f\u5473\u7740<strong>\u63a7\u5236<\/strong>\u6a21\u5757\u5982\u4f55\u52a0\u8f7d\u3001\u4ee5\u4ec0\u4e48\u987a\u5e8f\u52a0\u8f7d\u4ee5\u53ca\u4f7f\u7528\u54ea\u4e9b\u4f9d\u8d56\u9879\u3002\u5f53\u60a8\u60f3\u8981\u5173\u95ed\u7cfb\u7edf\u7684\u67d0\u4e9b\u90e8\u5206<strong>\u4ee3\u7801\u4e2d\u6ca1\u6709\u4efb\u4f55\u75d5\u8ff9<\/strong>\uff08\u4f8b\u5982 if\/else \u8bed\u53e5\uff09\uff0c\u5e76\u4e14\u4e0d\u5f71\u54cd\u5176\u4ed6\u7ec4\u4ef6\u7684<strong>\u7a33\u5b9a\u6027<\/strong>\u65f6\uff0c\u4e8b\u60c5\u4f1a\u53d8\u5f97\u66f4\u52a0\u68d8\u624b\u3002<\/p>\n<p>\u6700\u7b80\u5355\u7684\u793a\u4f8b\uff1a\u60f3\u8c61\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u5177\u6709\u8bb8\u591a\u4e92\u8fde\u7684\u529f\u80fd\u3002\u6709\u65f6\uff0c\u60a8\u9700\u8981\u7981\u7528\u5176\u4e2d\u4e4b\u4e00\u3002\u95ee\u9898\u662f\uff1a\u67d0\u4e9b\u529f\u80fd\u53ef\u80fd\u76f4\u63a5\u4f9d\u8d56\u4e8e\u5b83\uff0c\u800c\u5176\u4ed6\u529f\u80fd\u53ef\u80fd\u4f1a\u95f4\u63a5\uff08\u4f20\u9012\u6027\uff09\u53d7\u5230\u5f71\u54cd\u3002\u5982\u679c\u60a8\u5ffd\u7565\u8fd9\u4e9b\u4f9d\u8d56\u9879\uff0c\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u5d29\u6e83\u3002\u5982\u679c\u60a8\u9700\u8981\u7981\u7528\u591a\u4e2a\u529f\u80fd\uff0c\u5219\u7ec4\u5408\u53ef\u80fd\u4f1a\u53d8\u5f97\u590d\u6742\u4e14\u5bb9\u6613\u51fa\u9519\u3002\u7406\u60f3\u7684\u662f\u6709\u4e00\u79cd\u65b9\u6cd5\u53ef\u4ee5\u663e\u5f0f\u5730\u63cf\u8ff0\u529f\u80fd\u4f9d\u8d56\u6027\u5e76\u5b89\u5168\u5730\u7981\u7528\u5b83\u4eec\u800c\u4e0d\u4f1a\u9057\u6f0f\u4efb\u4f55\u5185\u5bb9\u3002<\/p>\n<p>\u6bd4\u5982\u8fd9\u6837<\/p>\n<pre>const user = createcontainer({\n  id: 'user',\n  start: async () =&gt; {\n    const data = await fetchuser();\n\n    return { api: { data } };\n  },\n});\n\nconst accounts = createcontainer({\n  id: 'accounts',\n  dependson: [user],\n  start: async ({ user }) =&gt; {\n    const data = await fetchaccounts({ id: user.data.id });\n\n    return { api: { data } };\n  },\n  enable: ({ user }) =&gt; user.data.id !== null,\n});\n\nconst wallets = createcontainer({\n  id: 'wallets',\n  dependson: [accounts],\n  start: () =&gt; ({ api: null }),\n});\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&#8230;\u5e76\u671f\u5f85\u8fd9\u6837\u7684\u4e8b\u60c5\uff1a<\/p>\n<pre>compose.up start\n\nuser: 'idle',     accounts: 'idle',     wallets: 'idle'\nuser: 'pending',  accounts: 'idle',     wallets: 'idle'\nuser: 'done',     accounts: 'idle',     wallets: 'idle'\n\n# if user.data.id\nuser: 'done',    accounts: 'pending',  wallets: 'idle'\nuser: 'done',    accounts: 'done',     wallets: 'pending'\nuser: 'done',    accounts: 'done',     wallets: 'done'\n\n# else\nuser: 'done',    accounts: 'off',      wallets: 'off'\n\ncompose.up done\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6211\u521b\u5efa\u4e86 @grlt-hub\/app-compose \u5e93\uff0c\u8fd9\u4f7f\u5f97\u8fd9\u6210\u4e3a\u73b0\u5b9e\u3002<\/p>\n<p>\u8be5\u5e93\u63d0\u4f9b\u4e86\u7528\u4e8e\u521b\u5efa\u6a21\u5757\u5e76\u5c06\u5176\u7ec4\u5408\u5230\u5355\u4e2a\u7cfb\u7edf\u4e2d\u7684\u4fbf\u6377\u529f\u80fd\u3002\u6bcf\u4e2a\u6a21\u5757\u90fd\u5c01\u88c5\u5728\u4e00\u4e2a\u5bb9\u5668\u4e2d\uff0c\u914d\u7f6e\u6e05\u6670\uff0c\u5305\u62ecid\u3001dependson\u3001optionaldependson\u3001start\u3001enable\u7b49\u53c2\u6570\u3002\u5f00\u53d1\u4eba\u5458\u4f7f\u7528 compose.up fn \u63cf\u8ff0\u5bb9\u5668\u5e76\u542f\u52a8\u5b83\u4eec\uff0c\u800c\u65e0\u9700\u62c5\u5fc3\u6267\u884c\u987a\u5e8f\u3002\u8fd9\u79cd\u65b9\u6cd5\u4f7f\u5bb9\u5668\u7684\u4f7f\u7528\u53d8\u5f97\u76f4\u89c2\u4e14\u63a5\u8fd1\u81ea\u7136\u8bed\u8a00\u3002<\/p>\n<ul>\n<li>\u63d0\u4f9b<strong>\u7b80\u5355\u76f4\u89c2\u7684\u5f00\u53d1\u8005\u4f53\u9a8c (dx)<\/strong>\u3002<\/li>\n<li>\u8bbe\u8ba1\u91cd\u70b9\u5173\u6ce8<strong>\u8d28\u91cf<\/strong>\u548c<strong>\u6027\u80fd<\/strong>\u3002<\/li>\n<li>\u91cd\u91cf\u5c0f\u4e8e<strong>1.5 kb<\/strong>\uff0c\u91cd\u91cf\u8f7b\u3002<\/li>\n<li>\u901a\u8fc7<strong>100% \u6d4b\u8bd5<\/strong>\uff0c\u5305\u62ec<strong>\u7c7b\u578b\u6d4b\u8bd5<\/strong>\u3002<\/li>\n<li>\u786e\u4fdd\u9ad8\u6027\u80fd\uff0c\u9002\u5408<strong>\u53ef\u6269\u5c55\u5e94\u7528\u7a0b\u5e8f<\/strong>\u3002<\/li>\n<li>\u5305\u62ec<strong>\u8c03\u8bd5\u5de5\u5177<\/strong>\u4ee5\u4fc3\u8fdb\u5f00\u53d1\u8fc7\u7a0b\u3002<\/li>\n<li>\u63d0\u4f9b\u4e86<strong>\u53ef\u89c6\u5316\u7cfb\u7edf<\/strong>\u6709\u6548\u5730\u7531\u5bb9\u5668\u7ec4\u6210\u7684\u80fd\u529b\uff08\u5305\u62ec\u4f20\u9012\u4f9d\u8d56\u9879\u53ca\u5176\u8def\u5f84\uff09\u3002<\/li>\n<li>\u9075\u5faa<strong>\u8bed\u4e49\u7248\u672c\u63a7\u5236<\/strong> (semver)\uff0c\u4fdd\u8bc1\u6bcf\u4e2a\u7248\u672c\u7684<strong>\u7a33\u5b9a\u6027<\/strong>\u548c<strong>\u53ef\u9884\u6d4b\u6027<\/strong>\u53d8\u5316\u3002<\/li>\n<\/ul>\n<p>\u51c6\u5907\u597d\u7b80\u5316\u60a8\u7684\u6a21\u5757\u5316\u67b6\u6784\u4e86\u5417\uff1f\u6df1\u5165\u7814\u7a76\u5e94\u7528\u7a0b\u5e8f\u7ec4\u5408\u5e76\u4f53\u9a8c\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u7684\u4f9d\u8d56\u5173\u7cfb\u7ba1\u7406\u3002\u68c0\u67e5\u4e00\u4e0b\u5e76\u8ba9\u6211\u4eec\u77e5\u9053\u5b83\u5982\u4f55\u6539\u53d8\u60a8\u7684\u9879\u76ee\uff01<\/p>\n<ul>\n<li> hub<\/li>\n<li>\u6587\u6863<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u8f7b\u677e\u521b\u5efa\u53ef\u6269\u5c55\u7684\u3001\u57fa\u4e8e\u6a21\u5757\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73b0\u4ee3\u5e94\u7528\u7a0b\u5e8f\u5728\u6a21\u5757\u5316\u67b6\u6784\u4e0a\u84ec\u52c3\u53d1\u5c55\uff0c\u65e0\u7f1d\u9002\u5e94\u4e0d\u65ad\u53d8\u5316\u7684\u4e1a\u52a1\u9700\u6c42\u3002\u7136\u800c\uff0c\u8981\u5b9e\u73b0\u771f\u6b63\u7684\u6a21\u5757\u5316\uff0c\u60a8\u9700\u8981\u7684\u4e0d\u4ec5\u4ec5\u662f\u72ec\u7acb\u7684\u7ec4\u4ef6 &#8211; \u60a8\u9700\u8981\u4e00\u79cd\u9ad8\u6548\u65b9\u5f0f\u5c06\u5b83\u4eec\u7ec4\u5408\u5728\u4e00\u8d77\u3002\u8fd9\u610f\u5473\u7740\u63a7\u5236\u6a21\u5757\u5982\u4f55\u52a0\u8f7d\u3001\u4ee5\u4ec0\u4e48\u987a\u5e8f\u52a0\u8f7d\u4ee5\u53ca\u4f7f\u7528\u54ea\u4e9b\u4f9d\u8d56\u9879\u3002\u5f53\u60a8\u60f3\u8981\u5173\u95ed\u7cfb\u7edf\u7684\u67d0\u4e9b\u90e8\u5206\u4ee3\u7801\u4e2d\u6ca1\u6709\u4efb\u4f55\u75d5\u8ff9\uff08\u4f8b\u5982 if\/else \u8bed\u53e5\uff09\uff0c\u5e76\u4e14\u4e0d\u5f71\u54cd\u5176\u4ed6\u7ec4\u4ef6\u7684\u7a33\u5b9a\u6027\u65f6\uff0c\u4e8b\u60c5\u4f1a\u53d8\u5f97\u66f4\u52a0\u68d8\u624b\u3002 \u6700\u7b80\u5355\u7684\u793a\u4f8b\uff1a\u60f3\u8c61\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u5177\u6709\u8bb8\u591a\u4e92\u8fde\u7684\u529f\u80fd\u3002\u6709\u65f6\uff0c\u60a8\u9700\u8981\u7981\u7528\u5176\u4e2d\u4e4b\u4e00\u3002\u95ee\u9898\u662f\uff1a\u67d0\u4e9b\u529f\u80fd\u53ef\u80fd\u76f4\u63a5\u4f9d\u8d56\u4e8e\u5b83\uff0c\u800c\u5176\u4ed6\u529f\u80fd\u53ef\u80fd\u4f1a\u95f4\u63a5\uff08\u4f20\u9012\u6027\uff09\u53d7\u5230\u5f71\u54cd\u3002\u5982\u679c\u60a8\u5ffd\u7565\u8fd9\u4e9b\u4f9d\u8d56\u9879\uff0c\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u5d29\u6e83\u3002\u5982\u679c\u60a8\u9700\u8981\u7981\u7528\u591a\u4e2a\u529f\u80fd\uff0c\u5219\u7ec4\u5408\u53ef\u80fd\u4f1a\u53d8\u5f97\u590d\u6742\u4e14\u5bb9\u6613\u51fa\u9519\u3002\u7406\u60f3\u7684\u662f\u6709\u4e00\u79cd\u65b9\u6cd5\u53ef\u4ee5\u663e\u5f0f\u5730\u63cf\u8ff0\u529f\u80fd\u4f9d\u8d56\u6027\u5e76\u5b89\u5168\u5730\u7981\u7528\u5b83\u4eec\u800c\u4e0d\u4f1a\u9057\u6f0f\u4efb\u4f55\u5185\u5bb9\u3002 \u6bd4\u5982\u8fd9\u6837 const user = createcontainer({ id: &#8216;user&#8217;, start: async () =&gt; { const data = await fetchuser(); return { api: { data } }; }, }); const accounts = createcontainer({ id: &#8216;accounts&#8217;, dependson: [user], start: async ({ user }) =&gt; { const data = await fetchaccounts({ id: user.data.id }); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3530","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3530"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3530\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}