Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(base-controller): Fix stateChange subscriptions with selectors #3702

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Dec 22, 2023

Explanation

Subscribers to the stateChange event of any BaseControllerV2-based controllers will now correctly handle the initial state change event.

Previously the initial state change would always result in this event firing, even for subscriptions with selectors where the selected value has not changed. Additionally, the previousValue returned was always set to undefined the first time.

BaseControllerV2 has been updated to correctly compare with the previous value even for the first state change. The returned previousValue is also now guaranteed to be correct even for the initial state change.

References

Fixes #3701

Changelog

@metamask/base-controller

  • Fixed: Subscribers to the stateChange event of any BaseControllerV2-based controllers will now correctly handle the initial state change event
    • Previously the initial state change would always result in this event firing, even for subscriptions with selectors where the selected value has not changed. Additionally, the previousValue returned was always set to undefined the first time.
    • BaseControllerV2 has been updated to correctly compare with the previous value even for the first state change. The returned previousValue is also now guaranteed to be correct even for the initial state change.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@Gudahtt

This comment was marked as resolved.

@Gudahtt Gudahtt force-pushed the fix-selectors-initial-value branch from 23c8fa5 to a89dd9f Compare January 3, 2024 20:19
@Gudahtt Gudahtt force-pushed the fix-state-change-event-selectors branch 3 times, most recently from 451b847 to 6e17f66 Compare January 3, 2024 21:07
@Gudahtt Gudahtt force-pushed the fix-selectors-initial-value branch 3 times, most recently from 596d89a to 34a6e69 Compare January 9, 2024 23:21
Base automatically changed from fix-selectors-initial-value to main January 9, 2024 23:25
Subscribers to the `stateChange` event of any `BaseControllerV2`-based
controllers will now correctly handle the initial state change event.

Previously the initial state change would always result in this event
firing, even for subscriptions with selectors where the selected value
has not changed. Additionally, the `previousValue` returned was always
set to `undefined` the first time.

`BaseControllerV2` has been updated to correctly compare with the
previous value even for the first state change. The returned
`previousValue` is also now guaranteed to be correct even for the
initial state change.

Fixes #3701
@Gudahtt Gudahtt force-pushed the fix-state-change-event-selectors branch from 6e17f66 to 0374150 Compare January 9, 2024 23:26
@Gudahtt Gudahtt marked this pull request as ready for review January 9, 2024 23:26
@Gudahtt Gudahtt requested a review from a team as a code owner January 9, 2024 23:26
@Gudahtt Gudahtt merged commit 2254707 into main Jan 10, 2024
136 checks passed
@Gudahtt Gudahtt deleted the fix-state-change-event-selectors branch January 10, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[base-controller] stateChange subscribers with selectors always fire on the first state change
2 participants