diamondburned / dissent

Tiny native Discord app
https://flathub.org/apps/details/so.libdb.dissent
GNU General Public License v3.0
1.27k stars 40 forks source link

Refactor window/chat.go click propagation #223

Closed diamondburned closed 8 months ago

diamondburned commented 8 months ago

Currently, when a user clicks a channel or a guild, the following happens:

  1. The guild button emits the click event to the "controller".
  2. The "controller" is the sidebar, so the sidebar updates its state, then passes the event up to its "controller".
  3. The "controller" is now the main window view, so it updates its state.

This is really bad, because when the window view needs to synchronize its child widgets, there's a risk that the child widget functions might cause it to propagate back up to the window view, causing an infinite recursion.

The better design would be to only propagate up to the main window directly, which is then in charge of updating everything at once. With that, this should happen:

  1. The guild button emits the click event to the "controller".
  2. The "controller" is the main window view, so it updates its state.
  3. The main window view ensures that the sidebar and guild button are consistent.

This way, child widgets never have to worry about propagating back to its parents. Rather, it only has to worry about propagating to its children. User interaction is the only way that child widgets are permitted to propagate up. This will avoid any potential recursion issues.