<small id='lXJ5g'></small><noframes id='lXJ5g'>

<tfoot id='lXJ5g'></tfoot>

<i id='lXJ5g'><tr id='lXJ5g'><dt id='lXJ5g'><q id='lXJ5g'><span id='lXJ5g'><b id='lXJ5g'><form id='lXJ5g'><ins id='lXJ5g'></ins><ul id='lXJ5g'></ul><sub id='lXJ5g'></sub></form><legend id='lXJ5g'></legend><bdo id='lXJ5g'><pre id='lXJ5g'><center id='lXJ5g'></center></pre></bdo></b><th id='lXJ5g'></th></span></q></dt></tr></i><div id='lXJ5g'><tfoot id='lXJ5g'></tfoot><dl id='lXJ5g'><fieldset id='lXJ5g'></fieldset></dl></div>

        <bdo id='lXJ5g'></bdo><ul id='lXJ5g'></ul>
      <legend id='lXJ5g'><style id='lXJ5g'><dir id='lXJ5g'><q id='lXJ5g'></q></dir></style></legend>

      1. 打字稿中开关的替代品

        alternative of switch in typescript(打字稿中开关的替代品)
      2. <i id='p8QF6'><tr id='p8QF6'><dt id='p8QF6'><q id='p8QF6'><span id='p8QF6'><b id='p8QF6'><form id='p8QF6'><ins id='p8QF6'></ins><ul id='p8QF6'></ul><sub id='p8QF6'></sub></form><legend id='p8QF6'></legend><bdo id='p8QF6'><pre id='p8QF6'><center id='p8QF6'></center></pre></bdo></b><th id='p8QF6'></th></span></q></dt></tr></i><div id='p8QF6'><tfoot id='p8QF6'></tfoot><dl id='p8QF6'><fieldset id='p8QF6'></fieldset></dl></div>
          <tfoot id='p8QF6'></tfoot>

            • <bdo id='p8QF6'></bdo><ul id='p8QF6'></ul>
            • <small id='p8QF6'></small><noframes id='p8QF6'>

                <tbody id='p8QF6'></tbody>
              <legend id='p8QF6'><style id='p8QF6'><dir id='p8QF6'><q id='p8QF6'></q></dir></style></legend>

                  本文介绍了打字稿中开关的替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试为我的开关柜考虑任何替代方案,因为它很长我有嵌套的开关盒,看起来像这样

                  I am trying to think of any alternative for my switchcase as it is a very long I have nested switch case which looks like this

                  switch (currentTab) {
                              case pending:
                                  switch (status) {
                                      case approved:
                                      case denied:
                                          break;
                  
                                      case partialApproved:
                                          finalUpdatedInvoiceAmount = updatedInvoiceAmount - (feeAmount - (approvedFeeAmount || 0));
                                          break;
                                  }
                                  break;
                  
                              case approved:
                                  switch (status) {
                                      case denied:
                                      case partialApproved:
                                          finalUpdatedInvoiceAmount = updatedInvoiceAmount - (feeAmount - (approvedFeeAmount || 0));
                                          break;
                                  }
                                  break;
                  
                              case denied:
                                  switch (status) {
                                      case approved:
                                      case partialApproved:
                                          finalUpdatedInvoiceAmount = oldApprovedFeeAmount ? updatedInvoiceAmount + (feeAmount - oldApprovedFeeAmount) : updatedInvoiceAmount - (feeAmount - (approvedFeeAmount || 0));
                                          break;
                                  }
                                  break;
                  
                              case partiallyApprovedTab:
                                  switch (status) {
                                      case approved:
                                      case denied:
                                      case partialApproved:
                                          finalUpdatedInvoiceAmount = oldApprovedFeeAmount ? updatedInvoiceAmount + (feeAmount - oldApprovedFeeAmount) : updatedInvoiceAmount - (feeAmount - (approvedFeeAmount || 0));
                                          break;
                                  }
                                  break;
                          }
                  

                  这是另一种可能性吗?由于代码非常庞大,以后可能会进入其他情况.

                  is an alternate possibility for this? As the code is very huge and later other cases might enter in this.

                  推荐答案

                  或许你可以试试handlerMap:

                  Maybe you can try handlerMap:

                  const handler1 = () => { finalUpdatedInvoiceAmount = updatedInvoiceAmount - (feeAmount - (approvedFeeAmount || 0)); }
                  const handler2 = () => { finalUpdatedInvoiceAmount = oldApprovedFeeAmount ? updatedInvoiceAmount + (feeAmount - oldApprovedFeeAmount) : updatedInvoiceAmount - (feeAmount - (approvedFeeAmount || 0)); }
                  
                  const handlerMap = {
                    [pending]: {
                      [partialApproved]: handler1
                    },
                    [approved]: {
                      [denied]: handler1,
                      [partialApproved]: handler1,
                    },
                    [denied]: {
                      [approved]: handler2,
                      [partialApproved]: handler2,
                    },
                    [partiallyApprovedTab]: {
                      [approved]: handler2,
                      [denied]: handler2,
                      [partialApproved]: handler2,
                    }
                  }
                  
                  handlerMap[currentTab] && handlerMap[currentTab][status] && handlerMap[currentTab][status]()
                  // handlerMap[currentTab]?.[status]?.()
                  

                  这篇关于打字稿中开关的替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                  <legend id='HPQTa'><style id='HPQTa'><dir id='HPQTa'><q id='HPQTa'></q></dir></style></legend>
                    <bdo id='HPQTa'></bdo><ul id='HPQTa'></ul>
                    • <tfoot id='HPQTa'></tfoot>

                        <i id='HPQTa'><tr id='HPQTa'><dt id='HPQTa'><q id='HPQTa'><span id='HPQTa'><b id='HPQTa'><form id='HPQTa'><ins id='HPQTa'></ins><ul id='HPQTa'></ul><sub id='HPQTa'></sub></form><legend id='HPQTa'></legend><bdo id='HPQTa'><pre id='HPQTa'><center id='HPQTa'></center></pre></bdo></b><th id='HPQTa'></th></span></q></dt></tr></i><div id='HPQTa'><tfoot id='HPQTa'></tfoot><dl id='HPQTa'><fieldset id='HPQTa'></fieldset></dl></div>
                            <tbody id='HPQTa'></tbody>

                          <small id='HPQTa'></small><noframes id='HPQTa'>