-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
[base-controller] ControllerMessenger selectors skip initial value #3649
Labels
Comments
Gudahtt
added a commit
that referenced
this issue
Dec 22, 2023
The "selectors" feature of the `ControllerMessenger` did not work correctly for the first event published after subscribing, because the original value of the payload (at time of subscribing) was not available for comparison. To address this, a `registerInitialEventPayload` method has been added to the `ControllerMessenger` and `RestrictedControllerMessenger`. This allows registering a function that returns the "event payload state" at a given time, which is used internally by the `subscribe` method to correctly initialize the payload cache when a subscriber with a selector is added. This ensures that the selector workds correctly even for the initial state change, in that it will return the correct previous value, and not fire at all if the selected piece of state is unchanged. In a later PR, `BaseControllerV2` can be updated to register an event payload for the `stateChange` event. This will fix this flaw for the `stateChange` event of each controller. Fixes #3649
3 tasks
Gudahtt
added a commit
that referenced
this issue
Dec 22, 2023
The "selectors" feature of the `ControllerMessenger` did not work correctly for the first event published after subscribing, because the original value of the payload (at time of subscribing) was not available for comparison. To address this, a `registerInitialEventPayload` method has been added to the `ControllerMessenger` and `RestrictedControllerMessenger`. This allows registering a function that returns the "event payload state" at a given time, which is used internally by the `subscribe` method to correctly initialize the payload cache when a subscriber with a selector is added. This ensures that the selector workds correctly even for the initial state change, in that it will return the correct previous value, and not fire at all if the selected piece of state is unchanged. In a later PR, `BaseControllerV2` can be updated to register an event payload for the `stateChange` event. This will fix this flaw for the `stateChange` event of each controller. Fixes #3649
Gudahtt
added a commit
that referenced
this issue
Dec 22, 2023
The "selectors" feature of the `ControllerMessenger` did not work correctly for the first event published after subscribing, because the original value of the payload (at time of subscribing) was not available for comparison. To address this, a `registerInitialEventPayload` method has been added to the `ControllerMessenger` and `RestrictedControllerMessenger`. This allows registering a function that returns the "event payload state" at a given time, which is used internally by the `subscribe` method to correctly initialize the payload cache when a subscriber with a selector is added. This ensures that the selector workds correctly even for the initial state change, in that it will return the correct previous value, and not fire at all if the selected piece of state is unchanged. In a later PR, `BaseControllerV2` can be updated to register an event payload for the `stateChange` event. This will fix this flaw for the `stateChange` event of each controller. Fixes #3649
Gudahtt
added a commit
that referenced
this issue
Jan 3, 2024
The "selectors" feature of the `ControllerMessenger` did not work correctly for the first event published after subscribing, because the original value of the payload (at time of subscribing) was not available for comparison. To address this, a `registerInitialEventPayload` method has been added to the `ControllerMessenger` and `RestrictedControllerMessenger`. This allows registering a function that returns the "event payload state" at a given time, which is used internally by the `subscribe` method to correctly initialize the payload cache when a subscriber with a selector is added. This ensures that the selector workds correctly even for the initial state change, in that it will return the correct previous value, and not fire at all if the selected piece of state is unchanged. In a later PR, `BaseControllerV2` can be updated to register an event payload for the `stateChange` event. This will fix this flaw for the `stateChange` event of each controller. Fixes #3649
Gudahtt
added a commit
that referenced
this issue
Jan 8, 2024
The "selectors" feature of the `ControllerMessenger` did not work correctly for the first event published after subscribing, because the original value of the payload (at time of subscribing) was not available for comparison. To address this, a `registerInitialEventPayload` method has been added to the `ControllerMessenger` and `RestrictedControllerMessenger`. This allows registering a function that returns the "event payload state" at a given time, which is used internally by the `subscribe` method to correctly initialize the payload cache when a subscriber with a selector is added. This ensures that the selector workds correctly even for the initial state change, in that it will return the correct previous value, and not fire at all if the selected piece of state is unchanged. In a later PR, `BaseControllerV2` can be updated to register an event payload for the `stateChange` event. This will fix this flaw for the `stateChange` event of each controller. Fixes #3649
Gudahtt
added a commit
that referenced
this issue
Jan 9, 2024
The "selectors" feature of the `ControllerMessenger` did not work correctly for the first event published after subscribing, because the original value of the payload (at time of subscribing) was not available for comparison. To address this, a `registerInitialEventPayload` method has been added to the `ControllerMessenger` and `RestrictedControllerMessenger`. This allows registering a function that returns the "event payload state" at a given time, which is used internally by the `subscribe` method to correctly initialize the payload cache when a subscriber with a selector is added. This ensures that the selector workds correctly even for the initial state change, in that it will return the correct previous value, and not fire at all if the selected piece of state is unchanged. In a later PR, `BaseControllerV2` can be updated to register an event payload for the `stateChange` event. This will fix this flaw for the `stateChange` event of each controller. Fixes #3649
Gudahtt
added a commit
that referenced
this issue
Jan 9, 2024
The "selectors" feature of the `ControllerMessenger` did not work correctly for the first event published after subscribing, because the original value of the payload (at time of subscribing) was not available for comparison. To address this, a `registerInitialEventPayload` method has been added to the `ControllerMessenger` and `RestrictedControllerMessenger`. This allows registering a function that returns the "event payload state" at a given time, which is used internally by the `subscribe` method to correctly initialize the payload cache when a subscriber with a selector is added. This ensures that the selector workds correctly even for the initial state change, in that it will return the correct previous value, and not fire at all if the selected piece of state is unchanged. In a later PR, `BaseControllerV2` can be updated to register an event payload for the `stateChange` event. This will fix this flaw for the `stateChange` event of each controller. Fixes #3649
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ControllerMessenger
subscribe
function accepts an optional "selector" which can act like a Redux selector in that it narrows the state to just the subset that is of interest to that subscriber. The subscriber isn't invoked unless that specific piece of state is updated.However, these selectors don't consider the initial state. They will always run upon the first state change, regardless what has changed.
We should update the
ControllerMessenger
to cache the initial state as well, so that we can use that for a point of comparison even on the first update.The text was updated successfully, but these errors were encountered: