Add finer control for store state with events
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 3.4k
- Forks
- 312
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Hi,
I currently have a number of stores which contain state across functional areas of my application. For example, I have one store to deal with all state regarding users. I maintain the state of the currently selected user, the list of all users, any filter that a user has applied, etc...
```
constructor () {
...
this.state = {
userList: [],
currentUser: null,
userFilter: '',
error: 0,
}
}
```
Using the store in this way saves a good amount of boilerplate code. I don't have to have a separate store for each one of the variables in the UserStore's state. I can also reuse functions in the UserStore for each of these items.
The downside to this approach is that the UserStore's change events are overly generic. I may update just one attribute of the state in a given function...
```
userLoaded (userData) {
this.setState({currentUser: userData});
}
```
But then the change event would fire callbacks on components that don't necessarily care about the currentUser. They may be waiting for an update of the userFilter or errors.
Would it be possible to add some type of extra change events so that I could fire events specific to particular pieces of the state? In this case, I would want to trigger a "UserLoaded" change event.
Or should I just separate my state into separate stores? Perhaps there is another way?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Es sind keine Dateien oder Tests identifiziert. Beginne damit, nachzuverfolgen, wie UserStore.setState Änderungsereignisse auslöst und wie Komponenten sich anmelden, und vergleiche anschließend bereichsbezogene Ereignisse mit separaten Stores. Als abgeschlossen würde ein von einem Maintainer genehmigtes Design für zustandsspezifische Änderungsbenachrichtigungen oder eine Alternative gelten, deren Verhalten definiert und getestet ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- frontend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100