Commit c671bf3
## Motivation
#### Homogenous selector types:
```ts
const selectorOne = (state: State) => state.something;
const selectorTwo = (state: State) => state.other;
createSelector([selectorOne, selectorTwo], () => ...);
```
#### Heterogenous selector types:
```ts
const selectorOne = (state: { something: string }) => state.something;
const selectorTwo = (state: { other: number }) => state.other;
createSelector([selectorOne, selectorTwo], () => ...);
```
Support for heterogenous typing is essential for selectors to function
properly, because selectors must be both mergeable and atomic. Without
heterogenous selectors, these becoming conflicting objectives.
- **Mergeable:**
- Without heterogenous typing for selectors, the size of the state type
for all selectors tend to inflate. This is because a selector's state
must be a supertype for the intersection of the state types of all of
its merged selectors, including selectors nested in the definitions of
merged selectors.
- Eventually, many selectors end up being defined with a state type that
is close to the entire Redux state.
- Paradoxically, selectors that only need access to very few properties
end up needing to have the widest state type, because they tend to be
merged into the most selectors across several nested levels.
- **Atomic:**
- When selectors are actually invoked, including in test files, it's not
always practical to prepare and pass in a very large state object.
- It's both safer and more convenient to restrict the state being passed
into the selector to the minimum size required for the selector to
function.
- This requirement becomes incompatible with the mergeability
requirement if all selectors must share a common state type.
Enabling merged selectors to accept different, even disjoint state types
resolves this issue.
> [!NOTE]
> See the
[`MultichainState`](https://github.com/MetaMask/metamask-extension/blob/4f970df0acec3e3bc80da08373aa3b16f23aae41/ui/selectors/multichain.ts#L53)
type for an example of a bloated selector state type which will become
unnecessary with this update.
## **Description**
- `[email protected]` supports heterogenous typing for selector inputs to
`createSelector` and `createDeepEqualSelector`.
- reduxjs/reselect#351
- reduxjs/reselect#274
- reduxjs/reselect#315
- Upgrade to `^5.1.1` (latest) is necessary to fix type issues in
`4.0.0`
-
https://app.circleci.com/jobs/github/MetaMask/metamask-extension/4320173
[](https://codespaces.new/MetaMask/metamask-extension/pull/29094?quickstart=1)
## **Related issues**
- Blocks TypeScript conversion of selectors for
MetaMask/MetaMask-planning#2894.
- #29014
## **Manual testing steps**
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
---------
Co-authored-by: MetaMask Bot <[email protected]>
1 parent 57f5a6b commit c671bf3
File tree
13 files changed
+185
-179
lines changed- lavamoat/browserify
- beta
- flask
- main
- mmi
- ui
- components/app/snaps
- snap-authorship-pill
- snap-icon
- ducks/bridge
- pages
- bridge/quotes
- confirmations/components/confirm/snaps/snaps-section
13 files changed
+185
-179
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1694 | 1694 | | |
1695 | 1695 | | |
1696 | 1696 | | |
1697 | | - | |
1698 | 1697 | | |
1699 | 1698 | | |
1700 | 1699 | | |
| 1700 | + | |
1701 | 1701 | | |
1702 | 1702 | | |
1703 | 1703 | | |
| |||
1756 | 1756 | | |
1757 | 1757 | | |
1758 | 1758 | | |
1759 | | - | |
1760 | | - | |
1761 | | - | |
1762 | | - | |
1763 | | - | |
1764 | | - | |
1765 | | - | |
1766 | 1759 | | |
1767 | 1760 | | |
1768 | 1761 | | |
| |||
5138 | 5131 | | |
5139 | 5132 | | |
5140 | 5133 | | |
| 5134 | + | |
| 5135 | + | |
| 5136 | + | |
| 5137 | + | |
| 5138 | + | |
| 5139 | + | |
| 5140 | + | |
5141 | 5141 | | |
5142 | 5142 | | |
5143 | 5143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1694 | 1694 | | |
1695 | 1695 | | |
1696 | 1696 | | |
1697 | | - | |
1698 | 1697 | | |
1699 | 1698 | | |
1700 | 1699 | | |
| 1700 | + | |
1701 | 1701 | | |
1702 | 1702 | | |
1703 | 1703 | | |
| |||
1756 | 1756 | | |
1757 | 1757 | | |
1758 | 1758 | | |
1759 | | - | |
1760 | | - | |
1761 | | - | |
1762 | | - | |
1763 | | - | |
1764 | | - | |
1765 | | - | |
1766 | 1759 | | |
1767 | 1760 | | |
1768 | 1761 | | |
| |||
5138 | 5131 | | |
5139 | 5132 | | |
5140 | 5133 | | |
| 5134 | + | |
| 5135 | + | |
| 5136 | + | |
| 5137 | + | |
| 5138 | + | |
| 5139 | + | |
| 5140 | + | |
5141 | 5141 | | |
5142 | 5142 | | |
5143 | 5143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1694 | 1694 | | |
1695 | 1695 | | |
1696 | 1696 | | |
1697 | | - | |
1698 | 1697 | | |
1699 | 1698 | | |
1700 | 1699 | | |
| 1700 | + | |
1701 | 1701 | | |
1702 | 1702 | | |
1703 | 1703 | | |
| |||
1756 | 1756 | | |
1757 | 1757 | | |
1758 | 1758 | | |
1759 | | - | |
1760 | | - | |
1761 | | - | |
1762 | | - | |
1763 | | - | |
1764 | | - | |
1765 | | - | |
1766 | 1759 | | |
1767 | 1760 | | |
1768 | 1761 | | |
| |||
5138 | 5131 | | |
5139 | 5132 | | |
5140 | 5133 | | |
| 5134 | + | |
| 5135 | + | |
| 5136 | + | |
| 5137 | + | |
| 5138 | + | |
| 5139 | + | |
| 5140 | + | |
5141 | 5141 | | |
5142 | 5142 | | |
5143 | 5143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1786 | 1786 | | |
1787 | 1787 | | |
1788 | 1788 | | |
1789 | | - | |
1790 | 1789 | | |
1791 | 1790 | | |
1792 | 1791 | | |
| 1792 | + | |
1793 | 1793 | | |
1794 | 1794 | | |
1795 | 1795 | | |
| |||
1848 | 1848 | | |
1849 | 1849 | | |
1850 | 1850 | | |
1851 | | - | |
1852 | | - | |
1853 | | - | |
1854 | | - | |
1855 | | - | |
1856 | | - | |
1857 | | - | |
1858 | 1851 | | |
1859 | 1852 | | |
1860 | 1853 | | |
| |||
5230 | 5223 | | |
5231 | 5224 | | |
5232 | 5225 | | |
| 5226 | + | |
| 5227 | + | |
| 5228 | + | |
| 5229 | + | |
| 5230 | + | |
| 5231 | + | |
| 5232 | + | |
5233 | 5233 | | |
5234 | 5234 | | |
5235 | 5235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
429 | | - | |
| 429 | + | |
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
| 100 | + | |
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| |||
722 | 726 | | |
723 | 727 | | |
724 | 728 | | |
725 | | - | |
726 | | - | |
727 | | - | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
728 | 734 | | |
729 | 735 | | |
730 | 736 | | |
| |||
827 | 833 | | |
828 | 834 | | |
829 | 835 | | |
830 | | - | |
831 | | - | |
832 | | - | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
833 | 841 | | |
834 | 842 | | |
835 | 843 | | |
| |||
898 | 906 | | |
899 | 907 | | |
900 | 908 | | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
909 | 921 | | |
910 | 922 | | |
911 | 923 | | |
| |||
0 commit comments