Selectors are difficult to use directly in clients without assuming root state
- Dominant language
- TypeScript
- Stars
- 413
- Forks
- 308
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 253
Description
Recently the assets team introduced [changes](https://github.com/MetaMask/core/blob/b31794cd9d6667d8c8dedd0f56caaefc6441840f/packages/assets-controllers/src/selectors/balanceSelectors.ts#L32) which indicate two ways that developers want to use selectors that we may have not considered before but that we should probably provide guidance on.
1. Most of the selectors that we expect developers to write are centered around a single controller. However, what happens if they want to write a selector that makes use of state from multiple controllers?
2. What happens if developers want to pass a selector to `useSelector`?
Neither of these are very possible right now:
1. Access to the state of a given controller, much less multiple controllers, implies access to a root state, which is only available within and is specific to a client.
2. Selectors are designed to take the state of a single controller, but `useSelector` expects that selectors take the root state.
To solve these problems it seems that we would need to provide:
- utility functions for wrapping selectors such that they can take a root state instead of a controller's state
- better patterns for exporting selectors such that they can be wrapped en masse easily
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading packages/assets-controllers/src/selectors/balanceSelectors.ts and tracing how its selectors are intended to be consumed. Then inspect the current selector and useSelector patterns across the repository. Done means reaching an agreed approach for root-state wrapping and exporting selectors for multi-controller and client use cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100