There are cases where a Dara variable is not directly used by a useVariable hook, it can still 'live' in client-side state and be updated by actions. E.g.
from dara.core import Variable
from dara.components import Input
sync_to = Variable()
Input(onchange=sync_to.sync())
In systems relying on the event bus events to track the current state of the variable, in the scenario above there was never an event fired about the variable state changing since only useVariable used to fire events.
This PR adds explicit events about updated variables to the variable-mutating actions.
Implementation Description
Added event bus to the context injected into actions, grabbing from nearest capturer with useEventBus. Actions then simply publish events when they mutate variables
Any new dependencies Introduced
How Has This Been Tested?
Unit tests added
Tested code in internal product
PR Checklist:
[x] I have implemented all requirements? (see JIRA, project documentation).
[x] I am not affecting someone else's work, If I am, they are included as a reviewer.
[x] I have added relevant tests (unit, integration or regression).
[ ] I have added comments to all the bits that are hard to follow.
[ ] I have added/updated Documentation.
[ ] I have updated the appropriate changelog with a line for my changes.
Motivation and Context
There are cases where a Dara variable is not directly used by a
useVariable
hook, it can still 'live' in client-side state and be updated by actions. E.g.In systems relying on the event bus events to track the current state of the variable, in the scenario above there was never an event fired about the variable state changing since only
useVariable
used to fire events.This PR adds explicit events about updated variables to the variable-mutating actions.
Implementation Description
Added event bus to the context injected into actions, grabbing from nearest capturer with
useEventBus
. Actions then simply publish events when they mutate variablesAny new dependencies Introduced
How Has This Been Tested?
Unit tests added Tested code in internal product
PR Checklist:
Screenshots (if appropriate):