[{"data":1,"prerenderedAt":6737},["Reactive",2],{"article-20240516":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"published":10,"categories":11,"slug":8,"body":13,"_type":6732,"_id":6733,"_source":6734,"_file":6735,"_extension":6736},"/articles/20240516","articles",false,"","责任链模式最强工具res-chain","责任链的好处，以及如何封装一个自己的责任链","2024/05/16",[12],"前端开发",{"type":14,"children":15,"toc":6723},"root",[16,27,34,47,59,80,92,525,560,565,570,753,758,763,768,773,778,803,808,826,831,836,1486,1491,1496,2345,2350,2364,2377,2856,2869,2875,2894,2910,3583,3595,4407,4425,4437,4442,5025,5034,5046,5090,5095,5100,5757,5762,6117,6144,6149,6163,6213,6218,6621,6626,6631,6636,6641,6667,6672,6677,6682,6687,6692,6703,6708,6717],{"type":17,"tag":18,"props":19,"children":20},"element","p",{},[21],{"type":17,"tag":22,"props":23,"children":26},"img",{"alt":24,"src":25},"Pasted image 20240515003946","https://johnhom-img.oss-cn-guangzhou.aliyuncs.com/images/Pasted%20image%2020240515003946.png",[],{"type":17,"tag":28,"props":29,"children":31},"h2",{"id":30},"责任链模式介绍",[32],{"type":33,"value":30},"text",{"type":17,"tag":18,"props":35,"children":36},{},[37,39,45],{"type":33,"value":38},"责任链模式（Chain of Responsibility Pattern）是一种行为型设计模式，",{"type":17,"tag":40,"props":41,"children":42},"strong",{},[43],{"type":33,"value":44},"它通过把请求的发送者和接收者解耦，将多个对象连接成一个链，并沿着这条链传递请求，直到有一个对象能够处理它为止，从而避免了请求的发送者和接收者之间的直接耦合",{"type":33,"value":46},"。",{"type":17,"tag":18,"props":48,"children":49},{},[50,52,57],{"type":33,"value":51},"在责任链模式中，",{"type":17,"tag":40,"props":53,"children":54},{},[55],{"type":33,"value":56},"每个处理者都持有对下一个处理者的引用",{"type":33,"value":58},"，即构成一个链表结构。当请求从链头开始流经链上的每个处理者时，如果某个处理者能够处理该请求，就直接处理，否则将请求发送给下一个处理者，直到有一个处理者能够处理为止。这种方式可以灵活地动态添加或修改请求的处理流程，同时也避免了由于请求类型过多而导致类的爆炸性增长的问题。",{"type":17,"tag":18,"props":60,"children":61},{},[62,64,71,73,78],{"type":33,"value":63},"看完以上责任链的描述，有没有发现跟Node.js的某些库特别的像，没错，就是",{"type":17,"tag":65,"props":66,"children":68},"code",{"className":67},[],[69],{"type":33,"value":70},"koa",{"type":33,"value":72},"。什么？没用过",{"type":17,"tag":65,"props":74,"children":76},{"className":75},[],[77],{"type":33,"value":70},{"type":33,"value":79},"？那我建议你立马学起来，因为它用起来特别的简单。",{"type":17,"tag":18,"props":81,"children":82},{},[83,85,90],{"type":33,"value":84},"下面来一个简单使用",{"type":17,"tag":65,"props":86,"children":88},{"className":87},[],[89],{"type":33,"value":70},{"type":33,"value":91},"的例子：",{"type":17,"tag":93,"props":94,"children":98},"pre",{"className":95,"code":96,"language":97,"meta":7,"style":7},"language-js shiki shiki-themes github-dark","const Koa = require('koa');\nconst app = new Koa();\n\napp.use(async (ctx, next) => {\n  if (ctx.request.url === '/') {\n    ctx.body = 'home';\n    return;\n  }\n  \n  next(); // 执行下面的回调函数\n});\n\napp.use(async (ctx, next) => {\n  if (ctx.request.url === '/hello') {\n    ctx.body = 'hello world';\n    return;\n  }\n});\n\napp.listen(3000);\n","js",[99],{"type":17,"tag":65,"props":100,"children":101},{"__ignoreMap":7},[102,148,179,189,248,277,301,314,323,332,352,361,369,417,442,463,475,483,491,499],{"type":17,"tag":103,"props":104,"children":107},"span",{"class":105,"line":106},"line",1,[108,114,120,125,131,137,143],{"type":17,"tag":103,"props":109,"children":111},{"style":110},"--shiki-default:#F97583",[112],{"type":33,"value":113},"const",{"type":17,"tag":103,"props":115,"children":117},{"style":116},"--shiki-default:#79B8FF",[118],{"type":33,"value":119}," Koa",{"type":17,"tag":103,"props":121,"children":122},{"style":110},[123],{"type":33,"value":124}," =",{"type":17,"tag":103,"props":126,"children":128},{"style":127},"--shiki-default:#B392F0",[129],{"type":33,"value":130}," require",{"type":17,"tag":103,"props":132,"children":134},{"style":133},"--shiki-default:#E1E4E8",[135],{"type":33,"value":136},"(",{"type":17,"tag":103,"props":138,"children":140},{"style":139},"--shiki-default:#9ECBFF",[141],{"type":33,"value":142},"'koa'",{"type":17,"tag":103,"props":144,"children":145},{"style":133},[146],{"type":33,"value":147},");\n",{"type":17,"tag":103,"props":149,"children":151},{"class":105,"line":150},2,[152,156,161,165,170,174],{"type":17,"tag":103,"props":153,"children":154},{"style":110},[155],{"type":33,"value":113},{"type":17,"tag":103,"props":157,"children":158},{"style":116},[159],{"type":33,"value":160}," app",{"type":17,"tag":103,"props":162,"children":163},{"style":110},[164],{"type":33,"value":124},{"type":17,"tag":103,"props":166,"children":167},{"style":110},[168],{"type":33,"value":169}," new",{"type":17,"tag":103,"props":171,"children":172},{"style":127},[173],{"type":33,"value":119},{"type":17,"tag":103,"props":175,"children":176},{"style":133},[177],{"type":33,"value":178},"();\n",{"type":17,"tag":103,"props":180,"children":182},{"class":105,"line":181},3,[183],{"type":17,"tag":103,"props":184,"children":186},{"emptyLinePlaceholder":185},true,[187],{"type":33,"value":188},"\n",{"type":17,"tag":103,"props":190,"children":192},{"class":105,"line":191},4,[193,198,203,207,212,217,223,228,233,238,243],{"type":17,"tag":103,"props":194,"children":195},{"style":133},[196],{"type":33,"value":197},"app.",{"type":17,"tag":103,"props":199,"children":200},{"style":127},[201],{"type":33,"value":202},"use",{"type":17,"tag":103,"props":204,"children":205},{"style":133},[206],{"type":33,"value":136},{"type":17,"tag":103,"props":208,"children":209},{"style":110},[210],{"type":33,"value":211},"async",{"type":17,"tag":103,"props":213,"children":214},{"style":133},[215],{"type":33,"value":216}," (",{"type":17,"tag":103,"props":218,"children":220},{"style":219},"--shiki-default:#FFAB70",[221],{"type":33,"value":222},"ctx",{"type":17,"tag":103,"props":224,"children":225},{"style":133},[226],{"type":33,"value":227},", ",{"type":17,"tag":103,"props":229,"children":230},{"style":219},[231],{"type":33,"value":232},"next",{"type":17,"tag":103,"props":234,"children":235},{"style":133},[236],{"type":33,"value":237},") ",{"type":17,"tag":103,"props":239,"children":240},{"style":110},[241],{"type":33,"value":242},"=>",{"type":17,"tag":103,"props":244,"children":245},{"style":133},[246],{"type":33,"value":247}," {\n",{"type":17,"tag":103,"props":249,"children":251},{"class":105,"line":250},5,[252,257,262,267,272],{"type":17,"tag":103,"props":253,"children":254},{"style":110},[255],{"type":33,"value":256},"  if",{"type":17,"tag":103,"props":258,"children":259},{"style":133},[260],{"type":33,"value":261}," (ctx.request.url ",{"type":17,"tag":103,"props":263,"children":264},{"style":110},[265],{"type":33,"value":266},"===",{"type":17,"tag":103,"props":268,"children":269},{"style":139},[270],{"type":33,"value":271}," '/'",{"type":17,"tag":103,"props":273,"children":274},{"style":133},[275],{"type":33,"value":276},") {\n",{"type":17,"tag":103,"props":278,"children":280},{"class":105,"line":279},6,[281,286,291,296],{"type":17,"tag":103,"props":282,"children":283},{"style":133},[284],{"type":33,"value":285},"    ctx.body ",{"type":17,"tag":103,"props":287,"children":288},{"style":110},[289],{"type":33,"value":290},"=",{"type":17,"tag":103,"props":292,"children":293},{"style":139},[294],{"type":33,"value":295}," 'home'",{"type":17,"tag":103,"props":297,"children":298},{"style":133},[299],{"type":33,"value":300},";\n",{"type":17,"tag":103,"props":302,"children":304},{"class":105,"line":303},7,[305,310],{"type":17,"tag":103,"props":306,"children":307},{"style":110},[308],{"type":33,"value":309},"    return",{"type":17,"tag":103,"props":311,"children":312},{"style":133},[313],{"type":33,"value":300},{"type":17,"tag":103,"props":315,"children":317},{"class":105,"line":316},8,[318],{"type":17,"tag":103,"props":319,"children":320},{"style":133},[321],{"type":33,"value":322},"  }\n",{"type":17,"tag":103,"props":324,"children":326},{"class":105,"line":325},9,[327],{"type":17,"tag":103,"props":328,"children":329},{"style":133},[330],{"type":33,"value":331},"  \n",{"type":17,"tag":103,"props":333,"children":335},{"class":105,"line":334},10,[336,341,346],{"type":17,"tag":103,"props":337,"children":338},{"style":127},[339],{"type":33,"value":340},"  next",{"type":17,"tag":103,"props":342,"children":343},{"style":133},[344],{"type":33,"value":345},"(); ",{"type":17,"tag":103,"props":347,"children":349},{"style":348},"--shiki-default:#6A737D",[350],{"type":33,"value":351},"// 执行下面的回调函数\n",{"type":17,"tag":103,"props":353,"children":355},{"class":105,"line":354},11,[356],{"type":17,"tag":103,"props":357,"children":358},{"style":133},[359],{"type":33,"value":360},"});\n",{"type":17,"tag":103,"props":362,"children":364},{"class":105,"line":363},12,[365],{"type":17,"tag":103,"props":366,"children":367},{"emptyLinePlaceholder":185},[368],{"type":33,"value":188},{"type":17,"tag":103,"props":370,"children":372},{"class":105,"line":371},13,[373,377,381,385,389,393,397,401,405,409,413],{"type":17,"tag":103,"props":374,"children":375},{"style":133},[376],{"type":33,"value":197},{"type":17,"tag":103,"props":378,"children":379},{"style":127},[380],{"type":33,"value":202},{"type":17,"tag":103,"props":382,"children":383},{"style":133},[384],{"type":33,"value":136},{"type":17,"tag":103,"props":386,"children":387},{"style":110},[388],{"type":33,"value":211},{"type":17,"tag":103,"props":390,"children":391},{"style":133},[392],{"type":33,"value":216},{"type":17,"tag":103,"props":394,"children":395},{"style":219},[396],{"type":33,"value":222},{"type":17,"tag":103,"props":398,"children":399},{"style":133},[400],{"type":33,"value":227},{"type":17,"tag":103,"props":402,"children":403},{"style":219},[404],{"type":33,"value":232},{"type":17,"tag":103,"props":406,"children":407},{"style":133},[408],{"type":33,"value":237},{"type":17,"tag":103,"props":410,"children":411},{"style":110},[412],{"type":33,"value":242},{"type":17,"tag":103,"props":414,"children":415},{"style":133},[416],{"type":33,"value":247},{"type":17,"tag":103,"props":418,"children":420},{"class":105,"line":419},14,[421,425,429,433,438],{"type":17,"tag":103,"props":422,"children":423},{"style":110},[424],{"type":33,"value":256},{"type":17,"tag":103,"props":426,"children":427},{"style":133},[428],{"type":33,"value":261},{"type":17,"tag":103,"props":430,"children":431},{"style":110},[432],{"type":33,"value":266},{"type":17,"tag":103,"props":434,"children":435},{"style":139},[436],{"type":33,"value":437}," '/hello'",{"type":17,"tag":103,"props":439,"children":440},{"style":133},[441],{"type":33,"value":276},{"type":17,"tag":103,"props":443,"children":445},{"class":105,"line":444},15,[446,450,454,459],{"type":17,"tag":103,"props":447,"children":448},{"style":133},[449],{"type":33,"value":285},{"type":17,"tag":103,"props":451,"children":452},{"style":110},[453],{"type":33,"value":290},{"type":17,"tag":103,"props":455,"children":456},{"style":139},[457],{"type":33,"value":458}," 'hello world'",{"type":17,"tag":103,"props":460,"children":461},{"style":133},[462],{"type":33,"value":300},{"type":17,"tag":103,"props":464,"children":466},{"class":105,"line":465},16,[467,471],{"type":17,"tag":103,"props":468,"children":469},{"style":110},[470],{"type":33,"value":309},{"type":17,"tag":103,"props":472,"children":473},{"style":133},[474],{"type":33,"value":300},{"type":17,"tag":103,"props":476,"children":478},{"class":105,"line":477},17,[479],{"type":17,"tag":103,"props":480,"children":481},{"style":133},[482],{"type":33,"value":322},{"type":17,"tag":103,"props":484,"children":486},{"class":105,"line":485},18,[487],{"type":17,"tag":103,"props":488,"children":489},{"style":133},[490],{"type":33,"value":360},{"type":17,"tag":103,"props":492,"children":494},{"class":105,"line":493},19,[495],{"type":17,"tag":103,"props":496,"children":497},{"emptyLinePlaceholder":185},[498],{"type":33,"value":188},{"type":17,"tag":103,"props":500,"children":502},{"class":105,"line":501},20,[503,507,512,516,521],{"type":17,"tag":103,"props":504,"children":505},{"style":133},[506],{"type":33,"value":197},{"type":17,"tag":103,"props":508,"children":509},{"style":127},[510],{"type":33,"value":511},"listen",{"type":17,"tag":103,"props":513,"children":514},{"style":133},[515],{"type":33,"value":136},{"type":17,"tag":103,"props":517,"children":518},{"style":116},[519],{"type":33,"value":520},"3000",{"type":17,"tag":103,"props":522,"children":523},{"style":133},[524],{"type":33,"value":147},{"type":17,"tag":18,"props":526,"children":527},{},[528,530,536,538,544,546,552,553,559],{"type":33,"value":529},"通过node运行上面的代码，在浏览器请求",{"type":17,"tag":65,"props":531,"children":533},{"className":532},[],[534],{"type":33,"value":535},"localhost:3000",{"type":33,"value":537},"，接口就会返回",{"type":17,"tag":65,"props":539,"children":541},{"className":540},[],[542],{"type":33,"value":543},"home",{"type":33,"value":545},"，当我们请求",{"type":17,"tag":65,"props":547,"children":549},{"className":548},[],[550],{"type":33,"value":551},"localhost:3000/hello",{"type":33,"value":537},{"type":17,"tag":65,"props":554,"children":556},{"className":555},[],[557],{"type":33,"value":558},"hello world",{"type":33,"value":46},{"type":17,"tag":18,"props":561,"children":562},{},[563],{"type":33,"value":564},"上面对请求的处理过程就很符合职责链模式的思想，我们可以清楚的知道每个链做的工作，并且清晰链条的顺序流程。",{"type":17,"tag":18,"props":566,"children":567},{},[568],{"type":33,"value":569},"有人就会问，只在一个回调里面也能处理呀，比如下面的代码：",{"type":17,"tag":93,"props":571,"children":573},{"className":95,"code":572,"language":97,"meta":7,"style":7},"app.use(async (ctx, next) => {\n  if (ctx.request.url === '/') {\n    ctx.body = 'home';\n    return;\n  } else if (ctx.request.url === '/home') {\n    ctx.body = 'hello world';\n    return\n  }\n});\n",[574],{"type":17,"tag":65,"props":575,"children":576},{"__ignoreMap":7},[577,624,647,666,677,712,731,739,746],{"type":17,"tag":103,"props":578,"children":579},{"class":105,"line":106},[580,584,588,592,596,600,604,608,612,616,620],{"type":17,"tag":103,"props":581,"children":582},{"style":133},[583],{"type":33,"value":197},{"type":17,"tag":103,"props":585,"children":586},{"style":127},[587],{"type":33,"value":202},{"type":17,"tag":103,"props":589,"children":590},{"style":133},[591],{"type":33,"value":136},{"type":17,"tag":103,"props":593,"children":594},{"style":110},[595],{"type":33,"value":211},{"type":17,"tag":103,"props":597,"children":598},{"style":133},[599],{"type":33,"value":216},{"type":17,"tag":103,"props":601,"children":602},{"style":219},[603],{"type":33,"value":222},{"type":17,"tag":103,"props":605,"children":606},{"style":133},[607],{"type":33,"value":227},{"type":17,"tag":103,"props":609,"children":610},{"style":219},[611],{"type":33,"value":232},{"type":17,"tag":103,"props":613,"children":614},{"style":133},[615],{"type":33,"value":237},{"type":17,"tag":103,"props":617,"children":618},{"style":110},[619],{"type":33,"value":242},{"type":17,"tag":103,"props":621,"children":622},{"style":133},[623],{"type":33,"value":247},{"type":17,"tag":103,"props":625,"children":626},{"class":105,"line":150},[627,631,635,639,643],{"type":17,"tag":103,"props":628,"children":629},{"style":110},[630],{"type":33,"value":256},{"type":17,"tag":103,"props":632,"children":633},{"style":133},[634],{"type":33,"value":261},{"type":17,"tag":103,"props":636,"children":637},{"style":110},[638],{"type":33,"value":266},{"type":17,"tag":103,"props":640,"children":641},{"style":139},[642],{"type":33,"value":271},{"type":17,"tag":103,"props":644,"children":645},{"style":133},[646],{"type":33,"value":276},{"type":17,"tag":103,"props":648,"children":649},{"class":105,"line":181},[650,654,658,662],{"type":17,"tag":103,"props":651,"children":652},{"style":133},[653],{"type":33,"value":285},{"type":17,"tag":103,"props":655,"children":656},{"style":110},[657],{"type":33,"value":290},{"type":17,"tag":103,"props":659,"children":660},{"style":139},[661],{"type":33,"value":295},{"type":17,"tag":103,"props":663,"children":664},{"style":133},[665],{"type":33,"value":300},{"type":17,"tag":103,"props":667,"children":668},{"class":105,"line":191},[669,673],{"type":17,"tag":103,"props":670,"children":671},{"style":110},[672],{"type":33,"value":309},{"type":17,"tag":103,"props":674,"children":675},{"style":133},[676],{"type":33,"value":300},{"type":17,"tag":103,"props":678,"children":679},{"class":105,"line":250},[680,685,690,695,699,703,708],{"type":17,"tag":103,"props":681,"children":682},{"style":133},[683],{"type":33,"value":684},"  } ",{"type":17,"tag":103,"props":686,"children":687},{"style":110},[688],{"type":33,"value":689},"else",{"type":17,"tag":103,"props":691,"children":692},{"style":110},[693],{"type":33,"value":694}," if",{"type":17,"tag":103,"props":696,"children":697},{"style":133},[698],{"type":33,"value":261},{"type":17,"tag":103,"props":700,"children":701},{"style":110},[702],{"type":33,"value":266},{"type":17,"tag":103,"props":704,"children":705},{"style":139},[706],{"type":33,"value":707}," '/home'",{"type":17,"tag":103,"props":709,"children":710},{"style":133},[711],{"type":33,"value":276},{"type":17,"tag":103,"props":713,"children":714},{"class":105,"line":279},[715,719,723,727],{"type":17,"tag":103,"props":716,"children":717},{"style":133},[718],{"type":33,"value":285},{"type":17,"tag":103,"props":720,"children":721},{"style":110},[722],{"type":33,"value":290},{"type":17,"tag":103,"props":724,"children":725},{"style":139},[726],{"type":33,"value":458},{"type":17,"tag":103,"props":728,"children":729},{"style":133},[730],{"type":33,"value":300},{"type":17,"tag":103,"props":732,"children":733},{"class":105,"line":303},[734],{"type":17,"tag":103,"props":735,"children":736},{"style":110},[737],{"type":33,"value":738},"    return\n",{"type":17,"tag":103,"props":740,"children":741},{"class":105,"line":316},[742],{"type":17,"tag":103,"props":743,"children":744},{"style":133},[745],{"type":33,"value":322},{"type":17,"tag":103,"props":747,"children":748},{"class":105,"line":325},[749],{"type":17,"tag":103,"props":750,"children":751},{"style":133},[752],{"type":33,"value":360},{"type":17,"tag":18,"props":754,"children":755},{},[756],{"type":33,"value":757},"是的，上面的代码确实可以实现，但是这就要回到我们使用责任链模式的初衷了：为了逻辑解耦。",{"type":17,"tag":28,"props":759,"children":761},{"id":760},"责任链解决的问题",[762],{"type":33,"value":760},{"type":17,"tag":18,"props":764,"children":765},{},[766],{"type":33,"value":767},"我们继续接着聊上一节的问题，使用if确实可以实现相同效果，但是某些场景用if不如使用职责链的方式实现。",{"type":17,"tag":18,"props":769,"children":770},{},[771],{"type":33,"value":772},"我们来一个应用案例来举个例子：",{"type":17,"tag":18,"props":774,"children":775},{},[776],{"type":33,"value":777},"假设我们负责一个售卖手机的网站，需求的定义是：经过分别缴纳500元定金和200元定金的两轮预订，现在到了正式购买阶段。公司对于交了定金的用户有一定的优惠政策，规则如下：",{"type":17,"tag":779,"props":780,"children":781},"ul",{},[782,788,793,798],{"type":17,"tag":783,"props":784,"children":785},"li",{},[786],{"type":33,"value":787},"缴纳500元定金的用户可以收到100元优惠券；",{"type":17,"tag":783,"props":789,"children":790},{},[791],{"type":33,"value":792},"缴纳200元定金的用户可以收到50元优惠券；",{"type":17,"tag":783,"props":794,"children":795},{},[796],{"type":33,"value":797},"没有缴纳定金的用户进入普通购买模式，没有优惠券。",{"type":17,"tag":783,"props":799,"children":800},{},[801],{"type":33,"value":802},"而且在库存不足的情况下，不一定能保证买得到。",{"type":17,"tag":18,"props":804,"children":805},{},[806],{"type":33,"value":807},"下面开始设计几个字段，解释它们的含义：",{"type":17,"tag":779,"props":809,"children":810},{},[811,816,821],{"type":17,"tag":783,"props":812,"children":813},{},[814],{"type":33,"value":815},"orderType：表示订单类型，值为1表示500元定金用户，值为2表示200元定金用户，值为3表示普通用户。",{"type":17,"tag":783,"props":817,"children":818},{},[819],{"type":33,"value":820},"pay：表示用户是否支付定金，值为布尔值true和false，就算用户下了500元定金的订单，但是如果没有支付定金，那也会降级为普通用户购买模式。",{"type":17,"tag":783,"props":822,"children":823},{},[824],{"type":33,"value":825},"stock：表示当前用户普通购买的手机库存数量，已经支付过定金的用户不受限制。",{"type":17,"tag":18,"props":827,"children":828},{},[829],{"type":33,"value":830},"下面我们分别用if和职责链模式来实现：",{"type":17,"tag":18,"props":832,"children":833},{},[834],{"type":33,"value":835},"使用if：",{"type":17,"tag":93,"props":837,"children":839},{"className":95,"code":838,"language":97,"meta":7,"style":7},"const order = function (orderType, pay, stock) {\n  if (orderType === 1) {\n    if (pay === true) {\n      console.log('500元定金预购，得到100元优惠券')\n    } else {\n      if (stock > 0) {\n        console.log('普通用户购买，无优惠券')\n      } else {\n        console.log('手机库存不足')\n      }\n    } else if (orderType === 2) {\n      if (pay === true) {\n        console.log('200元定金预购，得到50元优惠券')\n      } else {\n        if (stock > 0) {\n          console.log('普通用户购买，无优惠券')\n        } else {\n          console.log('手机库存不足')\n        }\n      }\n    } else if (orderType === 3) {\n      if (stock > 0) {\n          console.log('普通用户购买，无优惠券')\n        } else {\n          console.log('手机库存不足')\n      } \n  }\n}\n\norder(1, true, 500)  // 输出：500元定金预购，得到100元优惠券'\n",[840],{"type":17,"tag":65,"props":841,"children":842},{"__ignoreMap":7},[843,895,920,946,973,989,1016,1041,1057,1081,1089,1121,1144,1168,1183,1207,1231,1247,1270,1278,1285,1318,1342,1366,1382,1406,1415,1423,1432,1440],{"type":17,"tag":103,"props":844,"children":845},{"class":105,"line":106},[846,850,855,859,864,868,873,877,882,886,891],{"type":17,"tag":103,"props":847,"children":848},{"style":110},[849],{"type":33,"value":113},{"type":17,"tag":103,"props":851,"children":852},{"style":127},[853],{"type":33,"value":854}," order",{"type":17,"tag":103,"props":856,"children":857},{"style":110},[858],{"type":33,"value":124},{"type":17,"tag":103,"props":860,"children":861},{"style":110},[862],{"type":33,"value":863}," function",{"type":17,"tag":103,"props":865,"children":866},{"style":133},[867],{"type":33,"value":216},{"type":17,"tag":103,"props":869,"children":870},{"style":219},[871],{"type":33,"value":872},"orderType",{"type":17,"tag":103,"props":874,"children":875},{"style":133},[876],{"type":33,"value":227},{"type":17,"tag":103,"props":878,"children":879},{"style":219},[880],{"type":33,"value":881},"pay",{"type":17,"tag":103,"props":883,"children":884},{"style":133},[885],{"type":33,"value":227},{"type":17,"tag":103,"props":887,"children":888},{"style":219},[889],{"type":33,"value":890},"stock",{"type":17,"tag":103,"props":892,"children":893},{"style":133},[894],{"type":33,"value":276},{"type":17,"tag":103,"props":896,"children":897},{"class":105,"line":150},[898,902,907,911,916],{"type":17,"tag":103,"props":899,"children":900},{"style":110},[901],{"type":33,"value":256},{"type":17,"tag":103,"props":903,"children":904},{"style":133},[905],{"type":33,"value":906}," (orderType ",{"type":17,"tag":103,"props":908,"children":909},{"style":110},[910],{"type":33,"value":266},{"type":17,"tag":103,"props":912,"children":913},{"style":116},[914],{"type":33,"value":915}," 1",{"type":17,"tag":103,"props":917,"children":918},{"style":133},[919],{"type":33,"value":276},{"type":17,"tag":103,"props":921,"children":922},{"class":105,"line":181},[923,928,933,937,942],{"type":17,"tag":103,"props":924,"children":925},{"style":110},[926],{"type":33,"value":927},"    if",{"type":17,"tag":103,"props":929,"children":930},{"style":133},[931],{"type":33,"value":932}," (pay ",{"type":17,"tag":103,"props":934,"children":935},{"style":110},[936],{"type":33,"value":266},{"type":17,"tag":103,"props":938,"children":939},{"style":116},[940],{"type":33,"value":941}," true",{"type":17,"tag":103,"props":943,"children":944},{"style":133},[945],{"type":33,"value":276},{"type":17,"tag":103,"props":947,"children":948},{"class":105,"line":191},[949,954,959,963,968],{"type":17,"tag":103,"props":950,"children":951},{"style":133},[952],{"type":33,"value":953},"      console.",{"type":17,"tag":103,"props":955,"children":956},{"style":127},[957],{"type":33,"value":958},"log",{"type":17,"tag":103,"props":960,"children":961},{"style":133},[962],{"type":33,"value":136},{"type":17,"tag":103,"props":964,"children":965},{"style":139},[966],{"type":33,"value":967},"'500元定金预购，得到100元优惠券'",{"type":17,"tag":103,"props":969,"children":970},{"style":133},[971],{"type":33,"value":972},")\n",{"type":17,"tag":103,"props":974,"children":975},{"class":105,"line":250},[976,981,985],{"type":17,"tag":103,"props":977,"children":978},{"style":133},[979],{"type":33,"value":980},"    } ",{"type":17,"tag":103,"props":982,"children":983},{"style":110},[984],{"type":33,"value":689},{"type":17,"tag":103,"props":986,"children":987},{"style":133},[988],{"type":33,"value":247},{"type":17,"tag":103,"props":990,"children":991},{"class":105,"line":279},[992,997,1002,1007,1012],{"type":17,"tag":103,"props":993,"children":994},{"style":110},[995],{"type":33,"value":996},"      if",{"type":17,"tag":103,"props":998,"children":999},{"style":133},[1000],{"type":33,"value":1001}," (stock ",{"type":17,"tag":103,"props":1003,"children":1004},{"style":110},[1005],{"type":33,"value":1006},">",{"type":17,"tag":103,"props":1008,"children":1009},{"style":116},[1010],{"type":33,"value":1011}," 0",{"type":17,"tag":103,"props":1013,"children":1014},{"style":133},[1015],{"type":33,"value":276},{"type":17,"tag":103,"props":1017,"children":1018},{"class":105,"line":303},[1019,1024,1028,1032,1037],{"type":17,"tag":103,"props":1020,"children":1021},{"style":133},[1022],{"type":33,"value":1023},"        console.",{"type":17,"tag":103,"props":1025,"children":1026},{"style":127},[1027],{"type":33,"value":958},{"type":17,"tag":103,"props":1029,"children":1030},{"style":133},[1031],{"type":33,"value":136},{"type":17,"tag":103,"props":1033,"children":1034},{"style":139},[1035],{"type":33,"value":1036},"'普通用户购买，无优惠券'",{"type":17,"tag":103,"props":1038,"children":1039},{"style":133},[1040],{"type":33,"value":972},{"type":17,"tag":103,"props":1042,"children":1043},{"class":105,"line":316},[1044,1049,1053],{"type":17,"tag":103,"props":1045,"children":1046},{"style":133},[1047],{"type":33,"value":1048},"      } ",{"type":17,"tag":103,"props":1050,"children":1051},{"style":110},[1052],{"type":33,"value":689},{"type":17,"tag":103,"props":1054,"children":1055},{"style":133},[1056],{"type":33,"value":247},{"type":17,"tag":103,"props":1058,"children":1059},{"class":105,"line":325},[1060,1064,1068,1072,1077],{"type":17,"tag":103,"props":1061,"children":1062},{"style":133},[1063],{"type":33,"value":1023},{"type":17,"tag":103,"props":1065,"children":1066},{"style":127},[1067],{"type":33,"value":958},{"type":17,"tag":103,"props":1069,"children":1070},{"style":133},[1071],{"type":33,"value":136},{"type":17,"tag":103,"props":1073,"children":1074},{"style":139},[1075],{"type":33,"value":1076},"'手机库存不足'",{"type":17,"tag":103,"props":1078,"children":1079},{"style":133},[1080],{"type":33,"value":972},{"type":17,"tag":103,"props":1082,"children":1083},{"class":105,"line":334},[1084],{"type":17,"tag":103,"props":1085,"children":1086},{"style":133},[1087],{"type":33,"value":1088},"      }\n",{"type":17,"tag":103,"props":1090,"children":1091},{"class":105,"line":354},[1092,1096,1100,1104,1108,1112,1117],{"type":17,"tag":103,"props":1093,"children":1094},{"style":133},[1095],{"type":33,"value":980},{"type":17,"tag":103,"props":1097,"children":1098},{"style":110},[1099],{"type":33,"value":689},{"type":17,"tag":103,"props":1101,"children":1102},{"style":110},[1103],{"type":33,"value":694},{"type":17,"tag":103,"props":1105,"children":1106},{"style":133},[1107],{"type":33,"value":906},{"type":17,"tag":103,"props":1109,"children":1110},{"style":110},[1111],{"type":33,"value":266},{"type":17,"tag":103,"props":1113,"children":1114},{"style":116},[1115],{"type":33,"value":1116}," 2",{"type":17,"tag":103,"props":1118,"children":1119},{"style":133},[1120],{"type":33,"value":276},{"type":17,"tag":103,"props":1122,"children":1123},{"class":105,"line":363},[1124,1128,1132,1136,1140],{"type":17,"tag":103,"props":1125,"children":1126},{"style":110},[1127],{"type":33,"value":996},{"type":17,"tag":103,"props":1129,"children":1130},{"style":133},[1131],{"type":33,"value":932},{"type":17,"tag":103,"props":1133,"children":1134},{"style":110},[1135],{"type":33,"value":266},{"type":17,"tag":103,"props":1137,"children":1138},{"style":116},[1139],{"type":33,"value":941},{"type":17,"tag":103,"props":1141,"children":1142},{"style":133},[1143],{"type":33,"value":276},{"type":17,"tag":103,"props":1145,"children":1146},{"class":105,"line":371},[1147,1151,1155,1159,1164],{"type":17,"tag":103,"props":1148,"children":1149},{"style":133},[1150],{"type":33,"value":1023},{"type":17,"tag":103,"props":1152,"children":1153},{"style":127},[1154],{"type":33,"value":958},{"type":17,"tag":103,"props":1156,"children":1157},{"style":133},[1158],{"type":33,"value":136},{"type":17,"tag":103,"props":1160,"children":1161},{"style":139},[1162],{"type":33,"value":1163},"'200元定金预购，得到50元优惠券'",{"type":17,"tag":103,"props":1165,"children":1166},{"style":133},[1167],{"type":33,"value":972},{"type":17,"tag":103,"props":1169,"children":1170},{"class":105,"line":419},[1171,1175,1179],{"type":17,"tag":103,"props":1172,"children":1173},{"style":133},[1174],{"type":33,"value":1048},{"type":17,"tag":103,"props":1176,"children":1177},{"style":110},[1178],{"type":33,"value":689},{"type":17,"tag":103,"props":1180,"children":1181},{"style":133},[1182],{"type":33,"value":247},{"type":17,"tag":103,"props":1184,"children":1185},{"class":105,"line":444},[1186,1191,1195,1199,1203],{"type":17,"tag":103,"props":1187,"children":1188},{"style":110},[1189],{"type":33,"value":1190},"        if",{"type":17,"tag":103,"props":1192,"children":1193},{"style":133},[1194],{"type":33,"value":1001},{"type":17,"tag":103,"props":1196,"children":1197},{"style":110},[1198],{"type":33,"value":1006},{"type":17,"tag":103,"props":1200,"children":1201},{"style":116},[1202],{"type":33,"value":1011},{"type":17,"tag":103,"props":1204,"children":1205},{"style":133},[1206],{"type":33,"value":276},{"type":17,"tag":103,"props":1208,"children":1209},{"class":105,"line":465},[1210,1215,1219,1223,1227],{"type":17,"tag":103,"props":1211,"children":1212},{"style":133},[1213],{"type":33,"value":1214},"          console.",{"type":17,"tag":103,"props":1216,"children":1217},{"style":127},[1218],{"type":33,"value":958},{"type":17,"tag":103,"props":1220,"children":1221},{"style":133},[1222],{"type":33,"value":136},{"type":17,"tag":103,"props":1224,"children":1225},{"style":139},[1226],{"type":33,"value":1036},{"type":17,"tag":103,"props":1228,"children":1229},{"style":133},[1230],{"type":33,"value":972},{"type":17,"tag":103,"props":1232,"children":1233},{"class":105,"line":477},[1234,1239,1243],{"type":17,"tag":103,"props":1235,"children":1236},{"style":133},[1237],{"type":33,"value":1238},"        } ",{"type":17,"tag":103,"props":1240,"children":1241},{"style":110},[1242],{"type":33,"value":689},{"type":17,"tag":103,"props":1244,"children":1245},{"style":133},[1246],{"type":33,"value":247},{"type":17,"tag":103,"props":1248,"children":1249},{"class":105,"line":485},[1250,1254,1258,1262,1266],{"type":17,"tag":103,"props":1251,"children":1252},{"style":133},[1253],{"type":33,"value":1214},{"type":17,"tag":103,"props":1255,"children":1256},{"style":127},[1257],{"type":33,"value":958},{"type":17,"tag":103,"props":1259,"children":1260},{"style":133},[1261],{"type":33,"value":136},{"type":17,"tag":103,"props":1263,"children":1264},{"style":139},[1265],{"type":33,"value":1076},{"type":17,"tag":103,"props":1267,"children":1268},{"style":133},[1269],{"type":33,"value":972},{"type":17,"tag":103,"props":1271,"children":1272},{"class":105,"line":493},[1273],{"type":17,"tag":103,"props":1274,"children":1275},{"style":133},[1276],{"type":33,"value":1277},"        }\n",{"type":17,"tag":103,"props":1279,"children":1280},{"class":105,"line":501},[1281],{"type":17,"tag":103,"props":1282,"children":1283},{"style":133},[1284],{"type":33,"value":1088},{"type":17,"tag":103,"props":1286,"children":1288},{"class":105,"line":1287},21,[1289,1293,1297,1301,1305,1309,1314],{"type":17,"tag":103,"props":1290,"children":1291},{"style":133},[1292],{"type":33,"value":980},{"type":17,"tag":103,"props":1294,"children":1295},{"style":110},[1296],{"type":33,"value":689},{"type":17,"tag":103,"props":1298,"children":1299},{"style":110},[1300],{"type":33,"value":694},{"type":17,"tag":103,"props":1302,"children":1303},{"style":133},[1304],{"type":33,"value":906},{"type":17,"tag":103,"props":1306,"children":1307},{"style":110},[1308],{"type":33,"value":266},{"type":17,"tag":103,"props":1310,"children":1311},{"style":116},[1312],{"type":33,"value":1313}," 3",{"type":17,"tag":103,"props":1315,"children":1316},{"style":133},[1317],{"type":33,"value":276},{"type":17,"tag":103,"props":1319,"children":1321},{"class":105,"line":1320},22,[1322,1326,1330,1334,1338],{"type":17,"tag":103,"props":1323,"children":1324},{"style":110},[1325],{"type":33,"value":996},{"type":17,"tag":103,"props":1327,"children":1328},{"style":133},[1329],{"type":33,"value":1001},{"type":17,"tag":103,"props":1331,"children":1332},{"style":110},[1333],{"type":33,"value":1006},{"type":17,"tag":103,"props":1335,"children":1336},{"style":116},[1337],{"type":33,"value":1011},{"type":17,"tag":103,"props":1339,"children":1340},{"style":133},[1341],{"type":33,"value":276},{"type":17,"tag":103,"props":1343,"children":1345},{"class":105,"line":1344},23,[1346,1350,1354,1358,1362],{"type":17,"tag":103,"props":1347,"children":1348},{"style":133},[1349],{"type":33,"value":1214},{"type":17,"tag":103,"props":1351,"children":1352},{"style":127},[1353],{"type":33,"value":958},{"type":17,"tag":103,"props":1355,"children":1356},{"style":133},[1357],{"type":33,"value":136},{"type":17,"tag":103,"props":1359,"children":1360},{"style":139},[1361],{"type":33,"value":1036},{"type":17,"tag":103,"props":1363,"children":1364},{"style":133},[1365],{"type":33,"value":972},{"type":17,"tag":103,"props":1367,"children":1369},{"class":105,"line":1368},24,[1370,1374,1378],{"type":17,"tag":103,"props":1371,"children":1372},{"style":133},[1373],{"type":33,"value":1238},{"type":17,"tag":103,"props":1375,"children":1376},{"style":110},[1377],{"type":33,"value":689},{"type":17,"tag":103,"props":1379,"children":1380},{"style":133},[1381],{"type":33,"value":247},{"type":17,"tag":103,"props":1383,"children":1385},{"class":105,"line":1384},25,[1386,1390,1394,1398,1402],{"type":17,"tag":103,"props":1387,"children":1388},{"style":133},[1389],{"type":33,"value":1214},{"type":17,"tag":103,"props":1391,"children":1392},{"style":127},[1393],{"type":33,"value":958},{"type":17,"tag":103,"props":1395,"children":1396},{"style":133},[1397],{"type":33,"value":136},{"type":17,"tag":103,"props":1399,"children":1400},{"style":139},[1401],{"type":33,"value":1076},{"type":17,"tag":103,"props":1403,"children":1404},{"style":133},[1405],{"type":33,"value":972},{"type":17,"tag":103,"props":1407,"children":1409},{"class":105,"line":1408},26,[1410],{"type":17,"tag":103,"props":1411,"children":1412},{"style":133},[1413],{"type":33,"value":1414},"      } \n",{"type":17,"tag":103,"props":1416,"children":1418},{"class":105,"line":1417},27,[1419],{"type":17,"tag":103,"props":1420,"children":1421},{"style":133},[1422],{"type":33,"value":322},{"type":17,"tag":103,"props":1424,"children":1426},{"class":105,"line":1425},28,[1427],{"type":17,"tag":103,"props":1428,"children":1429},{"style":133},[1430],{"type":33,"value":1431},"}\n",{"type":17,"tag":103,"props":1433,"children":1435},{"class":105,"line":1434},29,[1436],{"type":17,"tag":103,"props":1437,"children":1438},{"emptyLinePlaceholder":185},[1439],{"type":33,"value":188},{"type":17,"tag":103,"props":1441,"children":1443},{"class":105,"line":1442},30,[1444,1449,1453,1458,1462,1467,1471,1476,1481],{"type":17,"tag":103,"props":1445,"children":1446},{"style":127},[1447],{"type":33,"value":1448},"order",{"type":17,"tag":103,"props":1450,"children":1451},{"style":133},[1452],{"type":33,"value":136},{"type":17,"tag":103,"props":1454,"children":1455},{"style":116},[1456],{"type":33,"value":1457},"1",{"type":17,"tag":103,"props":1459,"children":1460},{"style":133},[1461],{"type":33,"value":227},{"type":17,"tag":103,"props":1463,"children":1464},{"style":116},[1465],{"type":33,"value":1466},"true",{"type":17,"tag":103,"props":1468,"children":1469},{"style":133},[1470],{"type":33,"value":227},{"type":17,"tag":103,"props":1472,"children":1473},{"style":116},[1474],{"type":33,"value":1475},"500",{"type":17,"tag":103,"props":1477,"children":1478},{"style":133},[1479],{"type":33,"value":1480},")  ",{"type":17,"tag":103,"props":1482,"children":1483},{"style":348},[1484],{"type":33,"value":1485},"// 输出：500元定金预购，得到100元优惠券'\n",{"type":17,"tag":18,"props":1487,"children":1488},{},[1489],{"type":33,"value":1490},"虽然上面的代码也可以实现需求，但是代码实在是难以阅读，维护起来更是困难，如果继续在这个代码上开发，未来肯定会成为一座很大的屎山。",{"type":17,"tag":18,"props":1492,"children":1493},{},[1494],{"type":33,"value":1495},"下面我们使用责任链模式来实现：",{"type":17,"tag":93,"props":1497,"children":1499},{"className":95,"code":1498,"language":97,"meta":7,"style":7},"\nfunction printResult(orderType, pay, stock) {\n    // 这里ResChain类是模拟koa的写法，后面会讲如何实现ResChain\n    // 请先耐心看完它是如何处理的\n    const resChain = new ResChain()\n    \n    resChain.add('order500', (_, next) => {\n        if (orderType === 1 && pay === true) {\n            console.log('500元定金预购，拿到100元优惠券');\n            return;\n        }\n        next(); // 这里将会调用order200对应的回调函数\n    })\n\n    resChain.add('order200', (_, next) => {\n        if (orderType === 2 && pay === true) {\n            console.log('200元定金预购，拿到50元优惠券');\n            return;\n        }\n        next(); // 这里会调用noOrder对应回调函数\n    })\n\n    resChain.add('noOrder', (_, next) => {\n        if (stock > 0) {\n            console.log('普通用户购买，无优惠券');\n        } else {\n            console.log('手机库存不足');\n        }\n    })\n\n    resChain.run() // 开始执行order500对应的回调函数\n}\n\n// 测试 \nprintResult(1, true, 500)  // 500元定金预购，得到100元优惠券\nprintResult(1, false, 500) // 普通用户购买，无优惠券\nprintResult(2, true, 500)  // 200元定金预购，得到50元优惠券\nprintResult(3, false, 500) // 普通用户购买，无优惠券\nprintResult(3, false, 0)   // 手机库存不足\n",[1500],{"type":17,"tag":65,"props":1501,"children":1502},{"__ignoreMap":7},[1503,1510,1551,1559,1567,1598,1606,1658,1699,1724,1736,1743,1760,1768,1775,1823,1862,1886,1897,1904,1920,1927,1934,1982,2005,2028,2043,2066,2073,2080,2087,2110,2118,2126,2135,2177,2219,2261,2302],{"type":17,"tag":103,"props":1504,"children":1505},{"class":105,"line":106},[1506],{"type":17,"tag":103,"props":1507,"children":1508},{"emptyLinePlaceholder":185},[1509],{"type":33,"value":188},{"type":17,"tag":103,"props":1511,"children":1512},{"class":105,"line":150},[1513,1518,1523,1527,1531,1535,1539,1543,1547],{"type":17,"tag":103,"props":1514,"children":1515},{"style":110},[1516],{"type":33,"value":1517},"function",{"type":17,"tag":103,"props":1519,"children":1520},{"style":127},[1521],{"type":33,"value":1522}," printResult",{"type":17,"tag":103,"props":1524,"children":1525},{"style":133},[1526],{"type":33,"value":136},{"type":17,"tag":103,"props":1528,"children":1529},{"style":219},[1530],{"type":33,"value":872},{"type":17,"tag":103,"props":1532,"children":1533},{"style":133},[1534],{"type":33,"value":227},{"type":17,"tag":103,"props":1536,"children":1537},{"style":219},[1538],{"type":33,"value":881},{"type":17,"tag":103,"props":1540,"children":1541},{"style":133},[1542],{"type":33,"value":227},{"type":17,"tag":103,"props":1544,"children":1545},{"style":219},[1546],{"type":33,"value":890},{"type":17,"tag":103,"props":1548,"children":1549},{"style":133},[1550],{"type":33,"value":276},{"type":17,"tag":103,"props":1552,"children":1553},{"class":105,"line":181},[1554],{"type":17,"tag":103,"props":1555,"children":1556},{"style":348},[1557],{"type":33,"value":1558},"    // 这里ResChain类是模拟koa的写法，后面会讲如何实现ResChain\n",{"type":17,"tag":103,"props":1560,"children":1561},{"class":105,"line":191},[1562],{"type":17,"tag":103,"props":1563,"children":1564},{"style":348},[1565],{"type":33,"value":1566},"    // 请先耐心看完它是如何处理的\n",{"type":17,"tag":103,"props":1568,"children":1569},{"class":105,"line":250},[1570,1575,1580,1584,1588,1593],{"type":17,"tag":103,"props":1571,"children":1572},{"style":110},[1573],{"type":33,"value":1574},"    const",{"type":17,"tag":103,"props":1576,"children":1577},{"style":116},[1578],{"type":33,"value":1579}," resChain",{"type":17,"tag":103,"props":1581,"children":1582},{"style":110},[1583],{"type":33,"value":124},{"type":17,"tag":103,"props":1585,"children":1586},{"style":110},[1587],{"type":33,"value":169},{"type":17,"tag":103,"props":1589,"children":1590},{"style":127},[1591],{"type":33,"value":1592}," ResChain",{"type":17,"tag":103,"props":1594,"children":1595},{"style":133},[1596],{"type":33,"value":1597},"()\n",{"type":17,"tag":103,"props":1599,"children":1600},{"class":105,"line":279},[1601],{"type":17,"tag":103,"props":1602,"children":1603},{"style":133},[1604],{"type":33,"value":1605},"    \n",{"type":17,"tag":103,"props":1607,"children":1608},{"class":105,"line":303},[1609,1614,1619,1623,1628,1633,1638,1642,1646,1650,1654],{"type":17,"tag":103,"props":1610,"children":1611},{"style":133},[1612],{"type":33,"value":1613},"    resChain.",{"type":17,"tag":103,"props":1615,"children":1616},{"style":127},[1617],{"type":33,"value":1618},"add",{"type":17,"tag":103,"props":1620,"children":1621},{"style":133},[1622],{"type":33,"value":136},{"type":17,"tag":103,"props":1624,"children":1625},{"style":139},[1626],{"type":33,"value":1627},"'order500'",{"type":17,"tag":103,"props":1629,"children":1630},{"style":133},[1631],{"type":33,"value":1632},", (",{"type":17,"tag":103,"props":1634,"children":1635},{"style":219},[1636],{"type":33,"value":1637},"_",{"type":17,"tag":103,"props":1639,"children":1640},{"style":133},[1641],{"type":33,"value":227},{"type":17,"tag":103,"props":1643,"children":1644},{"style":219},[1645],{"type":33,"value":232},{"type":17,"tag":103,"props":1647,"children":1648},{"style":133},[1649],{"type":33,"value":237},{"type":17,"tag":103,"props":1651,"children":1652},{"style":110},[1653],{"type":33,"value":242},{"type":17,"tag":103,"props":1655,"children":1656},{"style":133},[1657],{"type":33,"value":247},{"type":17,"tag":103,"props":1659,"children":1660},{"class":105,"line":316},[1661,1665,1669,1673,1677,1682,1687,1691,1695],{"type":17,"tag":103,"props":1662,"children":1663},{"style":110},[1664],{"type":33,"value":1190},{"type":17,"tag":103,"props":1666,"children":1667},{"style":133},[1668],{"type":33,"value":906},{"type":17,"tag":103,"props":1670,"children":1671},{"style":110},[1672],{"type":33,"value":266},{"type":17,"tag":103,"props":1674,"children":1675},{"style":116},[1676],{"type":33,"value":915},{"type":17,"tag":103,"props":1678,"children":1679},{"style":110},[1680],{"type":33,"value":1681}," &&",{"type":17,"tag":103,"props":1683,"children":1684},{"style":133},[1685],{"type":33,"value":1686}," pay ",{"type":17,"tag":103,"props":1688,"children":1689},{"style":110},[1690],{"type":33,"value":266},{"type":17,"tag":103,"props":1692,"children":1693},{"style":116},[1694],{"type":33,"value":941},{"type":17,"tag":103,"props":1696,"children":1697},{"style":133},[1698],{"type":33,"value":276},{"type":17,"tag":103,"props":1700,"children":1701},{"class":105,"line":325},[1702,1707,1711,1715,1720],{"type":17,"tag":103,"props":1703,"children":1704},{"style":133},[1705],{"type":33,"value":1706},"            console.",{"type":17,"tag":103,"props":1708,"children":1709},{"style":127},[1710],{"type":33,"value":958},{"type":17,"tag":103,"props":1712,"children":1713},{"style":133},[1714],{"type":33,"value":136},{"type":17,"tag":103,"props":1716,"children":1717},{"style":139},[1718],{"type":33,"value":1719},"'500元定金预购，拿到100元优惠券'",{"type":17,"tag":103,"props":1721,"children":1722},{"style":133},[1723],{"type":33,"value":147},{"type":17,"tag":103,"props":1725,"children":1726},{"class":105,"line":334},[1727,1732],{"type":17,"tag":103,"props":1728,"children":1729},{"style":110},[1730],{"type":33,"value":1731},"            return",{"type":17,"tag":103,"props":1733,"children":1734},{"style":133},[1735],{"type":33,"value":300},{"type":17,"tag":103,"props":1737,"children":1738},{"class":105,"line":354},[1739],{"type":17,"tag":103,"props":1740,"children":1741},{"style":133},[1742],{"type":33,"value":1277},{"type":17,"tag":103,"props":1744,"children":1745},{"class":105,"line":363},[1746,1751,1755],{"type":17,"tag":103,"props":1747,"children":1748},{"style":127},[1749],{"type":33,"value":1750},"        next",{"type":17,"tag":103,"props":1752,"children":1753},{"style":133},[1754],{"type":33,"value":345},{"type":17,"tag":103,"props":1756,"children":1757},{"style":348},[1758],{"type":33,"value":1759},"// 这里将会调用order200对应的回调函数\n",{"type":17,"tag":103,"props":1761,"children":1762},{"class":105,"line":371},[1763],{"type":17,"tag":103,"props":1764,"children":1765},{"style":133},[1766],{"type":33,"value":1767},"    })\n",{"type":17,"tag":103,"props":1769,"children":1770},{"class":105,"line":419},[1771],{"type":17,"tag":103,"props":1772,"children":1773},{"emptyLinePlaceholder":185},[1774],{"type":33,"value":188},{"type":17,"tag":103,"props":1776,"children":1777},{"class":105,"line":444},[1778,1782,1786,1790,1795,1799,1803,1807,1811,1815,1819],{"type":17,"tag":103,"props":1779,"children":1780},{"style":133},[1781],{"type":33,"value":1613},{"type":17,"tag":103,"props":1783,"children":1784},{"style":127},[1785],{"type":33,"value":1618},{"type":17,"tag":103,"props":1787,"children":1788},{"style":133},[1789],{"type":33,"value":136},{"type":17,"tag":103,"props":1791,"children":1792},{"style":139},[1793],{"type":33,"value":1794},"'order200'",{"type":17,"tag":103,"props":1796,"children":1797},{"style":133},[1798],{"type":33,"value":1632},{"type":17,"tag":103,"props":1800,"children":1801},{"style":219},[1802],{"type":33,"value":1637},{"type":17,"tag":103,"props":1804,"children":1805},{"style":133},[1806],{"type":33,"value":227},{"type":17,"tag":103,"props":1808,"children":1809},{"style":219},[1810],{"type":33,"value":232},{"type":17,"tag":103,"props":1812,"children":1813},{"style":133},[1814],{"type":33,"value":237},{"type":17,"tag":103,"props":1816,"children":1817},{"style":110},[1818],{"type":33,"value":242},{"type":17,"tag":103,"props":1820,"children":1821},{"style":133},[1822],{"type":33,"value":247},{"type":17,"tag":103,"props":1824,"children":1825},{"class":105,"line":465},[1826,1830,1834,1838,1842,1846,1850,1854,1858],{"type":17,"tag":103,"props":1827,"children":1828},{"style":110},[1829],{"type":33,"value":1190},{"type":17,"tag":103,"props":1831,"children":1832},{"style":133},[1833],{"type":33,"value":906},{"type":17,"tag":103,"props":1835,"children":1836},{"style":110},[1837],{"type":33,"value":266},{"type":17,"tag":103,"props":1839,"children":1840},{"style":116},[1841],{"type":33,"value":1116},{"type":17,"tag":103,"props":1843,"children":1844},{"style":110},[1845],{"type":33,"value":1681},{"type":17,"tag":103,"props":1847,"children":1848},{"style":133},[1849],{"type":33,"value":1686},{"type":17,"tag":103,"props":1851,"children":1852},{"style":110},[1853],{"type":33,"value":266},{"type":17,"tag":103,"props":1855,"children":1856},{"style":116},[1857],{"type":33,"value":941},{"type":17,"tag":103,"props":1859,"children":1860},{"style":133},[1861],{"type":33,"value":276},{"type":17,"tag":103,"props":1863,"children":1864},{"class":105,"line":477},[1865,1869,1873,1877,1882],{"type":17,"tag":103,"props":1866,"children":1867},{"style":133},[1868],{"type":33,"value":1706},{"type":17,"tag":103,"props":1870,"children":1871},{"style":127},[1872],{"type":33,"value":958},{"type":17,"tag":103,"props":1874,"children":1875},{"style":133},[1876],{"type":33,"value":136},{"type":17,"tag":103,"props":1878,"children":1879},{"style":139},[1880],{"type":33,"value":1881},"'200元定金预购，拿到50元优惠券'",{"type":17,"tag":103,"props":1883,"children":1884},{"style":133},[1885],{"type":33,"value":147},{"type":17,"tag":103,"props":1887,"children":1888},{"class":105,"line":485},[1889,1893],{"type":17,"tag":103,"props":1890,"children":1891},{"style":110},[1892],{"type":33,"value":1731},{"type":17,"tag":103,"props":1894,"children":1895},{"style":133},[1896],{"type":33,"value":300},{"type":17,"tag":103,"props":1898,"children":1899},{"class":105,"line":493},[1900],{"type":17,"tag":103,"props":1901,"children":1902},{"style":133},[1903],{"type":33,"value":1277},{"type":17,"tag":103,"props":1905,"children":1906},{"class":105,"line":501},[1907,1911,1915],{"type":17,"tag":103,"props":1908,"children":1909},{"style":127},[1910],{"type":33,"value":1750},{"type":17,"tag":103,"props":1912,"children":1913},{"style":133},[1914],{"type":33,"value":345},{"type":17,"tag":103,"props":1916,"children":1917},{"style":348},[1918],{"type":33,"value":1919},"// 这里会调用noOrder对应回调函数\n",{"type":17,"tag":103,"props":1921,"children":1922},{"class":105,"line":1287},[1923],{"type":17,"tag":103,"props":1924,"children":1925},{"style":133},[1926],{"type":33,"value":1767},{"type":17,"tag":103,"props":1928,"children":1929},{"class":105,"line":1320},[1930],{"type":17,"tag":103,"props":1931,"children":1932},{"emptyLinePlaceholder":185},[1933],{"type":33,"value":188},{"type":17,"tag":103,"props":1935,"children":1936},{"class":105,"line":1344},[1937,1941,1945,1949,1954,1958,1962,1966,1970,1974,1978],{"type":17,"tag":103,"props":1938,"children":1939},{"style":133},[1940],{"type":33,"value":1613},{"type":17,"tag":103,"props":1942,"children":1943},{"style":127},[1944],{"type":33,"value":1618},{"type":17,"tag":103,"props":1946,"children":1947},{"style":133},[1948],{"type":33,"value":136},{"type":17,"tag":103,"props":1950,"children":1951},{"style":139},[1952],{"type":33,"value":1953},"'noOrder'",{"type":17,"tag":103,"props":1955,"children":1956},{"style":133},[1957],{"type":33,"value":1632},{"type":17,"tag":103,"props":1959,"children":1960},{"style":219},[1961],{"type":33,"value":1637},{"type":17,"tag":103,"props":1963,"children":1964},{"style":133},[1965],{"type":33,"value":227},{"type":17,"tag":103,"props":1967,"children":1968},{"style":219},[1969],{"type":33,"value":232},{"type":17,"tag":103,"props":1971,"children":1972},{"style":133},[1973],{"type":33,"value":237},{"type":17,"tag":103,"props":1975,"children":1976},{"style":110},[1977],{"type":33,"value":242},{"type":17,"tag":103,"props":1979,"children":1980},{"style":133},[1981],{"type":33,"value":247},{"type":17,"tag":103,"props":1983,"children":1984},{"class":105,"line":1368},[1985,1989,1993,1997,2001],{"type":17,"tag":103,"props":1986,"children":1987},{"style":110},[1988],{"type":33,"value":1190},{"type":17,"tag":103,"props":1990,"children":1991},{"style":133},[1992],{"type":33,"value":1001},{"type":17,"tag":103,"props":1994,"children":1995},{"style":110},[1996],{"type":33,"value":1006},{"type":17,"tag":103,"props":1998,"children":1999},{"style":116},[2000],{"type":33,"value":1011},{"type":17,"tag":103,"props":2002,"children":2003},{"style":133},[2004],{"type":33,"value":276},{"type":17,"tag":103,"props":2006,"children":2007},{"class":105,"line":1384},[2008,2012,2016,2020,2024],{"type":17,"tag":103,"props":2009,"children":2010},{"style":133},[2011],{"type":33,"value":1706},{"type":17,"tag":103,"props":2013,"children":2014},{"style":127},[2015],{"type":33,"value":958},{"type":17,"tag":103,"props":2017,"children":2018},{"style":133},[2019],{"type":33,"value":136},{"type":17,"tag":103,"props":2021,"children":2022},{"style":139},[2023],{"type":33,"value":1036},{"type":17,"tag":103,"props":2025,"children":2026},{"style":133},[2027],{"type":33,"value":147},{"type":17,"tag":103,"props":2029,"children":2030},{"class":105,"line":1408},[2031,2035,2039],{"type":17,"tag":103,"props":2032,"children":2033},{"style":133},[2034],{"type":33,"value":1238},{"type":17,"tag":103,"props":2036,"children":2037},{"style":110},[2038],{"type":33,"value":689},{"type":17,"tag":103,"props":2040,"children":2041},{"style":133},[2042],{"type":33,"value":247},{"type":17,"tag":103,"props":2044,"children":2045},{"class":105,"line":1417},[2046,2050,2054,2058,2062],{"type":17,"tag":103,"props":2047,"children":2048},{"style":133},[2049],{"type":33,"value":1706},{"type":17,"tag":103,"props":2051,"children":2052},{"style":127},[2053],{"type":33,"value":958},{"type":17,"tag":103,"props":2055,"children":2056},{"style":133},[2057],{"type":33,"value":136},{"type":17,"tag":103,"props":2059,"children":2060},{"style":139},[2061],{"type":33,"value":1076},{"type":17,"tag":103,"props":2063,"children":2064},{"style":133},[2065],{"type":33,"value":147},{"type":17,"tag":103,"props":2067,"children":2068},{"class":105,"line":1425},[2069],{"type":17,"tag":103,"props":2070,"children":2071},{"style":133},[2072],{"type":33,"value":1277},{"type":17,"tag":103,"props":2074,"children":2075},{"class":105,"line":1434},[2076],{"type":17,"tag":103,"props":2077,"children":2078},{"style":133},[2079],{"type":33,"value":1767},{"type":17,"tag":103,"props":2081,"children":2082},{"class":105,"line":1442},[2083],{"type":17,"tag":103,"props":2084,"children":2085},{"emptyLinePlaceholder":185},[2086],{"type":33,"value":188},{"type":17,"tag":103,"props":2088,"children":2090},{"class":105,"line":2089},31,[2091,2095,2100,2105],{"type":17,"tag":103,"props":2092,"children":2093},{"style":133},[2094],{"type":33,"value":1613},{"type":17,"tag":103,"props":2096,"children":2097},{"style":127},[2098],{"type":33,"value":2099},"run",{"type":17,"tag":103,"props":2101,"children":2102},{"style":133},[2103],{"type":33,"value":2104},"() ",{"type":17,"tag":103,"props":2106,"children":2107},{"style":348},[2108],{"type":33,"value":2109},"// 开始执行order500对应的回调函数\n",{"type":17,"tag":103,"props":2111,"children":2113},{"class":105,"line":2112},32,[2114],{"type":17,"tag":103,"props":2115,"children":2116},{"style":133},[2117],{"type":33,"value":1431},{"type":17,"tag":103,"props":2119,"children":2121},{"class":105,"line":2120},33,[2122],{"type":17,"tag":103,"props":2123,"children":2124},{"emptyLinePlaceholder":185},[2125],{"type":33,"value":188},{"type":17,"tag":103,"props":2127,"children":2129},{"class":105,"line":2128},34,[2130],{"type":17,"tag":103,"props":2131,"children":2132},{"style":348},[2133],{"type":33,"value":2134},"// 测试 \n",{"type":17,"tag":103,"props":2136,"children":2138},{"class":105,"line":2137},35,[2139,2144,2148,2152,2156,2160,2164,2168,2172],{"type":17,"tag":103,"props":2140,"children":2141},{"style":127},[2142],{"type":33,"value":2143},"printResult",{"type":17,"tag":103,"props":2145,"children":2146},{"style":133},[2147],{"type":33,"value":136},{"type":17,"tag":103,"props":2149,"children":2150},{"style":116},[2151],{"type":33,"value":1457},{"type":17,"tag":103,"props":2153,"children":2154},{"style":133},[2155],{"type":33,"value":227},{"type":17,"tag":103,"props":2157,"children":2158},{"style":116},[2159],{"type":33,"value":1466},{"type":17,"tag":103,"props":2161,"children":2162},{"style":133},[2163],{"type":33,"value":227},{"type":17,"tag":103,"props":2165,"children":2166},{"style":116},[2167],{"type":33,"value":1475},{"type":17,"tag":103,"props":2169,"children":2170},{"style":133},[2171],{"type":33,"value":1480},{"type":17,"tag":103,"props":2173,"children":2174},{"style":348},[2175],{"type":33,"value":2176},"// 500元定金预购，得到100元优惠券\n",{"type":17,"tag":103,"props":2178,"children":2180},{"class":105,"line":2179},36,[2181,2185,2189,2193,2197,2202,2206,2210,2214],{"type":17,"tag":103,"props":2182,"children":2183},{"style":127},[2184],{"type":33,"value":2143},{"type":17,"tag":103,"props":2186,"children":2187},{"style":133},[2188],{"type":33,"value":136},{"type":17,"tag":103,"props":2190,"children":2191},{"style":116},[2192],{"type":33,"value":1457},{"type":17,"tag":103,"props":2194,"children":2195},{"style":133},[2196],{"type":33,"value":227},{"type":17,"tag":103,"props":2198,"children":2199},{"style":116},[2200],{"type":33,"value":2201},"false",{"type":17,"tag":103,"props":2203,"children":2204},{"style":133},[2205],{"type":33,"value":227},{"type":17,"tag":103,"props":2207,"children":2208},{"style":116},[2209],{"type":33,"value":1475},{"type":17,"tag":103,"props":2211,"children":2212},{"style":133},[2213],{"type":33,"value":237},{"type":17,"tag":103,"props":2215,"children":2216},{"style":348},[2217],{"type":33,"value":2218},"// 普通用户购买，无优惠券\n",{"type":17,"tag":103,"props":2220,"children":2222},{"class":105,"line":2221},37,[2223,2227,2231,2236,2240,2244,2248,2252,2256],{"type":17,"tag":103,"props":2224,"children":2225},{"style":127},[2226],{"type":33,"value":2143},{"type":17,"tag":103,"props":2228,"children":2229},{"style":133},[2230],{"type":33,"value":136},{"type":17,"tag":103,"props":2232,"children":2233},{"style":116},[2234],{"type":33,"value":2235},"2",{"type":17,"tag":103,"props":2237,"children":2238},{"style":133},[2239],{"type":33,"value":227},{"type":17,"tag":103,"props":2241,"children":2242},{"style":116},[2243],{"type":33,"value":1466},{"type":17,"tag":103,"props":2245,"children":2246},{"style":133},[2247],{"type":33,"value":227},{"type":17,"tag":103,"props":2249,"children":2250},{"style":116},[2251],{"type":33,"value":1475},{"type":17,"tag":103,"props":2253,"children":2254},{"style":133},[2255],{"type":33,"value":1480},{"type":17,"tag":103,"props":2257,"children":2258},{"style":348},[2259],{"type":33,"value":2260},"// 200元定金预购，得到50元优惠券\n",{"type":17,"tag":103,"props":2262,"children":2264},{"class":105,"line":2263},38,[2265,2269,2273,2278,2282,2286,2290,2294,2298],{"type":17,"tag":103,"props":2266,"children":2267},{"style":127},[2268],{"type":33,"value":2143},{"type":17,"tag":103,"props":2270,"children":2271},{"style":133},[2272],{"type":33,"value":136},{"type":17,"tag":103,"props":2274,"children":2275},{"style":116},[2276],{"type":33,"value":2277},"3",{"type":17,"tag":103,"props":2279,"children":2280},{"style":133},[2281],{"type":33,"value":227},{"type":17,"tag":103,"props":2283,"children":2284},{"style":116},[2285],{"type":33,"value":2201},{"type":17,"tag":103,"props":2287,"children":2288},{"style":133},[2289],{"type":33,"value":227},{"type":17,"tag":103,"props":2291,"children":2292},{"style":116},[2293],{"type":33,"value":1475},{"type":17,"tag":103,"props":2295,"children":2296},{"style":133},[2297],{"type":33,"value":237},{"type":17,"tag":103,"props":2299,"children":2300},{"style":348},[2301],{"type":33,"value":2218},{"type":17,"tag":103,"props":2303,"children":2305},{"class":105,"line":2304},39,[2306,2310,2314,2318,2322,2326,2330,2335,2340],{"type":17,"tag":103,"props":2307,"children":2308},{"style":127},[2309],{"type":33,"value":2143},{"type":17,"tag":103,"props":2311,"children":2312},{"style":133},[2313],{"type":33,"value":136},{"type":17,"tag":103,"props":2315,"children":2316},{"style":116},[2317],{"type":33,"value":2277},{"type":17,"tag":103,"props":2319,"children":2320},{"style":133},[2321],{"type":33,"value":227},{"type":17,"tag":103,"props":2323,"children":2324},{"style":116},[2325],{"type":33,"value":2201},{"type":17,"tag":103,"props":2327,"children":2328},{"style":133},[2329],{"type":33,"value":227},{"type":17,"tag":103,"props":2331,"children":2332},{"style":116},[2333],{"type":33,"value":2334},"0",{"type":17,"tag":103,"props":2336,"children":2337},{"style":133},[2338],{"type":33,"value":2339},")   ",{"type":17,"tag":103,"props":2341,"children":2342},{"style":348},[2343],{"type":33,"value":2344},"// 手机库存不足\n",{"type":17,"tag":18,"props":2346,"children":2347},{},[2348],{"type":33,"value":2349},"以上的代码经过责任链处理之后特别的清晰，并且减少了大量的if-else嵌套，每个链的职责分，我们可以看出责任链模式存在的优点：",{"type":17,"tag":2351,"props":2352,"children":2353},"ol",{},[2354,2359],{"type":17,"tag":783,"props":2355,"children":2356},{},[2357],{"type":33,"value":2358},"降低了代码之间的耦合，很好的对每个处理逻辑进行封装。在每个链条内，只需要关注自身的逻辑实现。",{"type":17,"tag":783,"props":2360,"children":2361},{},[2362],{"type":33,"value":2363},"增强了代码的可维护性。我们可以很轻易在原有链条内的任何位置添加新的节点，或者对链条内的节点进行替换或者删除。",{"type":17,"tag":18,"props":2365,"children":2366},{},[2367,2369,2375],{"type":33,"value":2368},"责任链特别的灵活，如果说后面pm找我们加需求了，多了一个预付定金400，返回80元优惠券，处理起来也是易如反掌，只需要在",{"type":17,"tag":65,"props":2370,"children":2372},{"className":2371},[],[2373],{"type":33,"value":2374},"order500",{"type":33,"value":2376},"下面加多一个节点处理即可：",{"type":17,"tag":93,"props":2378,"children":2380},{"className":95,"code":2379,"language":97,"meta":7,"style":7},"    ... \n    resChain.add('order500', (_, next) => {\n        if (orderType === 1 && pay === true) {\n            console.log('500元定金预购，拿到100元优惠券');\n            return;\n        }\n        next();\n    })\n    \n    resChain.add('order400', (_, next) => {\n        if (orderType === 3 && pay === true) {\n            console.log('400元定金预购，拿80元优惠券');\n            return;\n        }\n        next();\n    })\n    \n    resChain.add('order200', (_, next) => {\n        if (orderType === 2 && pay === true) {\n            console.log('200元定金预购，拿到50元优惠券');\n            return;\n        }\n        next();\n    })\n    ...\n",[2381],{"type":17,"tag":65,"props":2382,"children":2383},{"__ignoreMap":7},[2384,2397,2444,2483,2506,2517,2524,2535,2542,2549,2597,2636,2660,2671,2678,2689,2696,2703,2750,2789,2812,2823,2830,2841,2848],{"type":17,"tag":103,"props":2385,"children":2386},{"class":105,"line":106},[2387,2392],{"type":17,"tag":103,"props":2388,"children":2389},{"style":110},[2390],{"type":33,"value":2391},"    ...",{"type":17,"tag":103,"props":2393,"children":2394},{"style":133},[2395],{"type":33,"value":2396}," \n",{"type":17,"tag":103,"props":2398,"children":2399},{"class":105,"line":150},[2400,2404,2408,2412,2416,2420,2424,2428,2432,2436,2440],{"type":17,"tag":103,"props":2401,"children":2402},{"style":133},[2403],{"type":33,"value":1613},{"type":17,"tag":103,"props":2405,"children":2406},{"style":127},[2407],{"type":33,"value":1618},{"type":17,"tag":103,"props":2409,"children":2410},{"style":133},[2411],{"type":33,"value":136},{"type":17,"tag":103,"props":2413,"children":2414},{"style":139},[2415],{"type":33,"value":1627},{"type":17,"tag":103,"props":2417,"children":2418},{"style":133},[2419],{"type":33,"value":1632},{"type":17,"tag":103,"props":2421,"children":2422},{"style":219},[2423],{"type":33,"value":1637},{"type":17,"tag":103,"props":2425,"children":2426},{"style":133},[2427],{"type":33,"value":227},{"type":17,"tag":103,"props":2429,"children":2430},{"style":219},[2431],{"type":33,"value":232},{"type":17,"tag":103,"props":2433,"children":2434},{"style":133},[2435],{"type":33,"value":237},{"type":17,"tag":103,"props":2437,"children":2438},{"style":110},[2439],{"type":33,"value":242},{"type":17,"tag":103,"props":2441,"children":2442},{"style":133},[2443],{"type":33,"value":247},{"type":17,"tag":103,"props":2445,"children":2446},{"class":105,"line":181},[2447,2451,2455,2459,2463,2467,2471,2475,2479],{"type":17,"tag":103,"props":2448,"children":2449},{"style":110},[2450],{"type":33,"value":1190},{"type":17,"tag":103,"props":2452,"children":2453},{"style":133},[2454],{"type":33,"value":906},{"type":17,"tag":103,"props":2456,"children":2457},{"style":110},[2458],{"type":33,"value":266},{"type":17,"tag":103,"props":2460,"children":2461},{"style":116},[2462],{"type":33,"value":915},{"type":17,"tag":103,"props":2464,"children":2465},{"style":110},[2466],{"type":33,"value":1681},{"type":17,"tag":103,"props":2468,"children":2469},{"style":133},[2470],{"type":33,"value":1686},{"type":17,"tag":103,"props":2472,"children":2473},{"style":110},[2474],{"type":33,"value":266},{"type":17,"tag":103,"props":2476,"children":2477},{"style":116},[2478],{"type":33,"value":941},{"type":17,"tag":103,"props":2480,"children":2481},{"style":133},[2482],{"type":33,"value":276},{"type":17,"tag":103,"props":2484,"children":2485},{"class":105,"line":191},[2486,2490,2494,2498,2502],{"type":17,"tag":103,"props":2487,"children":2488},{"style":133},[2489],{"type":33,"value":1706},{"type":17,"tag":103,"props":2491,"children":2492},{"style":127},[2493],{"type":33,"value":958},{"type":17,"tag":103,"props":2495,"children":2496},{"style":133},[2497],{"type":33,"value":136},{"type":17,"tag":103,"props":2499,"children":2500},{"style":139},[2501],{"type":33,"value":1719},{"type":17,"tag":103,"props":2503,"children":2504},{"style":133},[2505],{"type":33,"value":147},{"type":17,"tag":103,"props":2507,"children":2508},{"class":105,"line":250},[2509,2513],{"type":17,"tag":103,"props":2510,"children":2511},{"style":110},[2512],{"type":33,"value":1731},{"type":17,"tag":103,"props":2514,"children":2515},{"style":133},[2516],{"type":33,"value":300},{"type":17,"tag":103,"props":2518,"children":2519},{"class":105,"line":279},[2520],{"type":17,"tag":103,"props":2521,"children":2522},{"style":133},[2523],{"type":33,"value":1277},{"type":17,"tag":103,"props":2525,"children":2526},{"class":105,"line":303},[2527,2531],{"type":17,"tag":103,"props":2528,"children":2529},{"style":127},[2530],{"type":33,"value":1750},{"type":17,"tag":103,"props":2532,"children":2533},{"style":133},[2534],{"type":33,"value":178},{"type":17,"tag":103,"props":2536,"children":2537},{"class":105,"line":316},[2538],{"type":17,"tag":103,"props":2539,"children":2540},{"style":133},[2541],{"type":33,"value":1767},{"type":17,"tag":103,"props":2543,"children":2544},{"class":105,"line":325},[2545],{"type":17,"tag":103,"props":2546,"children":2547},{"style":133},[2548],{"type":33,"value":1605},{"type":17,"tag":103,"props":2550,"children":2551},{"class":105,"line":334},[2552,2556,2560,2564,2569,2573,2577,2581,2585,2589,2593],{"type":17,"tag":103,"props":2553,"children":2554},{"style":133},[2555],{"type":33,"value":1613},{"type":17,"tag":103,"props":2557,"children":2558},{"style":127},[2559],{"type":33,"value":1618},{"type":17,"tag":103,"props":2561,"children":2562},{"style":133},[2563],{"type":33,"value":136},{"type":17,"tag":103,"props":2565,"children":2566},{"style":139},[2567],{"type":33,"value":2568},"'order400'",{"type":17,"tag":103,"props":2570,"children":2571},{"style":133},[2572],{"type":33,"value":1632},{"type":17,"tag":103,"props":2574,"children":2575},{"style":219},[2576],{"type":33,"value":1637},{"type":17,"tag":103,"props":2578,"children":2579},{"style":133},[2580],{"type":33,"value":227},{"type":17,"tag":103,"props":2582,"children":2583},{"style":219},[2584],{"type":33,"value":232},{"type":17,"tag":103,"props":2586,"children":2587},{"style":133},[2588],{"type":33,"value":237},{"type":17,"tag":103,"props":2590,"children":2591},{"style":110},[2592],{"type":33,"value":242},{"type":17,"tag":103,"props":2594,"children":2595},{"style":133},[2596],{"type":33,"value":247},{"type":17,"tag":103,"props":2598,"children":2599},{"class":105,"line":354},[2600,2604,2608,2612,2616,2620,2624,2628,2632],{"type":17,"tag":103,"props":2601,"children":2602},{"style":110},[2603],{"type":33,"value":1190},{"type":17,"tag":103,"props":2605,"children":2606},{"style":133},[2607],{"type":33,"value":906},{"type":17,"tag":103,"props":2609,"children":2610},{"style":110},[2611],{"type":33,"value":266},{"type":17,"tag":103,"props":2613,"children":2614},{"style":116},[2615],{"type":33,"value":1313},{"type":17,"tag":103,"props":2617,"children":2618},{"style":110},[2619],{"type":33,"value":1681},{"type":17,"tag":103,"props":2621,"children":2622},{"style":133},[2623],{"type":33,"value":1686},{"type":17,"tag":103,"props":2625,"children":2626},{"style":110},[2627],{"type":33,"value":266},{"type":17,"tag":103,"props":2629,"children":2630},{"style":116},[2631],{"type":33,"value":941},{"type":17,"tag":103,"props":2633,"children":2634},{"style":133},[2635],{"type":33,"value":276},{"type":17,"tag":103,"props":2637,"children":2638},{"class":105,"line":363},[2639,2643,2647,2651,2656],{"type":17,"tag":103,"props":2640,"children":2641},{"style":133},[2642],{"type":33,"value":1706},{"type":17,"tag":103,"props":2644,"children":2645},{"style":127},[2646],{"type":33,"value":958},{"type":17,"tag":103,"props":2648,"children":2649},{"style":133},[2650],{"type":33,"value":136},{"type":17,"tag":103,"props":2652,"children":2653},{"style":139},[2654],{"type":33,"value":2655},"'400元定金预购，拿80元优惠券'",{"type":17,"tag":103,"props":2657,"children":2658},{"style":133},[2659],{"type":33,"value":147},{"type":17,"tag":103,"props":2661,"children":2662},{"class":105,"line":371},[2663,2667],{"type":17,"tag":103,"props":2664,"children":2665},{"style":110},[2666],{"type":33,"value":1731},{"type":17,"tag":103,"props":2668,"children":2669},{"style":133},[2670],{"type":33,"value":300},{"type":17,"tag":103,"props":2672,"children":2673},{"class":105,"line":419},[2674],{"type":17,"tag":103,"props":2675,"children":2676},{"style":133},[2677],{"type":33,"value":1277},{"type":17,"tag":103,"props":2679,"children":2680},{"class":105,"line":444},[2681,2685],{"type":17,"tag":103,"props":2682,"children":2683},{"style":127},[2684],{"type":33,"value":1750},{"type":17,"tag":103,"props":2686,"children":2687},{"style":133},[2688],{"type":33,"value":178},{"type":17,"tag":103,"props":2690,"children":2691},{"class":105,"line":465},[2692],{"type":17,"tag":103,"props":2693,"children":2694},{"style":133},[2695],{"type":33,"value":1767},{"type":17,"tag":103,"props":2697,"children":2698},{"class":105,"line":477},[2699],{"type":17,"tag":103,"props":2700,"children":2701},{"style":133},[2702],{"type":33,"value":1605},{"type":17,"tag":103,"props":2704,"children":2705},{"class":105,"line":485},[2706,2710,2714,2718,2722,2726,2730,2734,2738,2742,2746],{"type":17,"tag":103,"props":2707,"children":2708},{"style":133},[2709],{"type":33,"value":1613},{"type":17,"tag":103,"props":2711,"children":2712},{"style":127},[2713],{"type":33,"value":1618},{"type":17,"tag":103,"props":2715,"children":2716},{"style":133},[2717],{"type":33,"value":136},{"type":17,"tag":103,"props":2719,"children":2720},{"style":139},[2721],{"type":33,"value":1794},{"type":17,"tag":103,"props":2723,"children":2724},{"style":133},[2725],{"type":33,"value":1632},{"type":17,"tag":103,"props":2727,"children":2728},{"style":219},[2729],{"type":33,"value":1637},{"type":17,"tag":103,"props":2731,"children":2732},{"style":133},[2733],{"type":33,"value":227},{"type":17,"tag":103,"props":2735,"children":2736},{"style":219},[2737],{"type":33,"value":232},{"type":17,"tag":103,"props":2739,"children":2740},{"style":133},[2741],{"type":33,"value":237},{"type":17,"tag":103,"props":2743,"children":2744},{"style":110},[2745],{"type":33,"value":242},{"type":17,"tag":103,"props":2747,"children":2748},{"style":133},[2749],{"type":33,"value":247},{"type":17,"tag":103,"props":2751,"children":2752},{"class":105,"line":493},[2753,2757,2761,2765,2769,2773,2777,2781,2785],{"type":17,"tag":103,"props":2754,"children":2755},{"style":110},[2756],{"type":33,"value":1190},{"type":17,"tag":103,"props":2758,"children":2759},{"style":133},[2760],{"type":33,"value":906},{"type":17,"tag":103,"props":2762,"children":2763},{"style":110},[2764],{"type":33,"value":266},{"type":17,"tag":103,"props":2766,"children":2767},{"style":116},[2768],{"type":33,"value":1116},{"type":17,"tag":103,"props":2770,"children":2771},{"style":110},[2772],{"type":33,"value":1681},{"type":17,"tag":103,"props":2774,"children":2775},{"style":133},[2776],{"type":33,"value":1686},{"type":17,"tag":103,"props":2778,"children":2779},{"style":110},[2780],{"type":33,"value":266},{"type":17,"tag":103,"props":2782,"children":2783},{"style":116},[2784],{"type":33,"value":941},{"type":17,"tag":103,"props":2786,"children":2787},{"style":133},[2788],{"type":33,"value":276},{"type":17,"tag":103,"props":2790,"children":2791},{"class":105,"line":501},[2792,2796,2800,2804,2808],{"type":17,"tag":103,"props":2793,"children":2794},{"style":133},[2795],{"type":33,"value":1706},{"type":17,"tag":103,"props":2797,"children":2798},{"style":127},[2799],{"type":33,"value":958},{"type":17,"tag":103,"props":2801,"children":2802},{"style":133},[2803],{"type":33,"value":136},{"type":17,"tag":103,"props":2805,"children":2806},{"style":139},[2807],{"type":33,"value":1881},{"type":17,"tag":103,"props":2809,"children":2810},{"style":133},[2811],{"type":33,"value":147},{"type":17,"tag":103,"props":2813,"children":2814},{"class":105,"line":1287},[2815,2819],{"type":17,"tag":103,"props":2816,"children":2817},{"style":110},[2818],{"type":33,"value":1731},{"type":17,"tag":103,"props":2820,"children":2821},{"style":133},[2822],{"type":33,"value":300},{"type":17,"tag":103,"props":2824,"children":2825},{"class":105,"line":1320},[2826],{"type":17,"tag":103,"props":2827,"children":2828},{"style":133},[2829],{"type":33,"value":1277},{"type":17,"tag":103,"props":2831,"children":2832},{"class":105,"line":1344},[2833,2837],{"type":17,"tag":103,"props":2834,"children":2835},{"style":127},[2836],{"type":33,"value":1750},{"type":17,"tag":103,"props":2838,"children":2839},{"style":133},[2840],{"type":33,"value":178},{"type":17,"tag":103,"props":2842,"children":2843},{"class":105,"line":1368},[2844],{"type":17,"tag":103,"props":2845,"children":2846},{"style":133},[2847],{"type":33,"value":1767},{"type":17,"tag":103,"props":2849,"children":2850},{"class":105,"line":1384},[2851],{"type":17,"tag":103,"props":2852,"children":2853},{"style":110},[2854],{"type":33,"value":2855},"    ...\n",{"type":17,"tag":18,"props":2857,"children":2858},{},[2859,2861,2867],{"type":33,"value":2860},"就是这么简单。那这个",{"type":17,"tag":65,"props":2862,"children":2864},{"className":2863},[],[2865],{"type":33,"value":2866},"ResChain",{"type":33,"value":2868},"是如何实现的呢？",{"type":17,"tag":28,"props":2870,"children":2872},{"id":2871},"封装reschain",[2873],{"type":33,"value":2874},"封装ResChain",{"type":17,"tag":18,"props":2876,"children":2877},{},[2878,2880,2885,2887,2892],{"type":33,"value":2879},"先别急，首先我们来了解一下",{"type":17,"tag":65,"props":2881,"children":2883},{"className":2882},[],[2884],{"type":33,"value":70},{"type":33,"value":2886},"是如何实现：在链节点的回调函数内",{"type":17,"tag":65,"props":2888,"children":2890},{"className":2889},[],[2891],{"type":33,"value":232},{"type":33,"value":2893},"就可以跳到下一个节点的呢？",{"type":17,"tag":18,"props":2895,"children":2896},{},[2897,2899,2908],{"type":33,"value":2898},"话不多说，直接看源码，参考的库是",{"type":17,"tag":2900,"props":2901,"children":2905},"a",{"href":2902,"rel":2903},"https://github.com/koajs/compose",[2904],"nofollow",[2906],{"type":33,"value":2907},"koa-compose",{"type":33,"value":2909},"，代码也是特别的简洁：",{"type":17,"tag":93,"props":2911,"children":2913},{"className":95,"code":2912,"language":97,"meta":7,"style":7},"function compose (middleware) {\n    // 这里传入的middleware是函数数组，类似的结构为： [fn1, fn2, fn3, fn4, ...]\n  if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!')\n  for (const fn of middleware) {\n    if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')\n  }\n\n  return function (context, next) {\n    // last called middleware #\n    let index = -1\n    return dispatch(0)\n    function dispatch (i) {\n      // 这里是防止重复调用next\n      if (i \u003C= index) return Promise.reject(new Error('next() called multiple times'))\n      index = i\n      let fn = middleware[i]\n      if (i === middleware.length) fn = next\n      if (!fn) return Promise.resolve()\n      try {\n        // next函数其实就是middleware的下一个函数，执行next就是执行下一个函数\n        return Promise.resolve(fn(context, dispatch.bind(null, i + 1)))\n      } catch (err) {\n        return Promise.reject(err)\n      }\n    }\n  }\n}\n",[2914],{"type":17,"tag":65,"props":2915,"children":2916},{"__ignoreMap":7},[2917,2942,2950,3008,3039,3099,3106,3113,3146,3154,3181,3205,3230,3238,3308,3325,3346,3385,3426,3438,3446,3513,3530,3554,3561,3569,3576],{"type":17,"tag":103,"props":2918,"children":2919},{"class":105,"line":106},[2920,2924,2929,2933,2938],{"type":17,"tag":103,"props":2921,"children":2922},{"style":110},[2923],{"type":33,"value":1517},{"type":17,"tag":103,"props":2925,"children":2926},{"style":127},[2927],{"type":33,"value":2928}," compose",{"type":17,"tag":103,"props":2930,"children":2931},{"style":133},[2932],{"type":33,"value":216},{"type":17,"tag":103,"props":2934,"children":2935},{"style":219},[2936],{"type":33,"value":2937},"middleware",{"type":17,"tag":103,"props":2939,"children":2940},{"style":133},[2941],{"type":33,"value":276},{"type":17,"tag":103,"props":2943,"children":2944},{"class":105,"line":150},[2945],{"type":17,"tag":103,"props":2946,"children":2947},{"style":348},[2948],{"type":33,"value":2949},"    // 这里传入的middleware是函数数组，类似的结构为： [fn1, fn2, fn3, fn4, ...]\n",{"type":17,"tag":103,"props":2951,"children":2952},{"class":105,"line":181},[2953,2957,2961,2966,2971,2976,2981,2986,2990,2995,2999,3004],{"type":17,"tag":103,"props":2954,"children":2955},{"style":110},[2956],{"type":33,"value":256},{"type":17,"tag":103,"props":2958,"children":2959},{"style":133},[2960],{"type":33,"value":216},{"type":17,"tag":103,"props":2962,"children":2963},{"style":110},[2964],{"type":33,"value":2965},"!",{"type":17,"tag":103,"props":2967,"children":2968},{"style":133},[2969],{"type":33,"value":2970},"Array.",{"type":17,"tag":103,"props":2972,"children":2973},{"style":127},[2974],{"type":33,"value":2975},"isArray",{"type":17,"tag":103,"props":2977,"children":2978},{"style":133},[2979],{"type":33,"value":2980},"(middleware)) ",{"type":17,"tag":103,"props":2982,"children":2983},{"style":110},[2984],{"type":33,"value":2985},"throw",{"type":17,"tag":103,"props":2987,"children":2988},{"style":110},[2989],{"type":33,"value":169},{"type":17,"tag":103,"props":2991,"children":2992},{"style":127},[2993],{"type":33,"value":2994}," TypeError",{"type":17,"tag":103,"props":2996,"children":2997},{"style":133},[2998],{"type":33,"value":136},{"type":17,"tag":103,"props":3000,"children":3001},{"style":139},[3002],{"type":33,"value":3003},"'Middleware stack must be an array!'",{"type":17,"tag":103,"props":3005,"children":3006},{"style":133},[3007],{"type":33,"value":972},{"type":17,"tag":103,"props":3009,"children":3010},{"class":105,"line":191},[3011,3016,3020,3024,3029,3034],{"type":17,"tag":103,"props":3012,"children":3013},{"style":110},[3014],{"type":33,"value":3015},"  for",{"type":17,"tag":103,"props":3017,"children":3018},{"style":133},[3019],{"type":33,"value":216},{"type":17,"tag":103,"props":3021,"children":3022},{"style":110},[3023],{"type":33,"value":113},{"type":17,"tag":103,"props":3025,"children":3026},{"style":116},[3027],{"type":33,"value":3028}," fn",{"type":17,"tag":103,"props":3030,"children":3031},{"style":110},[3032],{"type":33,"value":3033}," of",{"type":17,"tag":103,"props":3035,"children":3036},{"style":133},[3037],{"type":33,"value":3038}," middleware) {\n",{"type":17,"tag":103,"props":3040,"children":3041},{"class":105,"line":250},[3042,3046,3050,3055,3060,3065,3070,3074,3078,3082,3086,3090,3095],{"type":17,"tag":103,"props":3043,"children":3044},{"style":110},[3045],{"type":33,"value":927},{"type":17,"tag":103,"props":3047,"children":3048},{"style":133},[3049],{"type":33,"value":216},{"type":17,"tag":103,"props":3051,"children":3052},{"style":110},[3053],{"type":33,"value":3054},"typeof",{"type":17,"tag":103,"props":3056,"children":3057},{"style":133},[3058],{"type":33,"value":3059}," fn ",{"type":17,"tag":103,"props":3061,"children":3062},{"style":110},[3063],{"type":33,"value":3064},"!==",{"type":17,"tag":103,"props":3066,"children":3067},{"style":139},[3068],{"type":33,"value":3069}," 'function'",{"type":17,"tag":103,"props":3071,"children":3072},{"style":133},[3073],{"type":33,"value":237},{"type":17,"tag":103,"props":3075,"children":3076},{"style":110},[3077],{"type":33,"value":2985},{"type":17,"tag":103,"props":3079,"children":3080},{"style":110},[3081],{"type":33,"value":169},{"type":17,"tag":103,"props":3083,"children":3084},{"style":127},[3085],{"type":33,"value":2994},{"type":17,"tag":103,"props":3087,"children":3088},{"style":133},[3089],{"type":33,"value":136},{"type":17,"tag":103,"props":3091,"children":3092},{"style":139},[3093],{"type":33,"value":3094},"'Middleware must be composed of functions!'",{"type":17,"tag":103,"props":3096,"children":3097},{"style":133},[3098],{"type":33,"value":972},{"type":17,"tag":103,"props":3100,"children":3101},{"class":105,"line":279},[3102],{"type":17,"tag":103,"props":3103,"children":3104},{"style":133},[3105],{"type":33,"value":322},{"type":17,"tag":103,"props":3107,"children":3108},{"class":105,"line":303},[3109],{"type":17,"tag":103,"props":3110,"children":3111},{"emptyLinePlaceholder":185},[3112],{"type":33,"value":188},{"type":17,"tag":103,"props":3114,"children":3115},{"class":105,"line":316},[3116,3121,3125,3129,3134,3138,3142],{"type":17,"tag":103,"props":3117,"children":3118},{"style":110},[3119],{"type":33,"value":3120},"  return",{"type":17,"tag":103,"props":3122,"children":3123},{"style":110},[3124],{"type":33,"value":863},{"type":17,"tag":103,"props":3126,"children":3127},{"style":133},[3128],{"type":33,"value":216},{"type":17,"tag":103,"props":3130,"children":3131},{"style":219},[3132],{"type":33,"value":3133},"context",{"type":17,"tag":103,"props":3135,"children":3136},{"style":133},[3137],{"type":33,"value":227},{"type":17,"tag":103,"props":3139,"children":3140},{"style":219},[3141],{"type":33,"value":232},{"type":17,"tag":103,"props":3143,"children":3144},{"style":133},[3145],{"type":33,"value":276},{"type":17,"tag":103,"props":3147,"children":3148},{"class":105,"line":325},[3149],{"type":17,"tag":103,"props":3150,"children":3151},{"style":348},[3152],{"type":33,"value":3153},"    // last called middleware #\n",{"type":17,"tag":103,"props":3155,"children":3156},{"class":105,"line":334},[3157,3162,3167,3171,3176],{"type":17,"tag":103,"props":3158,"children":3159},{"style":110},[3160],{"type":33,"value":3161},"    let",{"type":17,"tag":103,"props":3163,"children":3164},{"style":133},[3165],{"type":33,"value":3166}," index ",{"type":17,"tag":103,"props":3168,"children":3169},{"style":110},[3170],{"type":33,"value":290},{"type":17,"tag":103,"props":3172,"children":3173},{"style":110},[3174],{"type":33,"value":3175}," -",{"type":17,"tag":103,"props":3177,"children":3178},{"style":116},[3179],{"type":33,"value":3180},"1\n",{"type":17,"tag":103,"props":3182,"children":3183},{"class":105,"line":354},[3184,3188,3193,3197,3201],{"type":17,"tag":103,"props":3185,"children":3186},{"style":110},[3187],{"type":33,"value":309},{"type":17,"tag":103,"props":3189,"children":3190},{"style":127},[3191],{"type":33,"value":3192}," dispatch",{"type":17,"tag":103,"props":3194,"children":3195},{"style":133},[3196],{"type":33,"value":136},{"type":17,"tag":103,"props":3198,"children":3199},{"style":116},[3200],{"type":33,"value":2334},{"type":17,"tag":103,"props":3202,"children":3203},{"style":133},[3204],{"type":33,"value":972},{"type":17,"tag":103,"props":3206,"children":3207},{"class":105,"line":363},[3208,3213,3217,3221,3226],{"type":17,"tag":103,"props":3209,"children":3210},{"style":110},[3211],{"type":33,"value":3212},"    function",{"type":17,"tag":103,"props":3214,"children":3215},{"style":127},[3216],{"type":33,"value":3192},{"type":17,"tag":103,"props":3218,"children":3219},{"style":133},[3220],{"type":33,"value":216},{"type":17,"tag":103,"props":3222,"children":3223},{"style":219},[3224],{"type":33,"value":3225},"i",{"type":17,"tag":103,"props":3227,"children":3228},{"style":133},[3229],{"type":33,"value":276},{"type":17,"tag":103,"props":3231,"children":3232},{"class":105,"line":371},[3233],{"type":17,"tag":103,"props":3234,"children":3235},{"style":348},[3236],{"type":33,"value":3237},"      // 这里是防止重复调用next\n",{"type":17,"tag":103,"props":3239,"children":3240},{"class":105,"line":419},[3241,3245,3250,3255,3260,3265,3270,3275,3280,3284,3289,3294,3298,3303],{"type":17,"tag":103,"props":3242,"children":3243},{"style":110},[3244],{"type":33,"value":996},{"type":17,"tag":103,"props":3246,"children":3247},{"style":133},[3248],{"type":33,"value":3249}," (i ",{"type":17,"tag":103,"props":3251,"children":3252},{"style":110},[3253],{"type":33,"value":3254},"\u003C=",{"type":17,"tag":103,"props":3256,"children":3257},{"style":133},[3258],{"type":33,"value":3259}," index) ",{"type":17,"tag":103,"props":3261,"children":3262},{"style":110},[3263],{"type":33,"value":3264},"return",{"type":17,"tag":103,"props":3266,"children":3267},{"style":116},[3268],{"type":33,"value":3269}," Promise",{"type":17,"tag":103,"props":3271,"children":3272},{"style":133},[3273],{"type":33,"value":3274},".",{"type":17,"tag":103,"props":3276,"children":3277},{"style":127},[3278],{"type":33,"value":3279},"reject",{"type":17,"tag":103,"props":3281,"children":3282},{"style":133},[3283],{"type":33,"value":136},{"type":17,"tag":103,"props":3285,"children":3286},{"style":110},[3287],{"type":33,"value":3288},"new",{"type":17,"tag":103,"props":3290,"children":3291},{"style":127},[3292],{"type":33,"value":3293}," Error",{"type":17,"tag":103,"props":3295,"children":3296},{"style":133},[3297],{"type":33,"value":136},{"type":17,"tag":103,"props":3299,"children":3300},{"style":139},[3301],{"type":33,"value":3302},"'next() called multiple times'",{"type":17,"tag":103,"props":3304,"children":3305},{"style":133},[3306],{"type":33,"value":3307},"))\n",{"type":17,"tag":103,"props":3309,"children":3310},{"class":105,"line":444},[3311,3316,3320],{"type":17,"tag":103,"props":3312,"children":3313},{"style":133},[3314],{"type":33,"value":3315},"      index ",{"type":17,"tag":103,"props":3317,"children":3318},{"style":110},[3319],{"type":33,"value":290},{"type":17,"tag":103,"props":3321,"children":3322},{"style":133},[3323],{"type":33,"value":3324}," i\n",{"type":17,"tag":103,"props":3326,"children":3327},{"class":105,"line":465},[3328,3333,3337,3341],{"type":17,"tag":103,"props":3329,"children":3330},{"style":110},[3331],{"type":33,"value":3332},"      let",{"type":17,"tag":103,"props":3334,"children":3335},{"style":133},[3336],{"type":33,"value":3059},{"type":17,"tag":103,"props":3338,"children":3339},{"style":110},[3340],{"type":33,"value":290},{"type":17,"tag":103,"props":3342,"children":3343},{"style":133},[3344],{"type":33,"value":3345}," middleware[i]\n",{"type":17,"tag":103,"props":3347,"children":3348},{"class":105,"line":477},[3349,3353,3357,3361,3366,3371,3376,3380],{"type":17,"tag":103,"props":3350,"children":3351},{"style":110},[3352],{"type":33,"value":996},{"type":17,"tag":103,"props":3354,"children":3355},{"style":133},[3356],{"type":33,"value":3249},{"type":17,"tag":103,"props":3358,"children":3359},{"style":110},[3360],{"type":33,"value":266},{"type":17,"tag":103,"props":3362,"children":3363},{"style":133},[3364],{"type":33,"value":3365}," middleware.",{"type":17,"tag":103,"props":3367,"children":3368},{"style":116},[3369],{"type":33,"value":3370},"length",{"type":17,"tag":103,"props":3372,"children":3373},{"style":133},[3374],{"type":33,"value":3375},") fn ",{"type":17,"tag":103,"props":3377,"children":3378},{"style":110},[3379],{"type":33,"value":290},{"type":17,"tag":103,"props":3381,"children":3382},{"style":133},[3383],{"type":33,"value":3384}," next\n",{"type":17,"tag":103,"props":3386,"children":3387},{"class":105,"line":485},[3388,3392,3396,3400,3405,3409,3413,3417,3422],{"type":17,"tag":103,"props":3389,"children":3390},{"style":110},[3391],{"type":33,"value":996},{"type":17,"tag":103,"props":3393,"children":3394},{"style":133},[3395],{"type":33,"value":216},{"type":17,"tag":103,"props":3397,"children":3398},{"style":110},[3399],{"type":33,"value":2965},{"type":17,"tag":103,"props":3401,"children":3402},{"style":133},[3403],{"type":33,"value":3404},"fn) ",{"type":17,"tag":103,"props":3406,"children":3407},{"style":110},[3408],{"type":33,"value":3264},{"type":17,"tag":103,"props":3410,"children":3411},{"style":116},[3412],{"type":33,"value":3269},{"type":17,"tag":103,"props":3414,"children":3415},{"style":133},[3416],{"type":33,"value":3274},{"type":17,"tag":103,"props":3418,"children":3419},{"style":127},[3420],{"type":33,"value":3421},"resolve",{"type":17,"tag":103,"props":3423,"children":3424},{"style":133},[3425],{"type":33,"value":1597},{"type":17,"tag":103,"props":3427,"children":3428},{"class":105,"line":493},[3429,3434],{"type":17,"tag":103,"props":3430,"children":3431},{"style":110},[3432],{"type":33,"value":3433},"      try",{"type":17,"tag":103,"props":3435,"children":3436},{"style":133},[3437],{"type":33,"value":247},{"type":17,"tag":103,"props":3439,"children":3440},{"class":105,"line":501},[3441],{"type":17,"tag":103,"props":3442,"children":3443},{"style":348},[3444],{"type":33,"value":3445},"        // next函数其实就是middleware的下一个函数，执行next就是执行下一个函数\n",{"type":17,"tag":103,"props":3447,"children":3448},{"class":105,"line":1287},[3449,3454,3458,3462,3466,3470,3475,3480,3485,3489,3494,3499,3504,3508],{"type":17,"tag":103,"props":3450,"children":3451},{"style":110},[3452],{"type":33,"value":3453},"        return",{"type":17,"tag":103,"props":3455,"children":3456},{"style":116},[3457],{"type":33,"value":3269},{"type":17,"tag":103,"props":3459,"children":3460},{"style":133},[3461],{"type":33,"value":3274},{"type":17,"tag":103,"props":3463,"children":3464},{"style":127},[3465],{"type":33,"value":3421},{"type":17,"tag":103,"props":3467,"children":3468},{"style":133},[3469],{"type":33,"value":136},{"type":17,"tag":103,"props":3471,"children":3472},{"style":127},[3473],{"type":33,"value":3474},"fn",{"type":17,"tag":103,"props":3476,"children":3477},{"style":133},[3478],{"type":33,"value":3479},"(context, dispatch.",{"type":17,"tag":103,"props":3481,"children":3482},{"style":127},[3483],{"type":33,"value":3484},"bind",{"type":17,"tag":103,"props":3486,"children":3487},{"style":133},[3488],{"type":33,"value":136},{"type":17,"tag":103,"props":3490,"children":3491},{"style":116},[3492],{"type":33,"value":3493},"null",{"type":17,"tag":103,"props":3495,"children":3496},{"style":133},[3497],{"type":33,"value":3498},", i ",{"type":17,"tag":103,"props":3500,"children":3501},{"style":110},[3502],{"type":33,"value":3503},"+",{"type":17,"tag":103,"props":3505,"children":3506},{"style":116},[3507],{"type":33,"value":915},{"type":17,"tag":103,"props":3509,"children":3510},{"style":133},[3511],{"type":33,"value":3512},")))\n",{"type":17,"tag":103,"props":3514,"children":3515},{"class":105,"line":1320},[3516,3520,3525],{"type":17,"tag":103,"props":3517,"children":3518},{"style":133},[3519],{"type":33,"value":1048},{"type":17,"tag":103,"props":3521,"children":3522},{"style":110},[3523],{"type":33,"value":3524},"catch",{"type":17,"tag":103,"props":3526,"children":3527},{"style":133},[3528],{"type":33,"value":3529}," (err) {\n",{"type":17,"tag":103,"props":3531,"children":3532},{"class":105,"line":1344},[3533,3537,3541,3545,3549],{"type":17,"tag":103,"props":3534,"children":3535},{"style":110},[3536],{"type":33,"value":3453},{"type":17,"tag":103,"props":3538,"children":3539},{"style":116},[3540],{"type":33,"value":3269},{"type":17,"tag":103,"props":3542,"children":3543},{"style":133},[3544],{"type":33,"value":3274},{"type":17,"tag":103,"props":3546,"children":3547},{"style":127},[3548],{"type":33,"value":3279},{"type":17,"tag":103,"props":3550,"children":3551},{"style":133},[3552],{"type":33,"value":3553},"(err)\n",{"type":17,"tag":103,"props":3555,"children":3556},{"class":105,"line":1368},[3557],{"type":17,"tag":103,"props":3558,"children":3559},{"style":133},[3560],{"type":33,"value":1088},{"type":17,"tag":103,"props":3562,"children":3563},{"class":105,"line":1384},[3564],{"type":17,"tag":103,"props":3565,"children":3566},{"style":133},[3567],{"type":33,"value":3568},"    }\n",{"type":17,"tag":103,"props":3570,"children":3571},{"class":105,"line":1408},[3572],{"type":17,"tag":103,"props":3573,"children":3574},{"style":133},[3575],{"type":33,"value":322},{"type":17,"tag":103,"props":3577,"children":3578},{"class":105,"line":1417},[3579],{"type":17,"tag":103,"props":3580,"children":3581},{"style":133},[3582],{"type":33,"value":1431},{"type":17,"tag":18,"props":3584,"children":3585},{},[3586,3588,3593],{"type":33,"value":3587},"原理很简单吧，接下来我们来实现",{"type":17,"tag":65,"props":3589,"children":3591},{"className":3590},[],[3592],{"type":33,"value":2866},{"type":33,"value":3594},":",{"type":17,"tag":93,"props":3596,"children":3598},{"className":95,"code":3597,"language":97,"meta":7,"style":7},"export class ResChain {\n  \n  /**\n   * 按顺序存放链的key\n   */\n  keyOrder = [];\n  /**\n   * key对应的函数\n   */\n  key2FnMap = new Map();\n  /**\n   * 每个节点都可以拿到的对象\n   */\n  ctx = {}\n  constructor(ctx) {\n    this.ctx = ctx;\n  }\n\n  add(key: string, callback) {\n    if (this.key2FnMap.has(key)) {\n      throw new Error(`Chain ${key} already exists`);\n    }\n\n    this.keyOrder.push(key);\n    this.key2FnMap.set(key, callback);\n    return this;\n  }\n\n  async run() {\n    let index = -1;\n    const dispatch = (i) => {\n      if (i \u003C= index) {\n        return Promise.reject(new Error('next() called multiple times'));\n      }\n\n      index = i;\n      const fn = this.key2FnMap.get(this.keyOrder[i]);\n      if (!fn) {\n        return Promise.resolve(void 0);\n      }\n\n      return fn(this.ctx, dispatch.bind(null, i + 1));\n    };\n\n    return dispatch(0);\n  }\n}\n",[3599],{"type":17,"tag":65,"props":3600,"children":3601},{"__ignoreMap":7},[3602,3623,3630,3638,3646,3654,3671,3678,3686,3693,3718,3725,3733,3740,3757,3777,3799,3806,3813,3852,3883,3921,3928,3935,3957,3978,3994,4001,4008,4026,4053,4088,4108,4152,4159,4166,4182,4224,4244,4280,4288,4296,4350,4359,4367,4391,4399],{"type":17,"tag":103,"props":3603,"children":3604},{"class":105,"line":106},[3605,3610,3615,3619],{"type":17,"tag":103,"props":3606,"children":3607},{"style":110},[3608],{"type":33,"value":3609},"export",{"type":17,"tag":103,"props":3611,"children":3612},{"style":110},[3613],{"type":33,"value":3614}," class",{"type":17,"tag":103,"props":3616,"children":3617},{"style":127},[3618],{"type":33,"value":1592},{"type":17,"tag":103,"props":3620,"children":3621},{"style":133},[3622],{"type":33,"value":247},{"type":17,"tag":103,"props":3624,"children":3625},{"class":105,"line":150},[3626],{"type":17,"tag":103,"props":3627,"children":3628},{"style":133},[3629],{"type":33,"value":331},{"type":17,"tag":103,"props":3631,"children":3632},{"class":105,"line":181},[3633],{"type":17,"tag":103,"props":3634,"children":3635},{"style":348},[3636],{"type":33,"value":3637},"  /**\n",{"type":17,"tag":103,"props":3639,"children":3640},{"class":105,"line":191},[3641],{"type":17,"tag":103,"props":3642,"children":3643},{"style":348},[3644],{"type":33,"value":3645},"   * 按顺序存放链的key\n",{"type":17,"tag":103,"props":3647,"children":3648},{"class":105,"line":250},[3649],{"type":17,"tag":103,"props":3650,"children":3651},{"style":348},[3652],{"type":33,"value":3653},"   */\n",{"type":17,"tag":103,"props":3655,"children":3656},{"class":105,"line":279},[3657,3662,3666],{"type":17,"tag":103,"props":3658,"children":3659},{"style":219},[3660],{"type":33,"value":3661},"  keyOrder",{"type":17,"tag":103,"props":3663,"children":3664},{"style":110},[3665],{"type":33,"value":124},{"type":17,"tag":103,"props":3667,"children":3668},{"style":133},[3669],{"type":33,"value":3670}," [];\n",{"type":17,"tag":103,"props":3672,"children":3673},{"class":105,"line":303},[3674],{"type":17,"tag":103,"props":3675,"children":3676},{"style":348},[3677],{"type":33,"value":3637},{"type":17,"tag":103,"props":3679,"children":3680},{"class":105,"line":316},[3681],{"type":17,"tag":103,"props":3682,"children":3683},{"style":348},[3684],{"type":33,"value":3685},"   * key对应的函数\n",{"type":17,"tag":103,"props":3687,"children":3688},{"class":105,"line":325},[3689],{"type":17,"tag":103,"props":3690,"children":3691},{"style":348},[3692],{"type":33,"value":3653},{"type":17,"tag":103,"props":3694,"children":3695},{"class":105,"line":334},[3696,3701,3705,3709,3714],{"type":17,"tag":103,"props":3697,"children":3698},{"style":219},[3699],{"type":33,"value":3700},"  key2FnMap",{"type":17,"tag":103,"props":3702,"children":3703},{"style":110},[3704],{"type":33,"value":124},{"type":17,"tag":103,"props":3706,"children":3707},{"style":110},[3708],{"type":33,"value":169},{"type":17,"tag":103,"props":3710,"children":3711},{"style":127},[3712],{"type":33,"value":3713}," Map",{"type":17,"tag":103,"props":3715,"children":3716},{"style":133},[3717],{"type":33,"value":178},{"type":17,"tag":103,"props":3719,"children":3720},{"class":105,"line":354},[3721],{"type":17,"tag":103,"props":3722,"children":3723},{"style":348},[3724],{"type":33,"value":3637},{"type":17,"tag":103,"props":3726,"children":3727},{"class":105,"line":363},[3728],{"type":17,"tag":103,"props":3729,"children":3730},{"style":348},[3731],{"type":33,"value":3732},"   * 每个节点都可以拿到的对象\n",{"type":17,"tag":103,"props":3734,"children":3735},{"class":105,"line":371},[3736],{"type":17,"tag":103,"props":3737,"children":3738},{"style":348},[3739],{"type":33,"value":3653},{"type":17,"tag":103,"props":3741,"children":3742},{"class":105,"line":419},[3743,3748,3752],{"type":17,"tag":103,"props":3744,"children":3745},{"style":219},[3746],{"type":33,"value":3747},"  ctx",{"type":17,"tag":103,"props":3749,"children":3750},{"style":110},[3751],{"type":33,"value":124},{"type":17,"tag":103,"props":3753,"children":3754},{"style":133},[3755],{"type":33,"value":3756}," {}\n",{"type":17,"tag":103,"props":3758,"children":3759},{"class":105,"line":444},[3760,3765,3769,3773],{"type":17,"tag":103,"props":3761,"children":3762},{"style":110},[3763],{"type":33,"value":3764},"  constructor",{"type":17,"tag":103,"props":3766,"children":3767},{"style":133},[3768],{"type":33,"value":136},{"type":17,"tag":103,"props":3770,"children":3771},{"style":219},[3772],{"type":33,"value":222},{"type":17,"tag":103,"props":3774,"children":3775},{"style":133},[3776],{"type":33,"value":276},{"type":17,"tag":103,"props":3778,"children":3779},{"class":105,"line":465},[3780,3785,3790,3794],{"type":17,"tag":103,"props":3781,"children":3782},{"style":116},[3783],{"type":33,"value":3784},"    this",{"type":17,"tag":103,"props":3786,"children":3787},{"style":133},[3788],{"type":33,"value":3789},".ctx ",{"type":17,"tag":103,"props":3791,"children":3792},{"style":110},[3793],{"type":33,"value":290},{"type":17,"tag":103,"props":3795,"children":3796},{"style":133},[3797],{"type":33,"value":3798}," ctx;\n",{"type":17,"tag":103,"props":3800,"children":3801},{"class":105,"line":477},[3802],{"type":17,"tag":103,"props":3803,"children":3804},{"style":133},[3805],{"type":33,"value":322},{"type":17,"tag":103,"props":3807,"children":3808},{"class":105,"line":485},[3809],{"type":17,"tag":103,"props":3810,"children":3811},{"emptyLinePlaceholder":185},[3812],{"type":33,"value":188},{"type":17,"tag":103,"props":3814,"children":3815},{"class":105,"line":493},[3816,3821,3825,3830,3834,3839,3843,3848],{"type":17,"tag":103,"props":3817,"children":3818},{"style":127},[3819],{"type":33,"value":3820},"  add",{"type":17,"tag":103,"props":3822,"children":3823},{"style":133},[3824],{"type":33,"value":136},{"type":17,"tag":103,"props":3826,"children":3827},{"style":219},[3828],{"type":33,"value":3829},"key",{"type":17,"tag":103,"props":3831,"children":3832},{"style":110},[3833],{"type":33,"value":3594},{"type":17,"tag":103,"props":3835,"children":3836},{"style":116},[3837],{"type":33,"value":3838}," string",{"type":17,"tag":103,"props":3840,"children":3841},{"style":133},[3842],{"type":33,"value":227},{"type":17,"tag":103,"props":3844,"children":3845},{"style":219},[3846],{"type":33,"value":3847},"callback",{"type":17,"tag":103,"props":3849,"children":3850},{"style":133},[3851],{"type":33,"value":276},{"type":17,"tag":103,"props":3853,"children":3854},{"class":105,"line":501},[3855,3859,3863,3868,3873,3878],{"type":17,"tag":103,"props":3856,"children":3857},{"style":110},[3858],{"type":33,"value":927},{"type":17,"tag":103,"props":3860,"children":3861},{"style":133},[3862],{"type":33,"value":216},{"type":17,"tag":103,"props":3864,"children":3865},{"style":116},[3866],{"type":33,"value":3867},"this",{"type":17,"tag":103,"props":3869,"children":3870},{"style":133},[3871],{"type":33,"value":3872},".key2FnMap.",{"type":17,"tag":103,"props":3874,"children":3875},{"style":127},[3876],{"type":33,"value":3877},"has",{"type":17,"tag":103,"props":3879,"children":3880},{"style":133},[3881],{"type":33,"value":3882},"(key)) {\n",{"type":17,"tag":103,"props":3884,"children":3885},{"class":105,"line":1287},[3886,3891,3895,3899,3903,3908,3912,3917],{"type":17,"tag":103,"props":3887,"children":3888},{"style":110},[3889],{"type":33,"value":3890},"      throw",{"type":17,"tag":103,"props":3892,"children":3893},{"style":110},[3894],{"type":33,"value":169},{"type":17,"tag":103,"props":3896,"children":3897},{"style":127},[3898],{"type":33,"value":3293},{"type":17,"tag":103,"props":3900,"children":3901},{"style":133},[3902],{"type":33,"value":136},{"type":17,"tag":103,"props":3904,"children":3905},{"style":139},[3906],{"type":33,"value":3907},"`Chain ${",{"type":17,"tag":103,"props":3909,"children":3910},{"style":133},[3911],{"type":33,"value":3829},{"type":17,"tag":103,"props":3913,"children":3914},{"style":139},[3915],{"type":33,"value":3916},"} already exists`",{"type":17,"tag":103,"props":3918,"children":3919},{"style":133},[3920],{"type":33,"value":147},{"type":17,"tag":103,"props":3922,"children":3923},{"class":105,"line":1320},[3924],{"type":17,"tag":103,"props":3925,"children":3926},{"style":133},[3927],{"type":33,"value":3568},{"type":17,"tag":103,"props":3929,"children":3930},{"class":105,"line":1344},[3931],{"type":17,"tag":103,"props":3932,"children":3933},{"emptyLinePlaceholder":185},[3934],{"type":33,"value":188},{"type":17,"tag":103,"props":3936,"children":3937},{"class":105,"line":1368},[3938,3942,3947,3952],{"type":17,"tag":103,"props":3939,"children":3940},{"style":116},[3941],{"type":33,"value":3784},{"type":17,"tag":103,"props":3943,"children":3944},{"style":133},[3945],{"type":33,"value":3946},".keyOrder.",{"type":17,"tag":103,"props":3948,"children":3949},{"style":127},[3950],{"type":33,"value":3951},"push",{"type":17,"tag":103,"props":3953,"children":3954},{"style":133},[3955],{"type":33,"value":3956},"(key);\n",{"type":17,"tag":103,"props":3958,"children":3959},{"class":105,"line":1384},[3960,3964,3968,3973],{"type":17,"tag":103,"props":3961,"children":3962},{"style":116},[3963],{"type":33,"value":3784},{"type":17,"tag":103,"props":3965,"children":3966},{"style":133},[3967],{"type":33,"value":3872},{"type":17,"tag":103,"props":3969,"children":3970},{"style":127},[3971],{"type":33,"value":3972},"set",{"type":17,"tag":103,"props":3974,"children":3975},{"style":133},[3976],{"type":33,"value":3977},"(key, callback);\n",{"type":17,"tag":103,"props":3979,"children":3980},{"class":105,"line":1408},[3981,3985,3990],{"type":17,"tag":103,"props":3982,"children":3983},{"style":110},[3984],{"type":33,"value":309},{"type":17,"tag":103,"props":3986,"children":3987},{"style":116},[3988],{"type":33,"value":3989}," this",{"type":17,"tag":103,"props":3991,"children":3992},{"style":133},[3993],{"type":33,"value":300},{"type":17,"tag":103,"props":3995,"children":3996},{"class":105,"line":1417},[3997],{"type":17,"tag":103,"props":3998,"children":3999},{"style":133},[4000],{"type":33,"value":322},{"type":17,"tag":103,"props":4002,"children":4003},{"class":105,"line":1425},[4004],{"type":17,"tag":103,"props":4005,"children":4006},{"emptyLinePlaceholder":185},[4007],{"type":33,"value":188},{"type":17,"tag":103,"props":4009,"children":4010},{"class":105,"line":1434},[4011,4016,4021],{"type":17,"tag":103,"props":4012,"children":4013},{"style":110},[4014],{"type":33,"value":4015},"  async",{"type":17,"tag":103,"props":4017,"children":4018},{"style":127},[4019],{"type":33,"value":4020}," run",{"type":17,"tag":103,"props":4022,"children":4023},{"style":133},[4024],{"type":33,"value":4025},"() {\n",{"type":17,"tag":103,"props":4027,"children":4028},{"class":105,"line":1442},[4029,4033,4037,4041,4045,4049],{"type":17,"tag":103,"props":4030,"children":4031},{"style":110},[4032],{"type":33,"value":3161},{"type":17,"tag":103,"props":4034,"children":4035},{"style":133},[4036],{"type":33,"value":3166},{"type":17,"tag":103,"props":4038,"children":4039},{"style":110},[4040],{"type":33,"value":290},{"type":17,"tag":103,"props":4042,"children":4043},{"style":110},[4044],{"type":33,"value":3175},{"type":17,"tag":103,"props":4046,"children":4047},{"style":116},[4048],{"type":33,"value":1457},{"type":17,"tag":103,"props":4050,"children":4051},{"style":133},[4052],{"type":33,"value":300},{"type":17,"tag":103,"props":4054,"children":4055},{"class":105,"line":2089},[4056,4060,4064,4068,4072,4076,4080,4084],{"type":17,"tag":103,"props":4057,"children":4058},{"style":110},[4059],{"type":33,"value":1574},{"type":17,"tag":103,"props":4061,"children":4062},{"style":127},[4063],{"type":33,"value":3192},{"type":17,"tag":103,"props":4065,"children":4066},{"style":110},[4067],{"type":33,"value":124},{"type":17,"tag":103,"props":4069,"children":4070},{"style":133},[4071],{"type":33,"value":216},{"type":17,"tag":103,"props":4073,"children":4074},{"style":219},[4075],{"type":33,"value":3225},{"type":17,"tag":103,"props":4077,"children":4078},{"style":133},[4079],{"type":33,"value":237},{"type":17,"tag":103,"props":4081,"children":4082},{"style":110},[4083],{"type":33,"value":242},{"type":17,"tag":103,"props":4085,"children":4086},{"style":133},[4087],{"type":33,"value":247},{"type":17,"tag":103,"props":4089,"children":4090},{"class":105,"line":2112},[4091,4095,4099,4103],{"type":17,"tag":103,"props":4092,"children":4093},{"style":110},[4094],{"type":33,"value":996},{"type":17,"tag":103,"props":4096,"children":4097},{"style":133},[4098],{"type":33,"value":3249},{"type":17,"tag":103,"props":4100,"children":4101},{"style":110},[4102],{"type":33,"value":3254},{"type":17,"tag":103,"props":4104,"children":4105},{"style":133},[4106],{"type":33,"value":4107}," index) {\n",{"type":17,"tag":103,"props":4109,"children":4110},{"class":105,"line":2120},[4111,4115,4119,4123,4127,4131,4135,4139,4143,4147],{"type":17,"tag":103,"props":4112,"children":4113},{"style":110},[4114],{"type":33,"value":3453},{"type":17,"tag":103,"props":4116,"children":4117},{"style":116},[4118],{"type":33,"value":3269},{"type":17,"tag":103,"props":4120,"children":4121},{"style":133},[4122],{"type":33,"value":3274},{"type":17,"tag":103,"props":4124,"children":4125},{"style":127},[4126],{"type":33,"value":3279},{"type":17,"tag":103,"props":4128,"children":4129},{"style":133},[4130],{"type":33,"value":136},{"type":17,"tag":103,"props":4132,"children":4133},{"style":110},[4134],{"type":33,"value":3288},{"type":17,"tag":103,"props":4136,"children":4137},{"style":127},[4138],{"type":33,"value":3293},{"type":17,"tag":103,"props":4140,"children":4141},{"style":133},[4142],{"type":33,"value":136},{"type":17,"tag":103,"props":4144,"children":4145},{"style":139},[4146],{"type":33,"value":3302},{"type":17,"tag":103,"props":4148,"children":4149},{"style":133},[4150],{"type":33,"value":4151},"));\n",{"type":17,"tag":103,"props":4153,"children":4154},{"class":105,"line":2128},[4155],{"type":17,"tag":103,"props":4156,"children":4157},{"style":133},[4158],{"type":33,"value":1088},{"type":17,"tag":103,"props":4160,"children":4161},{"class":105,"line":2137},[4162],{"type":17,"tag":103,"props":4163,"children":4164},{"emptyLinePlaceholder":185},[4165],{"type":33,"value":188},{"type":17,"tag":103,"props":4167,"children":4168},{"class":105,"line":2179},[4169,4173,4177],{"type":17,"tag":103,"props":4170,"children":4171},{"style":133},[4172],{"type":33,"value":3315},{"type":17,"tag":103,"props":4174,"children":4175},{"style":110},[4176],{"type":33,"value":290},{"type":17,"tag":103,"props":4178,"children":4179},{"style":133},[4180],{"type":33,"value":4181}," i;\n",{"type":17,"tag":103,"props":4183,"children":4184},{"class":105,"line":2221},[4185,4190,4194,4198,4202,4206,4211,4215,4219],{"type":17,"tag":103,"props":4186,"children":4187},{"style":110},[4188],{"type":33,"value":4189},"      const",{"type":17,"tag":103,"props":4191,"children":4192},{"style":116},[4193],{"type":33,"value":3028},{"type":17,"tag":103,"props":4195,"children":4196},{"style":110},[4197],{"type":33,"value":124},{"type":17,"tag":103,"props":4199,"children":4200},{"style":116},[4201],{"type":33,"value":3989},{"type":17,"tag":103,"props":4203,"children":4204},{"style":133},[4205],{"type":33,"value":3872},{"type":17,"tag":103,"props":4207,"children":4208},{"style":127},[4209],{"type":33,"value":4210},"get",{"type":17,"tag":103,"props":4212,"children":4213},{"style":133},[4214],{"type":33,"value":136},{"type":17,"tag":103,"props":4216,"children":4217},{"style":116},[4218],{"type":33,"value":3867},{"type":17,"tag":103,"props":4220,"children":4221},{"style":133},[4222],{"type":33,"value":4223},".keyOrder[i]);\n",{"type":17,"tag":103,"props":4225,"children":4226},{"class":105,"line":2263},[4227,4231,4235,4239],{"type":17,"tag":103,"props":4228,"children":4229},{"style":110},[4230],{"type":33,"value":996},{"type":17,"tag":103,"props":4232,"children":4233},{"style":133},[4234],{"type":33,"value":216},{"type":17,"tag":103,"props":4236,"children":4237},{"style":110},[4238],{"type":33,"value":2965},{"type":17,"tag":103,"props":4240,"children":4241},{"style":133},[4242],{"type":33,"value":4243},"fn) {\n",{"type":17,"tag":103,"props":4245,"children":4246},{"class":105,"line":2304},[4247,4251,4255,4259,4263,4267,4272,4276],{"type":17,"tag":103,"props":4248,"children":4249},{"style":110},[4250],{"type":33,"value":3453},{"type":17,"tag":103,"props":4252,"children":4253},{"style":116},[4254],{"type":33,"value":3269},{"type":17,"tag":103,"props":4256,"children":4257},{"style":133},[4258],{"type":33,"value":3274},{"type":17,"tag":103,"props":4260,"children":4261},{"style":127},[4262],{"type":33,"value":3421},{"type":17,"tag":103,"props":4264,"children":4265},{"style":133},[4266],{"type":33,"value":136},{"type":17,"tag":103,"props":4268,"children":4269},{"style":110},[4270],{"type":33,"value":4271},"void",{"type":17,"tag":103,"props":4273,"children":4274},{"style":116},[4275],{"type":33,"value":1011},{"type":17,"tag":103,"props":4277,"children":4278},{"style":133},[4279],{"type":33,"value":147},{"type":17,"tag":103,"props":4281,"children":4283},{"class":105,"line":4282},40,[4284],{"type":17,"tag":103,"props":4285,"children":4286},{"style":133},[4287],{"type":33,"value":1088},{"type":17,"tag":103,"props":4289,"children":4291},{"class":105,"line":4290},41,[4292],{"type":17,"tag":103,"props":4293,"children":4294},{"emptyLinePlaceholder":185},[4295],{"type":33,"value":188},{"type":17,"tag":103,"props":4297,"children":4299},{"class":105,"line":4298},42,[4300,4305,4309,4313,4317,4322,4326,4330,4334,4338,4342,4346],{"type":17,"tag":103,"props":4301,"children":4302},{"style":110},[4303],{"type":33,"value":4304},"      return",{"type":17,"tag":103,"props":4306,"children":4307},{"style":127},[4308],{"type":33,"value":3028},{"type":17,"tag":103,"props":4310,"children":4311},{"style":133},[4312],{"type":33,"value":136},{"type":17,"tag":103,"props":4314,"children":4315},{"style":116},[4316],{"type":33,"value":3867},{"type":17,"tag":103,"props":4318,"children":4319},{"style":133},[4320],{"type":33,"value":4321},".ctx, dispatch.",{"type":17,"tag":103,"props":4323,"children":4324},{"style":127},[4325],{"type":33,"value":3484},{"type":17,"tag":103,"props":4327,"children":4328},{"style":133},[4329],{"type":33,"value":136},{"type":17,"tag":103,"props":4331,"children":4332},{"style":116},[4333],{"type":33,"value":3493},{"type":17,"tag":103,"props":4335,"children":4336},{"style":133},[4337],{"type":33,"value":3498},{"type":17,"tag":103,"props":4339,"children":4340},{"style":110},[4341],{"type":33,"value":3503},{"type":17,"tag":103,"props":4343,"children":4344},{"style":116},[4345],{"type":33,"value":915},{"type":17,"tag":103,"props":4347,"children":4348},{"style":133},[4349],{"type":33,"value":4151},{"type":17,"tag":103,"props":4351,"children":4353},{"class":105,"line":4352},43,[4354],{"type":17,"tag":103,"props":4355,"children":4356},{"style":133},[4357],{"type":33,"value":4358},"    };\n",{"type":17,"tag":103,"props":4360,"children":4362},{"class":105,"line":4361},44,[4363],{"type":17,"tag":103,"props":4364,"children":4365},{"emptyLinePlaceholder":185},[4366],{"type":33,"value":188},{"type":17,"tag":103,"props":4368,"children":4370},{"class":105,"line":4369},45,[4371,4375,4379,4383,4387],{"type":17,"tag":103,"props":4372,"children":4373},{"style":110},[4374],{"type":33,"value":309},{"type":17,"tag":103,"props":4376,"children":4377},{"style":127},[4378],{"type":33,"value":3192},{"type":17,"tag":103,"props":4380,"children":4381},{"style":133},[4382],{"type":33,"value":136},{"type":17,"tag":103,"props":4384,"children":4385},{"style":116},[4386],{"type":33,"value":2334},{"type":17,"tag":103,"props":4388,"children":4389},{"style":133},[4390],{"type":33,"value":147},{"type":17,"tag":103,"props":4392,"children":4394},{"class":105,"line":4393},46,[4395],{"type":17,"tag":103,"props":4396,"children":4397},{"style":133},[4398],{"type":33,"value":322},{"type":17,"tag":103,"props":4400,"children":4402},{"class":105,"line":4401},47,[4403],{"type":17,"tag":103,"props":4404,"children":4405},{"style":133},[4406],{"type":33,"value":1431},{"type":17,"tag":18,"props":4408,"children":4409},{},[4410,4412,4417,4419,4424],{"type":33,"value":4411},"以上就是我参考",{"type":17,"tag":65,"props":4413,"children":4415},{"className":4414},[],[4416],{"type":33,"value":70},{"type":33,"value":4418},"实现的责任链工具函数：",{"type":17,"tag":65,"props":4420,"children":4422},{"className":4421},[],[4423],{"type":33,"value":2866},{"type":33,"value":46},{"type":17,"tag":18,"props":4426,"children":4427},{},[4428,4430,4435],{"type":33,"value":4429},"有些人会说，",{"type":17,"tag":65,"props":4431,"children":4433},{"className":4432},[],[4434],{"type":33,"value":70},{"type":33,"value":4436},"的中间件是异步函数的，你这个行不行？",{"type":17,"tag":18,"props":4438,"children":4439},{},[4440],{"type":33,"value":4441},"当然可以，接下来看个异步的例子：",{"type":17,"tag":93,"props":4443,"children":4445},{"className":95,"code":4444,"language":97,"meta":7,"style":7},"const resChain = new ResChain();\n\nresChain.add('async1', async (_, next) => {\n  console.log('async1');\n  await next();\n});\n\n\nresChain.add('async2', async (_, next) => {\n  console.log('async2')\n  // 这里可以执行一些异步处理函数\n  await new Promise((resolve, reject) => {\n    setTimeOut(() => {\n      resolve();\n    }, 1000)\n  });\n\n  await next();\n});\n\n\nresChain.add('key3', async (_, next) => {\n  console.log('key3');\n  await next();\n});\n\n\n// 执行责任链\nawait resChain.run();\n\nconsole.log('finished');\n\n// 先输出 async1 async2 然后停顿了1秒钟之后，才输出async3 finished\n",[4446],{"type":17,"tag":65,"props":4447,"children":4448},{"__ignoreMap":7},[4449,4476,4483,4540,4564,4581,4588,4595,4602,4658,4681,4689,4733,4754,4766,4783,4791,4798,4813,4820,4827,4834,4890,4913,4928,4935,4942,4949,4957,4978,4985,5010,5017],{"type":17,"tag":103,"props":4450,"children":4451},{"class":105,"line":106},[4452,4456,4460,4464,4468,4472],{"type":17,"tag":103,"props":4453,"children":4454},{"style":110},[4455],{"type":33,"value":113},{"type":17,"tag":103,"props":4457,"children":4458},{"style":116},[4459],{"type":33,"value":1579},{"type":17,"tag":103,"props":4461,"children":4462},{"style":110},[4463],{"type":33,"value":124},{"type":17,"tag":103,"props":4465,"children":4466},{"style":110},[4467],{"type":33,"value":169},{"type":17,"tag":103,"props":4469,"children":4470},{"style":127},[4471],{"type":33,"value":1592},{"type":17,"tag":103,"props":4473,"children":4474},{"style":133},[4475],{"type":33,"value":178},{"type":17,"tag":103,"props":4477,"children":4478},{"class":105,"line":150},[4479],{"type":17,"tag":103,"props":4480,"children":4481},{"emptyLinePlaceholder":185},[4482],{"type":33,"value":188},{"type":17,"tag":103,"props":4484,"children":4485},{"class":105,"line":181},[4486,4491,4495,4499,4504,4508,4512,4516,4520,4524,4528,4532,4536],{"type":17,"tag":103,"props":4487,"children":4488},{"style":133},[4489],{"type":33,"value":4490},"resChain.",{"type":17,"tag":103,"props":4492,"children":4493},{"style":127},[4494],{"type":33,"value":1618},{"type":17,"tag":103,"props":4496,"children":4497},{"style":133},[4498],{"type":33,"value":136},{"type":17,"tag":103,"props":4500,"children":4501},{"style":139},[4502],{"type":33,"value":4503},"'async1'",{"type":17,"tag":103,"props":4505,"children":4506},{"style":133},[4507],{"type":33,"value":227},{"type":17,"tag":103,"props":4509,"children":4510},{"style":110},[4511],{"type":33,"value":211},{"type":17,"tag":103,"props":4513,"children":4514},{"style":133},[4515],{"type":33,"value":216},{"type":17,"tag":103,"props":4517,"children":4518},{"style":219},[4519],{"type":33,"value":1637},{"type":17,"tag":103,"props":4521,"children":4522},{"style":133},[4523],{"type":33,"value":227},{"type":17,"tag":103,"props":4525,"children":4526},{"style":219},[4527],{"type":33,"value":232},{"type":17,"tag":103,"props":4529,"children":4530},{"style":133},[4531],{"type":33,"value":237},{"type":17,"tag":103,"props":4533,"children":4534},{"style":110},[4535],{"type":33,"value":242},{"type":17,"tag":103,"props":4537,"children":4538},{"style":133},[4539],{"type":33,"value":247},{"type":17,"tag":103,"props":4541,"children":4542},{"class":105,"line":191},[4543,4548,4552,4556,4560],{"type":17,"tag":103,"props":4544,"children":4545},{"style":133},[4546],{"type":33,"value":4547},"  console.",{"type":17,"tag":103,"props":4549,"children":4550},{"style":127},[4551],{"type":33,"value":958},{"type":17,"tag":103,"props":4553,"children":4554},{"style":133},[4555],{"type":33,"value":136},{"type":17,"tag":103,"props":4557,"children":4558},{"style":139},[4559],{"type":33,"value":4503},{"type":17,"tag":103,"props":4561,"children":4562},{"style":133},[4563],{"type":33,"value":147},{"type":17,"tag":103,"props":4565,"children":4566},{"class":105,"line":250},[4567,4572,4577],{"type":17,"tag":103,"props":4568,"children":4569},{"style":110},[4570],{"type":33,"value":4571},"  await",{"type":17,"tag":103,"props":4573,"children":4574},{"style":127},[4575],{"type":33,"value":4576}," next",{"type":17,"tag":103,"props":4578,"children":4579},{"style":133},[4580],{"type":33,"value":178},{"type":17,"tag":103,"props":4582,"children":4583},{"class":105,"line":279},[4584],{"type":17,"tag":103,"props":4585,"children":4586},{"style":133},[4587],{"type":33,"value":360},{"type":17,"tag":103,"props":4589,"children":4590},{"class":105,"line":303},[4591],{"type":17,"tag":103,"props":4592,"children":4593},{"emptyLinePlaceholder":185},[4594],{"type":33,"value":188},{"type":17,"tag":103,"props":4596,"children":4597},{"class":105,"line":316},[4598],{"type":17,"tag":103,"props":4599,"children":4600},{"emptyLinePlaceholder":185},[4601],{"type":33,"value":188},{"type":17,"tag":103,"props":4603,"children":4604},{"class":105,"line":325},[4605,4609,4613,4617,4622,4626,4630,4634,4638,4642,4646,4650,4654],{"type":17,"tag":103,"props":4606,"children":4607},{"style":133},[4608],{"type":33,"value":4490},{"type":17,"tag":103,"props":4610,"children":4611},{"style":127},[4612],{"type":33,"value":1618},{"type":17,"tag":103,"props":4614,"children":4615},{"style":133},[4616],{"type":33,"value":136},{"type":17,"tag":103,"props":4618,"children":4619},{"style":139},[4620],{"type":33,"value":4621},"'async2'",{"type":17,"tag":103,"props":4623,"children":4624},{"style":133},[4625],{"type":33,"value":227},{"type":17,"tag":103,"props":4627,"children":4628},{"style":110},[4629],{"type":33,"value":211},{"type":17,"tag":103,"props":4631,"children":4632},{"style":133},[4633],{"type":33,"value":216},{"type":17,"tag":103,"props":4635,"children":4636},{"style":219},[4637],{"type":33,"value":1637},{"type":17,"tag":103,"props":4639,"children":4640},{"style":133},[4641],{"type":33,"value":227},{"type":17,"tag":103,"props":4643,"children":4644},{"style":219},[4645],{"type":33,"value":232},{"type":17,"tag":103,"props":4647,"children":4648},{"style":133},[4649],{"type":33,"value":237},{"type":17,"tag":103,"props":4651,"children":4652},{"style":110},[4653],{"type":33,"value":242},{"type":17,"tag":103,"props":4655,"children":4656},{"style":133},[4657],{"type":33,"value":247},{"type":17,"tag":103,"props":4659,"children":4660},{"class":105,"line":334},[4661,4665,4669,4673,4677],{"type":17,"tag":103,"props":4662,"children":4663},{"style":133},[4664],{"type":33,"value":4547},{"type":17,"tag":103,"props":4666,"children":4667},{"style":127},[4668],{"type":33,"value":958},{"type":17,"tag":103,"props":4670,"children":4671},{"style":133},[4672],{"type":33,"value":136},{"type":17,"tag":103,"props":4674,"children":4675},{"style":139},[4676],{"type":33,"value":4621},{"type":17,"tag":103,"props":4678,"children":4679},{"style":133},[4680],{"type":33,"value":972},{"type":17,"tag":103,"props":4682,"children":4683},{"class":105,"line":354},[4684],{"type":17,"tag":103,"props":4685,"children":4686},{"style":348},[4687],{"type":33,"value":4688},"  // 这里可以执行一些异步处理函数\n",{"type":17,"tag":103,"props":4690,"children":4691},{"class":105,"line":363},[4692,4696,4700,4704,4709,4713,4717,4721,4725,4729],{"type":17,"tag":103,"props":4693,"children":4694},{"style":110},[4695],{"type":33,"value":4571},{"type":17,"tag":103,"props":4697,"children":4698},{"style":110},[4699],{"type":33,"value":169},{"type":17,"tag":103,"props":4701,"children":4702},{"style":116},[4703],{"type":33,"value":3269},{"type":17,"tag":103,"props":4705,"children":4706},{"style":133},[4707],{"type":33,"value":4708},"((",{"type":17,"tag":103,"props":4710,"children":4711},{"style":219},[4712],{"type":33,"value":3421},{"type":17,"tag":103,"props":4714,"children":4715},{"style":133},[4716],{"type":33,"value":227},{"type":17,"tag":103,"props":4718,"children":4719},{"style":219},[4720],{"type":33,"value":3279},{"type":17,"tag":103,"props":4722,"children":4723},{"style":133},[4724],{"type":33,"value":237},{"type":17,"tag":103,"props":4726,"children":4727},{"style":110},[4728],{"type":33,"value":242},{"type":17,"tag":103,"props":4730,"children":4731},{"style":133},[4732],{"type":33,"value":247},{"type":17,"tag":103,"props":4734,"children":4735},{"class":105,"line":371},[4736,4741,4746,4750],{"type":17,"tag":103,"props":4737,"children":4738},{"style":127},[4739],{"type":33,"value":4740},"    setTimeOut",{"type":17,"tag":103,"props":4742,"children":4743},{"style":133},[4744],{"type":33,"value":4745},"(() ",{"type":17,"tag":103,"props":4747,"children":4748},{"style":110},[4749],{"type":33,"value":242},{"type":17,"tag":103,"props":4751,"children":4752},{"style":133},[4753],{"type":33,"value":247},{"type":17,"tag":103,"props":4755,"children":4756},{"class":105,"line":419},[4757,4762],{"type":17,"tag":103,"props":4758,"children":4759},{"style":127},[4760],{"type":33,"value":4761},"      resolve",{"type":17,"tag":103,"props":4763,"children":4764},{"style":133},[4765],{"type":33,"value":178},{"type":17,"tag":103,"props":4767,"children":4768},{"class":105,"line":444},[4769,4774,4779],{"type":17,"tag":103,"props":4770,"children":4771},{"style":133},[4772],{"type":33,"value":4773},"    }, ",{"type":17,"tag":103,"props":4775,"children":4776},{"style":116},[4777],{"type":33,"value":4778},"1000",{"type":17,"tag":103,"props":4780,"children":4781},{"style":133},[4782],{"type":33,"value":972},{"type":17,"tag":103,"props":4784,"children":4785},{"class":105,"line":465},[4786],{"type":17,"tag":103,"props":4787,"children":4788},{"style":133},[4789],{"type":33,"value":4790},"  });\n",{"type":17,"tag":103,"props":4792,"children":4793},{"class":105,"line":477},[4794],{"type":17,"tag":103,"props":4795,"children":4796},{"emptyLinePlaceholder":185},[4797],{"type":33,"value":188},{"type":17,"tag":103,"props":4799,"children":4800},{"class":105,"line":485},[4801,4805,4809],{"type":17,"tag":103,"props":4802,"children":4803},{"style":110},[4804],{"type":33,"value":4571},{"type":17,"tag":103,"props":4806,"children":4807},{"style":127},[4808],{"type":33,"value":4576},{"type":17,"tag":103,"props":4810,"children":4811},{"style":133},[4812],{"type":33,"value":178},{"type":17,"tag":103,"props":4814,"children":4815},{"class":105,"line":493},[4816],{"type":17,"tag":103,"props":4817,"children":4818},{"style":133},[4819],{"type":33,"value":360},{"type":17,"tag":103,"props":4821,"children":4822},{"class":105,"line":501},[4823],{"type":17,"tag":103,"props":4824,"children":4825},{"emptyLinePlaceholder":185},[4826],{"type":33,"value":188},{"type":17,"tag":103,"props":4828,"children":4829},{"class":105,"line":1287},[4830],{"type":17,"tag":103,"props":4831,"children":4832},{"emptyLinePlaceholder":185},[4833],{"type":33,"value":188},{"type":17,"tag":103,"props":4835,"children":4836},{"class":105,"line":1320},[4837,4841,4845,4849,4854,4858,4862,4866,4870,4874,4878,4882,4886],{"type":17,"tag":103,"props":4838,"children":4839},{"style":133},[4840],{"type":33,"value":4490},{"type":17,"tag":103,"props":4842,"children":4843},{"style":127},[4844],{"type":33,"value":1618},{"type":17,"tag":103,"props":4846,"children":4847},{"style":133},[4848],{"type":33,"value":136},{"type":17,"tag":103,"props":4850,"children":4851},{"style":139},[4852],{"type":33,"value":4853},"'key3'",{"type":17,"tag":103,"props":4855,"children":4856},{"style":133},[4857],{"type":33,"value":227},{"type":17,"tag":103,"props":4859,"children":4860},{"style":110},[4861],{"type":33,"value":211},{"type":17,"tag":103,"props":4863,"children":4864},{"style":133},[4865],{"type":33,"value":216},{"type":17,"tag":103,"props":4867,"children":4868},{"style":219},[4869],{"type":33,"value":1637},{"type":17,"tag":103,"props":4871,"children":4872},{"style":133},[4873],{"type":33,"value":227},{"type":17,"tag":103,"props":4875,"children":4876},{"style":219},[4877],{"type":33,"value":232},{"type":17,"tag":103,"props":4879,"children":4880},{"style":133},[4881],{"type":33,"value":237},{"type":17,"tag":103,"props":4883,"children":4884},{"style":110},[4885],{"type":33,"value":242},{"type":17,"tag":103,"props":4887,"children":4888},{"style":133},[4889],{"type":33,"value":247},{"type":17,"tag":103,"props":4891,"children":4892},{"class":105,"line":1344},[4893,4897,4901,4905,4909],{"type":17,"tag":103,"props":4894,"children":4895},{"style":133},[4896],{"type":33,"value":4547},{"type":17,"tag":103,"props":4898,"children":4899},{"style":127},[4900],{"type":33,"value":958},{"type":17,"tag":103,"props":4902,"children":4903},{"style":133},[4904],{"type":33,"value":136},{"type":17,"tag":103,"props":4906,"children":4907},{"style":139},[4908],{"type":33,"value":4853},{"type":17,"tag":103,"props":4910,"children":4911},{"style":133},[4912],{"type":33,"value":147},{"type":17,"tag":103,"props":4914,"children":4915},{"class":105,"line":1368},[4916,4920,4924],{"type":17,"tag":103,"props":4917,"children":4918},{"style":110},[4919],{"type":33,"value":4571},{"type":17,"tag":103,"props":4921,"children":4922},{"style":127},[4923],{"type":33,"value":4576},{"type":17,"tag":103,"props":4925,"children":4926},{"style":133},[4927],{"type":33,"value":178},{"type":17,"tag":103,"props":4929,"children":4930},{"class":105,"line":1384},[4931],{"type":17,"tag":103,"props":4932,"children":4933},{"style":133},[4934],{"type":33,"value":360},{"type":17,"tag":103,"props":4936,"children":4937},{"class":105,"line":1408},[4938],{"type":17,"tag":103,"props":4939,"children":4940},{"emptyLinePlaceholder":185},[4941],{"type":33,"value":188},{"type":17,"tag":103,"props":4943,"children":4944},{"class":105,"line":1417},[4945],{"type":17,"tag":103,"props":4946,"children":4947},{"emptyLinePlaceholder":185},[4948],{"type":33,"value":188},{"type":17,"tag":103,"props":4950,"children":4951},{"class":105,"line":1425},[4952],{"type":17,"tag":103,"props":4953,"children":4954},{"style":348},[4955],{"type":33,"value":4956},"// 执行责任链\n",{"type":17,"tag":103,"props":4958,"children":4959},{"class":105,"line":1434},[4960,4965,4970,4974],{"type":17,"tag":103,"props":4961,"children":4962},{"style":110},[4963],{"type":33,"value":4964},"await",{"type":17,"tag":103,"props":4966,"children":4967},{"style":133},[4968],{"type":33,"value":4969}," resChain.",{"type":17,"tag":103,"props":4971,"children":4972},{"style":127},[4973],{"type":33,"value":2099},{"type":17,"tag":103,"props":4975,"children":4976},{"style":133},[4977],{"type":33,"value":178},{"type":17,"tag":103,"props":4979,"children":4980},{"class":105,"line":1442},[4981],{"type":17,"tag":103,"props":4982,"children":4983},{"emptyLinePlaceholder":185},[4984],{"type":33,"value":188},{"type":17,"tag":103,"props":4986,"children":4987},{"class":105,"line":2089},[4988,4993,4997,5001,5006],{"type":17,"tag":103,"props":4989,"children":4990},{"style":133},[4991],{"type":33,"value":4992},"console.",{"type":17,"tag":103,"props":4994,"children":4995},{"style":127},[4996],{"type":33,"value":958},{"type":17,"tag":103,"props":4998,"children":4999},{"style":133},[5000],{"type":33,"value":136},{"type":17,"tag":103,"props":5002,"children":5003},{"style":139},[5004],{"type":33,"value":5005},"'finished'",{"type":17,"tag":103,"props":5007,"children":5008},{"style":133},[5009],{"type":33,"value":147},{"type":17,"tag":103,"props":5011,"children":5012},{"class":105,"line":2112},[5013],{"type":17,"tag":103,"props":5014,"children":5015},{"emptyLinePlaceholder":185},[5016],{"type":33,"value":188},{"type":17,"tag":103,"props":5018,"children":5019},{"class":105,"line":2120},[5020],{"type":17,"tag":103,"props":5021,"children":5022},{"style":348},[5023],{"type":33,"value":5024},"// 先输出 async1 async2 然后停顿了1秒钟之后，才输出async3 finished\n",{"type":17,"tag":5026,"props":5027,"children":5028},"blockquote",{},[5029],{"type":17,"tag":18,"props":5030,"children":5031},{},[5032],{"type":33,"value":5033},"🚧 需要注意：如果是异步模式，则链上的每个回调函数必须要 await next()，因为next函数代表下一个环的异步函数。",{"type":17,"tag":18,"props":5035,"children":5036},{},[5037,5039,5044],{"type":33,"value":5038},"有人可能还注意到了，",{"type":17,"tag":65,"props":5040,"children":5042},{"className":5041},[],[5043],{"type":33,"value":2866},{"type":33,"value":5045},"实例化的时候可以传入对象，比如下面的代码：",{"type":17,"tag":93,"props":5047,"children":5049},{"className":95,"code":5048,"language":97,"meta":7,"style":7},"const resChain = new ResChain({ interrupt: false });\n",[5050],{"type":17,"tag":65,"props":5051,"children":5052},{"__ignoreMap":7},[5053],{"type":17,"tag":103,"props":5054,"children":5055},{"class":105,"line":106},[5056,5060,5064,5068,5072,5076,5081,5085],{"type":17,"tag":103,"props":5057,"children":5058},{"style":110},[5059],{"type":33,"value":113},{"type":17,"tag":103,"props":5061,"children":5062},{"style":116},[5063],{"type":33,"value":1579},{"type":17,"tag":103,"props":5065,"children":5066},{"style":110},[5067],{"type":33,"value":124},{"type":17,"tag":103,"props":5069,"children":5070},{"style":110},[5071],{"type":33,"value":169},{"type":17,"tag":103,"props":5073,"children":5074},{"style":127},[5075],{"type":33,"value":1592},{"type":17,"tag":103,"props":5077,"children":5078},{"style":133},[5079],{"type":33,"value":5080},"({ interrupt: ",{"type":17,"tag":103,"props":5082,"children":5083},{"style":116},[5084],{"type":33,"value":2201},{"type":17,"tag":103,"props":5086,"children":5087},{"style":133},[5088],{"type":33,"value":5089}," });\n",{"type":17,"tag":18,"props":5091,"children":5092},{},[5093],{"type":33,"value":5094},"传入对象具体有什么用法呢？可以用来获取一些在链中处理好的数据，来实现发送者和处理者的解耦。可能比较抽象，我们来举个例子。",{"type":17,"tag":18,"props":5096,"children":5097},{},[5098],{"type":33,"value":5099},"比如需要进行数据校验的场景，如果不通过，则中断提交：",{"type":17,"tag":93,"props":5101,"children":5103},{"className":95,"code":5102,"language":97,"meta":7,"style":7},"const ctx = {\n  // 表单项\n  model: {\n    name: '',\n    phone: '',\n  },\n  // 错误提示\n  error: '',\n  // 是否中断\n  interrupt: false,\n}\nconst resChain = new ResChain(ctx);\n\nresChain.add('校验name', (ctx, next) => {\n  const { name = '' } = ctx;\n  if (name === '') {\n    ctx.error = '请填写name';\n    ctx.interrupt = true;\n    return;\n  }\n\n  next();\n})\n\nresChain.add('校验phone', (ctx, next) => {\n  const { phone = '' } = ctx;\n  if (phone === '') {\n    ctx.error = '请填写手机号';\n    ctx.interrupt = true;\n    return;\n  }\n\n  next();\n})\n\n// 执行责任链\nresChain.run();\n\n// 如果需要中断，则提示\nif (resChain.ctx.interrupt) {\n  alert(resChain.ctx.error);\n  return;\n}\n",[5104],{"type":17,"tag":65,"props":5105,"children":5106},{"__ignoreMap":7},[5107,5127,5135,5143,5161,5177,5185,5193,5209,5217,5233,5240,5268,5275,5323,5363,5387,5408,5428,5439,5446,5453,5464,5472,5479,5527,5563,5587,5607,5626,5637,5644,5651,5662,5669,5676,5683,5698,5705,5713,5726,5739,5750],{"type":17,"tag":103,"props":5108,"children":5109},{"class":105,"line":106},[5110,5114,5119,5123],{"type":17,"tag":103,"props":5111,"children":5112},{"style":110},[5113],{"type":33,"value":113},{"type":17,"tag":103,"props":5115,"children":5116},{"style":116},[5117],{"type":33,"value":5118}," ctx",{"type":17,"tag":103,"props":5120,"children":5121},{"style":110},[5122],{"type":33,"value":124},{"type":17,"tag":103,"props":5124,"children":5125},{"style":133},[5126],{"type":33,"value":247},{"type":17,"tag":103,"props":5128,"children":5129},{"class":105,"line":150},[5130],{"type":17,"tag":103,"props":5131,"children":5132},{"style":348},[5133],{"type":33,"value":5134},"  // 表单项\n",{"type":17,"tag":103,"props":5136,"children":5137},{"class":105,"line":181},[5138],{"type":17,"tag":103,"props":5139,"children":5140},{"style":133},[5141],{"type":33,"value":5142},"  model: {\n",{"type":17,"tag":103,"props":5144,"children":5145},{"class":105,"line":191},[5146,5151,5156],{"type":17,"tag":103,"props":5147,"children":5148},{"style":133},[5149],{"type":33,"value":5150},"    name: ",{"type":17,"tag":103,"props":5152,"children":5153},{"style":139},[5154],{"type":33,"value":5155},"''",{"type":17,"tag":103,"props":5157,"children":5158},{"style":133},[5159],{"type":33,"value":5160},",\n",{"type":17,"tag":103,"props":5162,"children":5163},{"class":105,"line":250},[5164,5169,5173],{"type":17,"tag":103,"props":5165,"children":5166},{"style":133},[5167],{"type":33,"value":5168},"    phone: ",{"type":17,"tag":103,"props":5170,"children":5171},{"style":139},[5172],{"type":33,"value":5155},{"type":17,"tag":103,"props":5174,"children":5175},{"style":133},[5176],{"type":33,"value":5160},{"type":17,"tag":103,"props":5178,"children":5179},{"class":105,"line":279},[5180],{"type":17,"tag":103,"props":5181,"children":5182},{"style":133},[5183],{"type":33,"value":5184},"  },\n",{"type":17,"tag":103,"props":5186,"children":5187},{"class":105,"line":303},[5188],{"type":17,"tag":103,"props":5189,"children":5190},{"style":348},[5191],{"type":33,"value":5192},"  // 错误提示\n",{"type":17,"tag":103,"props":5194,"children":5195},{"class":105,"line":316},[5196,5201,5205],{"type":17,"tag":103,"props":5197,"children":5198},{"style":133},[5199],{"type":33,"value":5200},"  error: ",{"type":17,"tag":103,"props":5202,"children":5203},{"style":139},[5204],{"type":33,"value":5155},{"type":17,"tag":103,"props":5206,"children":5207},{"style":133},[5208],{"type":33,"value":5160},{"type":17,"tag":103,"props":5210,"children":5211},{"class":105,"line":325},[5212],{"type":17,"tag":103,"props":5213,"children":5214},{"style":348},[5215],{"type":33,"value":5216},"  // 是否中断\n",{"type":17,"tag":103,"props":5218,"children":5219},{"class":105,"line":334},[5220,5225,5229],{"type":17,"tag":103,"props":5221,"children":5222},{"style":133},[5223],{"type":33,"value":5224},"  interrupt: ",{"type":17,"tag":103,"props":5226,"children":5227},{"style":116},[5228],{"type":33,"value":2201},{"type":17,"tag":103,"props":5230,"children":5231},{"style":133},[5232],{"type":33,"value":5160},{"type":17,"tag":103,"props":5234,"children":5235},{"class":105,"line":354},[5236],{"type":17,"tag":103,"props":5237,"children":5238},{"style":133},[5239],{"type":33,"value":1431},{"type":17,"tag":103,"props":5241,"children":5242},{"class":105,"line":363},[5243,5247,5251,5255,5259,5263],{"type":17,"tag":103,"props":5244,"children":5245},{"style":110},[5246],{"type":33,"value":113},{"type":17,"tag":103,"props":5248,"children":5249},{"style":116},[5250],{"type":33,"value":1579},{"type":17,"tag":103,"props":5252,"children":5253},{"style":110},[5254],{"type":33,"value":124},{"type":17,"tag":103,"props":5256,"children":5257},{"style":110},[5258],{"type":33,"value":169},{"type":17,"tag":103,"props":5260,"children":5261},{"style":127},[5262],{"type":33,"value":1592},{"type":17,"tag":103,"props":5264,"children":5265},{"style":133},[5266],{"type":33,"value":5267},"(ctx);\n",{"type":17,"tag":103,"props":5269,"children":5270},{"class":105,"line":371},[5271],{"type":17,"tag":103,"props":5272,"children":5273},{"emptyLinePlaceholder":185},[5274],{"type":33,"value":188},{"type":17,"tag":103,"props":5276,"children":5277},{"class":105,"line":419},[5278,5282,5286,5290,5295,5299,5303,5307,5311,5315,5319],{"type":17,"tag":103,"props":5279,"children":5280},{"style":133},[5281],{"type":33,"value":4490},{"type":17,"tag":103,"props":5283,"children":5284},{"style":127},[5285],{"type":33,"value":1618},{"type":17,"tag":103,"props":5287,"children":5288},{"style":133},[5289],{"type":33,"value":136},{"type":17,"tag":103,"props":5291,"children":5292},{"style":139},[5293],{"type":33,"value":5294},"'校验name'",{"type":17,"tag":103,"props":5296,"children":5297},{"style":133},[5298],{"type":33,"value":1632},{"type":17,"tag":103,"props":5300,"children":5301},{"style":219},[5302],{"type":33,"value":222},{"type":17,"tag":103,"props":5304,"children":5305},{"style":133},[5306],{"type":33,"value":227},{"type":17,"tag":103,"props":5308,"children":5309},{"style":219},[5310],{"type":33,"value":232},{"type":17,"tag":103,"props":5312,"children":5313},{"style":133},[5314],{"type":33,"value":237},{"type":17,"tag":103,"props":5316,"children":5317},{"style":110},[5318],{"type":33,"value":242},{"type":17,"tag":103,"props":5320,"children":5321},{"style":133},[5322],{"type":33,"value":247},{"type":17,"tag":103,"props":5324,"children":5325},{"class":105,"line":444},[5326,5331,5336,5341,5345,5350,5355,5359],{"type":17,"tag":103,"props":5327,"children":5328},{"style":110},[5329],{"type":33,"value":5330},"  const",{"type":17,"tag":103,"props":5332,"children":5333},{"style":133},[5334],{"type":33,"value":5335}," { ",{"type":17,"tag":103,"props":5337,"children":5338},{"style":116},[5339],{"type":33,"value":5340},"name",{"type":17,"tag":103,"props":5342,"children":5343},{"style":110},[5344],{"type":33,"value":124},{"type":17,"tag":103,"props":5346,"children":5347},{"style":139},[5348],{"type":33,"value":5349}," ''",{"type":17,"tag":103,"props":5351,"children":5352},{"style":133},[5353],{"type":33,"value":5354}," } ",{"type":17,"tag":103,"props":5356,"children":5357},{"style":110},[5358],{"type":33,"value":290},{"type":17,"tag":103,"props":5360,"children":5361},{"style":133},[5362],{"type":33,"value":3798},{"type":17,"tag":103,"props":5364,"children":5365},{"class":105,"line":465},[5366,5370,5375,5379,5383],{"type":17,"tag":103,"props":5367,"children":5368},{"style":110},[5369],{"type":33,"value":256},{"type":17,"tag":103,"props":5371,"children":5372},{"style":133},[5373],{"type":33,"value":5374}," (name ",{"type":17,"tag":103,"props":5376,"children":5377},{"style":110},[5378],{"type":33,"value":266},{"type":17,"tag":103,"props":5380,"children":5381},{"style":139},[5382],{"type":33,"value":5349},{"type":17,"tag":103,"props":5384,"children":5385},{"style":133},[5386],{"type":33,"value":276},{"type":17,"tag":103,"props":5388,"children":5389},{"class":105,"line":477},[5390,5395,5399,5404],{"type":17,"tag":103,"props":5391,"children":5392},{"style":133},[5393],{"type":33,"value":5394},"    ctx.error ",{"type":17,"tag":103,"props":5396,"children":5397},{"style":110},[5398],{"type":33,"value":290},{"type":17,"tag":103,"props":5400,"children":5401},{"style":139},[5402],{"type":33,"value":5403}," '请填写name'",{"type":17,"tag":103,"props":5405,"children":5406},{"style":133},[5407],{"type":33,"value":300},{"type":17,"tag":103,"props":5409,"children":5410},{"class":105,"line":485},[5411,5416,5420,5424],{"type":17,"tag":103,"props":5412,"children":5413},{"style":133},[5414],{"type":33,"value":5415},"    ctx.interrupt ",{"type":17,"tag":103,"props":5417,"children":5418},{"style":110},[5419],{"type":33,"value":290},{"type":17,"tag":103,"props":5421,"children":5422},{"style":116},[5423],{"type":33,"value":941},{"type":17,"tag":103,"props":5425,"children":5426},{"style":133},[5427],{"type":33,"value":300},{"type":17,"tag":103,"props":5429,"children":5430},{"class":105,"line":493},[5431,5435],{"type":17,"tag":103,"props":5432,"children":5433},{"style":110},[5434],{"type":33,"value":309},{"type":17,"tag":103,"props":5436,"children":5437},{"style":133},[5438],{"type":33,"value":300},{"type":17,"tag":103,"props":5440,"children":5441},{"class":105,"line":501},[5442],{"type":17,"tag":103,"props":5443,"children":5444},{"style":133},[5445],{"type":33,"value":322},{"type":17,"tag":103,"props":5447,"children":5448},{"class":105,"line":1287},[5449],{"type":17,"tag":103,"props":5450,"children":5451},{"emptyLinePlaceholder":185},[5452],{"type":33,"value":188},{"type":17,"tag":103,"props":5454,"children":5455},{"class":105,"line":1320},[5456,5460],{"type":17,"tag":103,"props":5457,"children":5458},{"style":127},[5459],{"type":33,"value":340},{"type":17,"tag":103,"props":5461,"children":5462},{"style":133},[5463],{"type":33,"value":178},{"type":17,"tag":103,"props":5465,"children":5466},{"class":105,"line":1344},[5467],{"type":17,"tag":103,"props":5468,"children":5469},{"style":133},[5470],{"type":33,"value":5471},"})\n",{"type":17,"tag":103,"props":5473,"children":5474},{"class":105,"line":1368},[5475],{"type":17,"tag":103,"props":5476,"children":5477},{"emptyLinePlaceholder":185},[5478],{"type":33,"value":188},{"type":17,"tag":103,"props":5480,"children":5481},{"class":105,"line":1384},[5482,5486,5490,5494,5499,5503,5507,5511,5515,5519,5523],{"type":17,"tag":103,"props":5483,"children":5484},{"style":133},[5485],{"type":33,"value":4490},{"type":17,"tag":103,"props":5487,"children":5488},{"style":127},[5489],{"type":33,"value":1618},{"type":17,"tag":103,"props":5491,"children":5492},{"style":133},[5493],{"type":33,"value":136},{"type":17,"tag":103,"props":5495,"children":5496},{"style":139},[5497],{"type":33,"value":5498},"'校验phone'",{"type":17,"tag":103,"props":5500,"children":5501},{"style":133},[5502],{"type":33,"value":1632},{"type":17,"tag":103,"props":5504,"children":5505},{"style":219},[5506],{"type":33,"value":222},{"type":17,"tag":103,"props":5508,"children":5509},{"style":133},[5510],{"type":33,"value":227},{"type":17,"tag":103,"props":5512,"children":5513},{"style":219},[5514],{"type":33,"value":232},{"type":17,"tag":103,"props":5516,"children":5517},{"style":133},[5518],{"type":33,"value":237},{"type":17,"tag":103,"props":5520,"children":5521},{"style":110},[5522],{"type":33,"value":242},{"type":17,"tag":103,"props":5524,"children":5525},{"style":133},[5526],{"type":33,"value":247},{"type":17,"tag":103,"props":5528,"children":5529},{"class":105,"line":1408},[5530,5534,5538,5543,5547,5551,5555,5559],{"type":17,"tag":103,"props":5531,"children":5532},{"style":110},[5533],{"type":33,"value":5330},{"type":17,"tag":103,"props":5535,"children":5536},{"style":133},[5537],{"type":33,"value":5335},{"type":17,"tag":103,"props":5539,"children":5540},{"style":116},[5541],{"type":33,"value":5542},"phone",{"type":17,"tag":103,"props":5544,"children":5545},{"style":110},[5546],{"type":33,"value":124},{"type":17,"tag":103,"props":5548,"children":5549},{"style":139},[5550],{"type":33,"value":5349},{"type":17,"tag":103,"props":5552,"children":5553},{"style":133},[5554],{"type":33,"value":5354},{"type":17,"tag":103,"props":5556,"children":5557},{"style":110},[5558],{"type":33,"value":290},{"type":17,"tag":103,"props":5560,"children":5561},{"style":133},[5562],{"type":33,"value":3798},{"type":17,"tag":103,"props":5564,"children":5565},{"class":105,"line":1417},[5566,5570,5575,5579,5583],{"type":17,"tag":103,"props":5567,"children":5568},{"style":110},[5569],{"type":33,"value":256},{"type":17,"tag":103,"props":5571,"children":5572},{"style":133},[5573],{"type":33,"value":5574}," (phone ",{"type":17,"tag":103,"props":5576,"children":5577},{"style":110},[5578],{"type":33,"value":266},{"type":17,"tag":103,"props":5580,"children":5581},{"style":139},[5582],{"type":33,"value":5349},{"type":17,"tag":103,"props":5584,"children":5585},{"style":133},[5586],{"type":33,"value":276},{"type":17,"tag":103,"props":5588,"children":5589},{"class":105,"line":1425},[5590,5594,5598,5603],{"type":17,"tag":103,"props":5591,"children":5592},{"style":133},[5593],{"type":33,"value":5394},{"type":17,"tag":103,"props":5595,"children":5596},{"style":110},[5597],{"type":33,"value":290},{"type":17,"tag":103,"props":5599,"children":5600},{"style":139},[5601],{"type":33,"value":5602}," '请填写手机号'",{"type":17,"tag":103,"props":5604,"children":5605},{"style":133},[5606],{"type":33,"value":300},{"type":17,"tag":103,"props":5608,"children":5609},{"class":105,"line":1434},[5610,5614,5618,5622],{"type":17,"tag":103,"props":5611,"children":5612},{"style":133},[5613],{"type":33,"value":5415},{"type":17,"tag":103,"props":5615,"children":5616},{"style":110},[5617],{"type":33,"value":290},{"type":17,"tag":103,"props":5619,"children":5620},{"style":116},[5621],{"type":33,"value":941},{"type":17,"tag":103,"props":5623,"children":5624},{"style":133},[5625],{"type":33,"value":300},{"type":17,"tag":103,"props":5627,"children":5628},{"class":105,"line":1442},[5629,5633],{"type":17,"tag":103,"props":5630,"children":5631},{"style":110},[5632],{"type":33,"value":309},{"type":17,"tag":103,"props":5634,"children":5635},{"style":133},[5636],{"type":33,"value":300},{"type":17,"tag":103,"props":5638,"children":5639},{"class":105,"line":2089},[5640],{"type":17,"tag":103,"props":5641,"children":5642},{"style":133},[5643],{"type":33,"value":322},{"type":17,"tag":103,"props":5645,"children":5646},{"class":105,"line":2112},[5647],{"type":17,"tag":103,"props":5648,"children":5649},{"emptyLinePlaceholder":185},[5650],{"type":33,"value":188},{"type":17,"tag":103,"props":5652,"children":5653},{"class":105,"line":2120},[5654,5658],{"type":17,"tag":103,"props":5655,"children":5656},{"style":127},[5657],{"type":33,"value":340},{"type":17,"tag":103,"props":5659,"children":5660},{"style":133},[5661],{"type":33,"value":178},{"type":17,"tag":103,"props":5663,"children":5664},{"class":105,"line":2128},[5665],{"type":17,"tag":103,"props":5666,"children":5667},{"style":133},[5668],{"type":33,"value":5471},{"type":17,"tag":103,"props":5670,"children":5671},{"class":105,"line":2137},[5672],{"type":17,"tag":103,"props":5673,"children":5674},{"emptyLinePlaceholder":185},[5675],{"type":33,"value":188},{"type":17,"tag":103,"props":5677,"children":5678},{"class":105,"line":2179},[5679],{"type":17,"tag":103,"props":5680,"children":5681},{"style":348},[5682],{"type":33,"value":4956},{"type":17,"tag":103,"props":5684,"children":5685},{"class":105,"line":2221},[5686,5690,5694],{"type":17,"tag":103,"props":5687,"children":5688},{"style":133},[5689],{"type":33,"value":4490},{"type":17,"tag":103,"props":5691,"children":5692},{"style":127},[5693],{"type":33,"value":2099},{"type":17,"tag":103,"props":5695,"children":5696},{"style":133},[5697],{"type":33,"value":178},{"type":17,"tag":103,"props":5699,"children":5700},{"class":105,"line":2263},[5701],{"type":17,"tag":103,"props":5702,"children":5703},{"emptyLinePlaceholder":185},[5704],{"type":33,"value":188},{"type":17,"tag":103,"props":5706,"children":5707},{"class":105,"line":2304},[5708],{"type":17,"tag":103,"props":5709,"children":5710},{"style":348},[5711],{"type":33,"value":5712},"// 如果需要中断，则提示\n",{"type":17,"tag":103,"props":5714,"children":5715},{"class":105,"line":4282},[5716,5721],{"type":17,"tag":103,"props":5717,"children":5718},{"style":110},[5719],{"type":33,"value":5720},"if",{"type":17,"tag":103,"props":5722,"children":5723},{"style":133},[5724],{"type":33,"value":5725}," (resChain.ctx.interrupt) {\n",{"type":17,"tag":103,"props":5727,"children":5728},{"class":105,"line":4290},[5729,5734],{"type":17,"tag":103,"props":5730,"children":5731},{"style":127},[5732],{"type":33,"value":5733},"  alert",{"type":17,"tag":103,"props":5735,"children":5736},{"style":133},[5737],{"type":33,"value":5738},"(resChain.ctx.error);\n",{"type":17,"tag":103,"props":5740,"children":5741},{"class":105,"line":4298},[5742,5746],{"type":17,"tag":103,"props":5743,"children":5744},{"style":110},[5745],{"type":33,"value":3120},{"type":17,"tag":103,"props":5747,"children":5748},{"style":133},[5749],{"type":33,"value":300},{"type":17,"tag":103,"props":5751,"children":5752},{"class":105,"line":4352},[5753],{"type":17,"tag":103,"props":5754,"children":5755},{"style":133},[5756],{"type":33,"value":1431},{"type":17,"tag":18,"props":5758,"children":5759},{},[5760],{"type":33,"value":5761},"如果是使用if来实现：",{"type":17,"tag":93,"props":5763,"children":5765},{"className":95,"code":5764,"language":97,"meta":7,"style":7},"const ctx = {\n  // 表单项\n  model: {\n    name: '',\n    phone: '',\n  },\n  // 错误提示\n  error: '',\n  // 是否中断\n  interrupt: false,\n}\n\nif(ctx.model.name === '') {\n  ctx.error = '请填写用户名';\n  ctx.interrupt = true;\n}\n\nif (!ctx.interrupt && ctx.model.phone === '') {\n  ctx.error = '请填写手机号';\n  ctx.interrupt = true;\n}\n\n// 如果需要中断，则提示\nif (resChain.ctx.interrupt) {\n  alert(resChain.ctx.error);\n  return;\n}\n",[5766],{"type":17,"tag":65,"props":5767,"children":5768},{"__ignoreMap":7},[5769,5788,5795,5802,5817,5832,5839,5846,5861,5868,5883,5890,5897,5921,5942,5962,5969,5976,6018,6037,6056,6063,6070,6077,6088,6099,6110],{"type":17,"tag":103,"props":5770,"children":5771},{"class":105,"line":106},[5772,5776,5780,5784],{"type":17,"tag":103,"props":5773,"children":5774},{"style":110},[5775],{"type":33,"value":113},{"type":17,"tag":103,"props":5777,"children":5778},{"style":116},[5779],{"type":33,"value":5118},{"type":17,"tag":103,"props":5781,"children":5782},{"style":110},[5783],{"type":33,"value":124},{"type":17,"tag":103,"props":5785,"children":5786},{"style":133},[5787],{"type":33,"value":247},{"type":17,"tag":103,"props":5789,"children":5790},{"class":105,"line":150},[5791],{"type":17,"tag":103,"props":5792,"children":5793},{"style":348},[5794],{"type":33,"value":5134},{"type":17,"tag":103,"props":5796,"children":5797},{"class":105,"line":181},[5798],{"type":17,"tag":103,"props":5799,"children":5800},{"style":133},[5801],{"type":33,"value":5142},{"type":17,"tag":103,"props":5803,"children":5804},{"class":105,"line":191},[5805,5809,5813],{"type":17,"tag":103,"props":5806,"children":5807},{"style":133},[5808],{"type":33,"value":5150},{"type":17,"tag":103,"props":5810,"children":5811},{"style":139},[5812],{"type":33,"value":5155},{"type":17,"tag":103,"props":5814,"children":5815},{"style":133},[5816],{"type":33,"value":5160},{"type":17,"tag":103,"props":5818,"children":5819},{"class":105,"line":250},[5820,5824,5828],{"type":17,"tag":103,"props":5821,"children":5822},{"style":133},[5823],{"type":33,"value":5168},{"type":17,"tag":103,"props":5825,"children":5826},{"style":139},[5827],{"type":33,"value":5155},{"type":17,"tag":103,"props":5829,"children":5830},{"style":133},[5831],{"type":33,"value":5160},{"type":17,"tag":103,"props":5833,"children":5834},{"class":105,"line":279},[5835],{"type":17,"tag":103,"props":5836,"children":5837},{"style":133},[5838],{"type":33,"value":5184},{"type":17,"tag":103,"props":5840,"children":5841},{"class":105,"line":303},[5842],{"type":17,"tag":103,"props":5843,"children":5844},{"style":348},[5845],{"type":33,"value":5192},{"type":17,"tag":103,"props":5847,"children":5848},{"class":105,"line":316},[5849,5853,5857],{"type":17,"tag":103,"props":5850,"children":5851},{"style":133},[5852],{"type":33,"value":5200},{"type":17,"tag":103,"props":5854,"children":5855},{"style":139},[5856],{"type":33,"value":5155},{"type":17,"tag":103,"props":5858,"children":5859},{"style":133},[5860],{"type":33,"value":5160},{"type":17,"tag":103,"props":5862,"children":5863},{"class":105,"line":325},[5864],{"type":17,"tag":103,"props":5865,"children":5866},{"style":348},[5867],{"type":33,"value":5216},{"type":17,"tag":103,"props":5869,"children":5870},{"class":105,"line":334},[5871,5875,5879],{"type":17,"tag":103,"props":5872,"children":5873},{"style":133},[5874],{"type":33,"value":5224},{"type":17,"tag":103,"props":5876,"children":5877},{"style":116},[5878],{"type":33,"value":2201},{"type":17,"tag":103,"props":5880,"children":5881},{"style":133},[5882],{"type":33,"value":5160},{"type":17,"tag":103,"props":5884,"children":5885},{"class":105,"line":354},[5886],{"type":17,"tag":103,"props":5887,"children":5888},{"style":133},[5889],{"type":33,"value":1431},{"type":17,"tag":103,"props":5891,"children":5892},{"class":105,"line":363},[5893],{"type":17,"tag":103,"props":5894,"children":5895},{"emptyLinePlaceholder":185},[5896],{"type":33,"value":188},{"type":17,"tag":103,"props":5898,"children":5899},{"class":105,"line":371},[5900,5904,5909,5913,5917],{"type":17,"tag":103,"props":5901,"children":5902},{"style":110},[5903],{"type":33,"value":5720},{"type":17,"tag":103,"props":5905,"children":5906},{"style":133},[5907],{"type":33,"value":5908},"(ctx.model.name ",{"type":17,"tag":103,"props":5910,"children":5911},{"style":110},[5912],{"type":33,"value":266},{"type":17,"tag":103,"props":5914,"children":5915},{"style":139},[5916],{"type":33,"value":5349},{"type":17,"tag":103,"props":5918,"children":5919},{"style":133},[5920],{"type":33,"value":276},{"type":17,"tag":103,"props":5922,"children":5923},{"class":105,"line":419},[5924,5929,5933,5938],{"type":17,"tag":103,"props":5925,"children":5926},{"style":133},[5927],{"type":33,"value":5928},"  ctx.error ",{"type":17,"tag":103,"props":5930,"children":5931},{"style":110},[5932],{"type":33,"value":290},{"type":17,"tag":103,"props":5934,"children":5935},{"style":139},[5936],{"type":33,"value":5937}," '请填写用户名'",{"type":17,"tag":103,"props":5939,"children":5940},{"style":133},[5941],{"type":33,"value":300},{"type":17,"tag":103,"props":5943,"children":5944},{"class":105,"line":444},[5945,5950,5954,5958],{"type":17,"tag":103,"props":5946,"children":5947},{"style":133},[5948],{"type":33,"value":5949},"  ctx.interrupt ",{"type":17,"tag":103,"props":5951,"children":5952},{"style":110},[5953],{"type":33,"value":290},{"type":17,"tag":103,"props":5955,"children":5956},{"style":116},[5957],{"type":33,"value":941},{"type":17,"tag":103,"props":5959,"children":5960},{"style":133},[5961],{"type":33,"value":300},{"type":17,"tag":103,"props":5963,"children":5964},{"class":105,"line":465},[5965],{"type":17,"tag":103,"props":5966,"children":5967},{"style":133},[5968],{"type":33,"value":1431},{"type":17,"tag":103,"props":5970,"children":5971},{"class":105,"line":477},[5972],{"type":17,"tag":103,"props":5973,"children":5974},{"emptyLinePlaceholder":185},[5975],{"type":33,"value":188},{"type":17,"tag":103,"props":5977,"children":5978},{"class":105,"line":485},[5979,5983,5987,5991,5996,6001,6006,6010,6014],{"type":17,"tag":103,"props":5980,"children":5981},{"style":110},[5982],{"type":33,"value":5720},{"type":17,"tag":103,"props":5984,"children":5985},{"style":133},[5986],{"type":33,"value":216},{"type":17,"tag":103,"props":5988,"children":5989},{"style":110},[5990],{"type":33,"value":2965},{"type":17,"tag":103,"props":5992,"children":5993},{"style":133},[5994],{"type":33,"value":5995},"ctx.interrupt ",{"type":17,"tag":103,"props":5997,"children":5998},{"style":110},[5999],{"type":33,"value":6000},"&&",{"type":17,"tag":103,"props":6002,"children":6003},{"style":133},[6004],{"type":33,"value":6005}," ctx.model.phone ",{"type":17,"tag":103,"props":6007,"children":6008},{"style":110},[6009],{"type":33,"value":266},{"type":17,"tag":103,"props":6011,"children":6012},{"style":139},[6013],{"type":33,"value":5349},{"type":17,"tag":103,"props":6015,"children":6016},{"style":133},[6017],{"type":33,"value":276},{"type":17,"tag":103,"props":6019,"children":6020},{"class":105,"line":493},[6021,6025,6029,6033],{"type":17,"tag":103,"props":6022,"children":6023},{"style":133},[6024],{"type":33,"value":5928},{"type":17,"tag":103,"props":6026,"children":6027},{"style":110},[6028],{"type":33,"value":290},{"type":17,"tag":103,"props":6030,"children":6031},{"style":139},[6032],{"type":33,"value":5602},{"type":17,"tag":103,"props":6034,"children":6035},{"style":133},[6036],{"type":33,"value":300},{"type":17,"tag":103,"props":6038,"children":6039},{"class":105,"line":501},[6040,6044,6048,6052],{"type":17,"tag":103,"props":6041,"children":6042},{"style":133},[6043],{"type":33,"value":5949},{"type":17,"tag":103,"props":6045,"children":6046},{"style":110},[6047],{"type":33,"value":290},{"type":17,"tag":103,"props":6049,"children":6050},{"style":116},[6051],{"type":33,"value":941},{"type":17,"tag":103,"props":6053,"children":6054},{"style":133},[6055],{"type":33,"value":300},{"type":17,"tag":103,"props":6057,"children":6058},{"class":105,"line":1287},[6059],{"type":17,"tag":103,"props":6060,"children":6061},{"style":133},[6062],{"type":33,"value":1431},{"type":17,"tag":103,"props":6064,"children":6065},{"class":105,"line":1320},[6066],{"type":17,"tag":103,"props":6067,"children":6068},{"emptyLinePlaceholder":185},[6069],{"type":33,"value":188},{"type":17,"tag":103,"props":6071,"children":6072},{"class":105,"line":1344},[6073],{"type":17,"tag":103,"props":6074,"children":6075},{"style":348},[6076],{"type":33,"value":5712},{"type":17,"tag":103,"props":6078,"children":6079},{"class":105,"line":1368},[6080,6084],{"type":17,"tag":103,"props":6081,"children":6082},{"style":110},[6083],{"type":33,"value":5720},{"type":17,"tag":103,"props":6085,"children":6086},{"style":133},[6087],{"type":33,"value":5725},{"type":17,"tag":103,"props":6089,"children":6090},{"class":105,"line":1384},[6091,6095],{"type":17,"tag":103,"props":6092,"children":6093},{"style":127},[6094],{"type":33,"value":5733},{"type":17,"tag":103,"props":6096,"children":6097},{"style":133},[6098],{"type":33,"value":5738},{"type":17,"tag":103,"props":6100,"children":6101},{"class":105,"line":1408},[6102,6106],{"type":17,"tag":103,"props":6103,"children":6104},{"style":110},[6105],{"type":33,"value":3120},{"type":17,"tag":103,"props":6107,"children":6108},{"style":133},[6109],{"type":33,"value":300},{"type":17,"tag":103,"props":6111,"children":6112},{"class":105,"line":1417},[6113],{"type":17,"tag":103,"props":6114,"children":6115},{"style":133},[6116],{"type":33,"value":1431},{"type":17,"tag":18,"props":6118,"children":6119},{},[6120,6122,6127,6129,6135,6137,6142],{"type":33,"value":6121},"可以发现，对",{"type":17,"tag":65,"props":6123,"children":6125},{"className":6124},[],[6126],{"type":33,"value":5542},{"type":33,"value":6128},"的判断逻辑，就要先判断",{"type":17,"tag":65,"props":6130,"children":6132},{"className":6131},[],[6133],{"type":33,"value":6134},"interrupt",{"type":33,"value":6136},"是否为",{"type":17,"tag":65,"props":6138,"children":6140},{"className":6139},[],[6141],{"type":33,"value":2201},{"type":33,"value":6143},"才能继续，而且如果下面还有其他的字段校验，那必须都走一遍if。",{"type":17,"tag":18,"props":6145,"children":6146},{},[6147],{"type":33,"value":6148},"这也是责任链的一个优势，可以在某个环节按自己的想法停止，不用继续走后面的节点。",{"type":17,"tag":18,"props":6150,"children":6151},{},[6152,6154,6161],{"type":33,"value":6153},"目前我已经把这个工具上传到npm了，如果想要在自己的项目中使用，直接安装",{"type":17,"tag":2900,"props":6155,"children":6158},{"href":6156,"rel":6157},"https://github.com/johnhom1024/res-chain",[2904],[6159],{"type":33,"value":6160},"res-chain",{"type":33,"value":6162},"：",{"type":17,"tag":93,"props":6164,"children":6168},{"className":6165,"code":6166,"language":6167,"meta":7,"style":7},"language-bash shiki shiki-themes github-dark","npm install res-chain\n\n# 或者\n# yarn add res-chain\n","bash",[6169],{"type":17,"tag":65,"props":6170,"children":6171},{"__ignoreMap":7},[6172,6190,6197,6205],{"type":17,"tag":103,"props":6173,"children":6174},{"class":105,"line":106},[6175,6180,6185],{"type":17,"tag":103,"props":6176,"children":6177},{"style":127},[6178],{"type":33,"value":6179},"npm",{"type":17,"tag":103,"props":6181,"children":6182},{"style":139},[6183],{"type":33,"value":6184}," install",{"type":17,"tag":103,"props":6186,"children":6187},{"style":139},[6188],{"type":33,"value":6189}," res-chain\n",{"type":17,"tag":103,"props":6191,"children":6192},{"class":105,"line":150},[6193],{"type":17,"tag":103,"props":6194,"children":6195},{"emptyLinePlaceholder":185},[6196],{"type":33,"value":188},{"type":17,"tag":103,"props":6198,"children":6199},{"class":105,"line":181},[6200],{"type":17,"tag":103,"props":6201,"children":6202},{"style":348},[6203],{"type":33,"value":6204},"# 或者\n",{"type":17,"tag":103,"props":6206,"children":6207},{"class":105,"line":191},[6208],{"type":17,"tag":103,"props":6209,"children":6210},{"style":348},[6211],{"type":33,"value":6212},"# yarn add res-chain\n",{"type":17,"tag":18,"props":6214,"children":6215},{},[6216],{"type":33,"value":6217},"引入：",{"type":17,"tag":93,"props":6219,"children":6221},{"className":95,"code":6220,"language":97,"meta":7,"style":7},"import { ResChain } from 'res-chain';\n// CommonJS方式的引入也是支持的\n// const { ResChain } = 'res-chain';\n\nconst resChain = new ResChain();\n\nresChain.add('key1', (_, next) => {\n  console.log('key1');\n  next();\n});\n\nresChain.add('key2', (_, next) => {\n  console.log('key2');\n  // 这里没有调用next，则不会执行key3\n});\n\nresChain.add('key3', (_, next) => {\n  console.log('key3');\n  next();\n});\n\n// 执行职责链\nresChain.run(); // => 将会按顺序输出 key1 key2\n",[6222],{"type":17,"tag":65,"props":6223,"children":6224},{"__ignoreMap":7},[6225,6252,6260,6268,6275,6302,6309,6357,6380,6391,6398,6405,6453,6476,6484,6491,6498,6545,6568,6579,6586,6593,6601],{"type":17,"tag":103,"props":6226,"children":6227},{"class":105,"line":106},[6228,6233,6238,6243,6248],{"type":17,"tag":103,"props":6229,"children":6230},{"style":110},[6231],{"type":33,"value":6232},"import",{"type":17,"tag":103,"props":6234,"children":6235},{"style":133},[6236],{"type":33,"value":6237}," { ResChain } ",{"type":17,"tag":103,"props":6239,"children":6240},{"style":110},[6241],{"type":33,"value":6242},"from",{"type":17,"tag":103,"props":6244,"children":6245},{"style":139},[6246],{"type":33,"value":6247}," 'res-chain'",{"type":17,"tag":103,"props":6249,"children":6250},{"style":133},[6251],{"type":33,"value":300},{"type":17,"tag":103,"props":6253,"children":6254},{"class":105,"line":150},[6255],{"type":17,"tag":103,"props":6256,"children":6257},{"style":348},[6258],{"type":33,"value":6259},"// CommonJS方式的引入也是支持的\n",{"type":17,"tag":103,"props":6261,"children":6262},{"class":105,"line":181},[6263],{"type":17,"tag":103,"props":6264,"children":6265},{"style":348},[6266],{"type":33,"value":6267},"// const { ResChain } = 'res-chain';\n",{"type":17,"tag":103,"props":6269,"children":6270},{"class":105,"line":191},[6271],{"type":17,"tag":103,"props":6272,"children":6273},{"emptyLinePlaceholder":185},[6274],{"type":33,"value":188},{"type":17,"tag":103,"props":6276,"children":6277},{"class":105,"line":250},[6278,6282,6286,6290,6294,6298],{"type":17,"tag":103,"props":6279,"children":6280},{"style":110},[6281],{"type":33,"value":113},{"type":17,"tag":103,"props":6283,"children":6284},{"style":116},[6285],{"type":33,"value":1579},{"type":17,"tag":103,"props":6287,"children":6288},{"style":110},[6289],{"type":33,"value":124},{"type":17,"tag":103,"props":6291,"children":6292},{"style":110},[6293],{"type":33,"value":169},{"type":17,"tag":103,"props":6295,"children":6296},{"style":127},[6297],{"type":33,"value":1592},{"type":17,"tag":103,"props":6299,"children":6300},{"style":133},[6301],{"type":33,"value":178},{"type":17,"tag":103,"props":6303,"children":6304},{"class":105,"line":279},[6305],{"type":17,"tag":103,"props":6306,"children":6307},{"emptyLinePlaceholder":185},[6308],{"type":33,"value":188},{"type":17,"tag":103,"props":6310,"children":6311},{"class":105,"line":303},[6312,6316,6320,6324,6329,6333,6337,6341,6345,6349,6353],{"type":17,"tag":103,"props":6313,"children":6314},{"style":133},[6315],{"type":33,"value":4490},{"type":17,"tag":103,"props":6317,"children":6318},{"style":127},[6319],{"type":33,"value":1618},{"type":17,"tag":103,"props":6321,"children":6322},{"style":133},[6323],{"type":33,"value":136},{"type":17,"tag":103,"props":6325,"children":6326},{"style":139},[6327],{"type":33,"value":6328},"'key1'",{"type":17,"tag":103,"props":6330,"children":6331},{"style":133},[6332],{"type":33,"value":1632},{"type":17,"tag":103,"props":6334,"children":6335},{"style":219},[6336],{"type":33,"value":1637},{"type":17,"tag":103,"props":6338,"children":6339},{"style":133},[6340],{"type":33,"value":227},{"type":17,"tag":103,"props":6342,"children":6343},{"style":219},[6344],{"type":33,"value":232},{"type":17,"tag":103,"props":6346,"children":6347},{"style":133},[6348],{"type":33,"value":237},{"type":17,"tag":103,"props":6350,"children":6351},{"style":110},[6352],{"type":33,"value":242},{"type":17,"tag":103,"props":6354,"children":6355},{"style":133},[6356],{"type":33,"value":247},{"type":17,"tag":103,"props":6358,"children":6359},{"class":105,"line":316},[6360,6364,6368,6372,6376],{"type":17,"tag":103,"props":6361,"children":6362},{"style":133},[6363],{"type":33,"value":4547},{"type":17,"tag":103,"props":6365,"children":6366},{"style":127},[6367],{"type":33,"value":958},{"type":17,"tag":103,"props":6369,"children":6370},{"style":133},[6371],{"type":33,"value":136},{"type":17,"tag":103,"props":6373,"children":6374},{"style":139},[6375],{"type":33,"value":6328},{"type":17,"tag":103,"props":6377,"children":6378},{"style":133},[6379],{"type":33,"value":147},{"type":17,"tag":103,"props":6381,"children":6382},{"class":105,"line":325},[6383,6387],{"type":17,"tag":103,"props":6384,"children":6385},{"style":127},[6386],{"type":33,"value":340},{"type":17,"tag":103,"props":6388,"children":6389},{"style":133},[6390],{"type":33,"value":178},{"type":17,"tag":103,"props":6392,"children":6393},{"class":105,"line":334},[6394],{"type":17,"tag":103,"props":6395,"children":6396},{"style":133},[6397],{"type":33,"value":360},{"type":17,"tag":103,"props":6399,"children":6400},{"class":105,"line":354},[6401],{"type":17,"tag":103,"props":6402,"children":6403},{"emptyLinePlaceholder":185},[6404],{"type":33,"value":188},{"type":17,"tag":103,"props":6406,"children":6407},{"class":105,"line":363},[6408,6412,6416,6420,6425,6429,6433,6437,6441,6445,6449],{"type":17,"tag":103,"props":6409,"children":6410},{"style":133},[6411],{"type":33,"value":4490},{"type":17,"tag":103,"props":6413,"children":6414},{"style":127},[6415],{"type":33,"value":1618},{"type":17,"tag":103,"props":6417,"children":6418},{"style":133},[6419],{"type":33,"value":136},{"type":17,"tag":103,"props":6421,"children":6422},{"style":139},[6423],{"type":33,"value":6424},"'key2'",{"type":17,"tag":103,"props":6426,"children":6427},{"style":133},[6428],{"type":33,"value":1632},{"type":17,"tag":103,"props":6430,"children":6431},{"style":219},[6432],{"type":33,"value":1637},{"type":17,"tag":103,"props":6434,"children":6435},{"style":133},[6436],{"type":33,"value":227},{"type":17,"tag":103,"props":6438,"children":6439},{"style":219},[6440],{"type":33,"value":232},{"type":17,"tag":103,"props":6442,"children":6443},{"style":133},[6444],{"type":33,"value":237},{"type":17,"tag":103,"props":6446,"children":6447},{"style":110},[6448],{"type":33,"value":242},{"type":17,"tag":103,"props":6450,"children":6451},{"style":133},[6452],{"type":33,"value":247},{"type":17,"tag":103,"props":6454,"children":6455},{"class":105,"line":371},[6456,6460,6464,6468,6472],{"type":17,"tag":103,"props":6457,"children":6458},{"style":133},[6459],{"type":33,"value":4547},{"type":17,"tag":103,"props":6461,"children":6462},{"style":127},[6463],{"type":33,"value":958},{"type":17,"tag":103,"props":6465,"children":6466},{"style":133},[6467],{"type":33,"value":136},{"type":17,"tag":103,"props":6469,"children":6470},{"style":139},[6471],{"type":33,"value":6424},{"type":17,"tag":103,"props":6473,"children":6474},{"style":133},[6475],{"type":33,"value":147},{"type":17,"tag":103,"props":6477,"children":6478},{"class":105,"line":419},[6479],{"type":17,"tag":103,"props":6480,"children":6481},{"style":348},[6482],{"type":33,"value":6483},"  // 这里没有调用next，则不会执行key3\n",{"type":17,"tag":103,"props":6485,"children":6486},{"class":105,"line":444},[6487],{"type":17,"tag":103,"props":6488,"children":6489},{"style":133},[6490],{"type":33,"value":360},{"type":17,"tag":103,"props":6492,"children":6493},{"class":105,"line":465},[6494],{"type":17,"tag":103,"props":6495,"children":6496},{"emptyLinePlaceholder":185},[6497],{"type":33,"value":188},{"type":17,"tag":103,"props":6499,"children":6500},{"class":105,"line":477},[6501,6505,6509,6513,6517,6521,6525,6529,6533,6537,6541],{"type":17,"tag":103,"props":6502,"children":6503},{"style":133},[6504],{"type":33,"value":4490},{"type":17,"tag":103,"props":6506,"children":6507},{"style":127},[6508],{"type":33,"value":1618},{"type":17,"tag":103,"props":6510,"children":6511},{"style":133},[6512],{"type":33,"value":136},{"type":17,"tag":103,"props":6514,"children":6515},{"style":139},[6516],{"type":33,"value":4853},{"type":17,"tag":103,"props":6518,"children":6519},{"style":133},[6520],{"type":33,"value":1632},{"type":17,"tag":103,"props":6522,"children":6523},{"style":219},[6524],{"type":33,"value":1637},{"type":17,"tag":103,"props":6526,"children":6527},{"style":133},[6528],{"type":33,"value":227},{"type":17,"tag":103,"props":6530,"children":6531},{"style":219},[6532],{"type":33,"value":232},{"type":17,"tag":103,"props":6534,"children":6535},{"style":133},[6536],{"type":33,"value":237},{"type":17,"tag":103,"props":6538,"children":6539},{"style":110},[6540],{"type":33,"value":242},{"type":17,"tag":103,"props":6542,"children":6543},{"style":133},[6544],{"type":33,"value":247},{"type":17,"tag":103,"props":6546,"children":6547},{"class":105,"line":485},[6548,6552,6556,6560,6564],{"type":17,"tag":103,"props":6549,"children":6550},{"style":133},[6551],{"type":33,"value":4547},{"type":17,"tag":103,"props":6553,"children":6554},{"style":127},[6555],{"type":33,"value":958},{"type":17,"tag":103,"props":6557,"children":6558},{"style":133},[6559],{"type":33,"value":136},{"type":17,"tag":103,"props":6561,"children":6562},{"style":139},[6563],{"type":33,"value":4853},{"type":17,"tag":103,"props":6565,"children":6566},{"style":133},[6567],{"type":33,"value":147},{"type":17,"tag":103,"props":6569,"children":6570},{"class":105,"line":493},[6571,6575],{"type":17,"tag":103,"props":6572,"children":6573},{"style":127},[6574],{"type":33,"value":340},{"type":17,"tag":103,"props":6576,"children":6577},{"style":133},[6578],{"type":33,"value":178},{"type":17,"tag":103,"props":6580,"children":6581},{"class":105,"line":501},[6582],{"type":17,"tag":103,"props":6583,"children":6584},{"style":133},[6585],{"type":33,"value":360},{"type":17,"tag":103,"props":6587,"children":6588},{"class":105,"line":1287},[6589],{"type":17,"tag":103,"props":6590,"children":6591},{"emptyLinePlaceholder":185},[6592],{"type":33,"value":188},{"type":17,"tag":103,"props":6594,"children":6595},{"class":105,"line":1320},[6596],{"type":17,"tag":103,"props":6597,"children":6598},{"style":348},[6599],{"type":33,"value":6600},"// 执行职责链\n",{"type":17,"tag":103,"props":6602,"children":6603},{"class":105,"line":1344},[6604,6608,6612,6616],{"type":17,"tag":103,"props":6605,"children":6606},{"style":133},[6607],{"type":33,"value":4490},{"type":17,"tag":103,"props":6609,"children":6610},{"style":127},[6611],{"type":33,"value":2099},{"type":17,"tag":103,"props":6613,"children":6614},{"style":133},[6615],{"type":33,"value":345},{"type":17,"tag":103,"props":6617,"children":6618},{"style":348},[6619],{"type":33,"value":6620},"// => 将会按顺序输出 key1 key2\n",{"type":17,"tag":18,"props":6622,"children":6623},{},[6624],{"type":33,"value":6625},"芜湖起飞。",{"type":17,"tag":18,"props":6627,"children":6628},{},[6629],{"type":33,"value":6630},"有了这个工具函数，我们就可以视场景去优化项目中的一大坨if-else嵌套，或者直接使用它来实现一些业务中比较复杂的逻辑。",{"type":17,"tag":28,"props":6632,"children":6634},{"id":6633},"起源",[6635],{"type":33,"value":6633},{"type":17,"tag":18,"props":6637,"children":6638},{},[6639],{"type":33,"value":6640},"这个工具诞生的过程还挺巧合的，某一天周六我在公司加班赶需求，发现需要在一堆旧逻辑if-else中添加新的逻辑，强迫症的我实在是无法忍受在屎山上继续堆屎。。。",{"type":17,"tag":18,"props":6642,"children":6643},{},[6644,6646,6651,6653,6658,6660,6665],{"type":33,"value":6645},"我陷入沉思，用什么方式去优化呢？看了网上责任链模式的实现，感觉还是不够优雅。无意中翻到了之前用",{"type":17,"tag":65,"props":6647,"children":6649},{"className":6648},[],[6650],{"type":33,"value":70},{"type":33,"value":6652},"写的项目，突然灵光咋现💡，",{"type":17,"tag":65,"props":6654,"children":6656},{"className":6655},[],[6657],{"type":33,"value":70},{"type":33,"value":6659},"的中间件不就是一个很棒的实践。调用",{"type":17,"tag":65,"props":6661,"children":6663},{"className":6662},[],[6664],{"type":33,"value":232},{"type":33,"value":6666},"就能够往下一个节点走，不调用的话就可以终止。",{"type":17,"tag":28,"props":6668,"children":6670},{"id":6669},"总结",[6671],{"type":33,"value":6669},{"type":17,"tag":18,"props":6673,"children":6674},{},[6675],{"type":33,"value":6676},"过去无意学到的某个知识，或者某个概念，在未来也许会发挥作用，你需要做的就是等待。",{"type":17,"tag":18,"props":6678,"children":6679},{},[6680],{"type":33,"value":6681},"如果你也喜欢这个工具，欢迎去github里给个🌟，感谢。",{"type":17,"tag":18,"props":6683,"children":6684},{},[6685],{"type":33,"value":6686},"如果有什么更好的建议，在底下留言，一起探讨。",{"type":17,"tag":28,"props":6688,"children":6690},{"id":6689},"工具链接",[6691],{"type":33,"value":6689},{"type":17,"tag":779,"props":6693,"children":6694},{},[6695],{"type":17,"tag":783,"props":6696,"children":6697},{},[6698],{"type":17,"tag":2900,"props":6699,"children":6701},{"href":6156,"rel":6700},[2904],[6702],{"type":33,"value":6160},{"type":17,"tag":28,"props":6704,"children":6706},{"id":6705},"参考",[6707],{"type":33,"value":6705},{"type":17,"tag":18,"props":6709,"children":6710},{},[6711],{"type":17,"tag":2900,"props":6712,"children":6715},{"href":6713,"rel":6714},"https://juejin.cn/post/6844903855348514829",[2904],[6716],{"type":33,"value":6713},{"type":17,"tag":6718,"props":6719,"children":6720},"style",{},[6721],{"type":33,"value":6722},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":150,"depth":150,"links":6724},[6725,6726,6727,6728,6729,6730,6731],{"id":30,"depth":150,"text":30},{"id":760,"depth":150,"text":760},{"id":2871,"depth":150,"text":2874},{"id":6633,"depth":150,"text":6633},{"id":6669,"depth":150,"text":6669},{"id":6689,"depth":150,"text":6689},{"id":6705,"depth":150,"text":6705},"markdown","content:articles:20240516.md","content","articles/20240516.md","md",1772793492643]