<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          ReselectRedux 的選擇器庫

          聯(lián)合創(chuàng)作 · 2023-09-26 07:55

          Reselect 是一個 Redux 的選擇器庫,靈感來源于 NuclearJS

          • Selector 可以計算衍生的數(shù)據(jù),可以讓 Redux 存儲盡可能少的 state 。

          • Selector 非常高效,除非某個參數(shù)發(fā)生變化,否則不會發(fā)生計算過程。

          • Selector 是可組合的,它們可以輸入、傳遞到其他的選擇器。

          示例:

          import { createSelector } from 'reselect'
          
          const shopItemsSelector = state => state.shop.items
          const taxPercentSelector = state => state.shop.taxPercent
          
          const subtotalSelector = createSelector(
            shopItemsSelector,
            items => items.reduce((acc, item) => acc + item.value, 0)
          )
          
          const taxSelector = createSelector(
            subtotalSelector,
            taxPercentSelector,
            (subtotal, taxPercent) => subtotal * (taxPercent / 100)
          )
          
          export const totalSelector = createSelector(
            subtotalSelector,
            taxSelector,
            (subtotal, tax) => ({ total: subtotal + tax })
          )
          
          let exampleState = {
            shop: {
              taxPercent: 8,
              items: [
                { name: 'apple', value: 1.20 },
                { name: 'orange', value: 0.95 },
              ]
            }
          }
          
          console.log(subtotalSelector(exampleState)) // 2.15
          console.log(taxSelector(exampleState))      // 0.172
          console.log(totalSelector(exampleState))    // { total: 2.322 }
          瀏覽 27
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  一级片电影中文字幕 | 成人无码一区二区三区 | 欧美性爱日韩精品 | 国产一区免费看 | 成人免费三级91 |