Change is emitted after Store's action handler even when state is not changed
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 312
- PR merge metrics
- No merged PRs in 30d
Description
It looks like alt code emits change event from Stores even when nothing was actually changed, i.e. when `setState` was not even called in the handler. I wonder what's the reason behind such behaviour, if it's intended (it seems that it is, looking at the code).
I have cases when `setState` might not be called from the action handler under certain circumstances. Besides, `setState` might be called to set a primitive value (boolean, number or string) that already has the same value (for example, boolean flag was already set to `true`). To prevent this, I have to manually insert `this.preventDefault()` and manually check whether my `setState()` is actually going to change something to save performance. I would love if the framework did it for me. I know it might be not reasonable to always compare the whole new state and old state, but just comparing the primitive values would already cover many cases, in my opinion.
Contributor guide
Research direction
Start by tracing the Store action-handler path that emits the change event, then reproduce both a handler that skips setState and one that assigns an unchanged primitive. Done means the intended state-change behavior is specified and covered by tests, including the no-change cases described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100