-
Notifications
You must be signed in to change notification settings - Fork 261
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
Replace Observable and ModelChangeListener with EventBus #3749
Replace Observable and ModelChangeListener with EventBus #3749
Conversation
Instead of directly listening to `ObservableList`, we instead send out events for subscribers to consume. - ChatMessageAdded - PlayerConnected - PlayerDisconnected - ServerStopped This also means `MapTool` no longer needs to maintain a list of messages since the panel can directly listen for and maintain the list. `ObservableList` is no longer necessary and has been replaced with `List` where used.
The use of the `Observable`/`Observer` pattern was unnecessary here since the objects are created together anyways, and the observer was very simple.
With this change, subscribers no longer need to subscribe to a particular model object but can generically listen for event types that come from anywhere. In particular, this frees several components from having to ensure that their current zone is the one they are actually listening to. For any components that relied on a particular zone, these include a check that the event's zone matches the one in the component. For the most part, this change does not change behaviour beyond handling events in the new way. There are a few exceptions where components unconditionally responded to every model event whether or not it was actually applicable. These components are now more constrained in what they respond to: - `UndoPerZone` no longer subscribes to anything as it did nothing but log all of a zone's events. - `DrawPanelTreeModel` only subscribes to the `DrawableChanged` event. - `TokenPanelTreeModel` only subscribes to the various `Token*` events. - `ZoneRenderer` only subscribes to the events that it already handled explicitly. But it no longer calls `updateTokenTree()` and `repaintDebouncer.dispatch()` for all the other possible events. All the events that were fired this way were in the `Zone.Event` enum (which no longer exists). Here is the mapping from old to new: - `Zone.Event.TOKEN_ADDED`: `TokenAdded` - `Zone.Event.TOKEN_REMOVED`: `TokenRemoved` - `Zone.Event.TOKEN_CHANGED`: `TokenChanged` - `Zone.Event.GRID_CHANGED`: `GridChanged` - `Zone.Event.DRAWABLE_ADDED`: `DrawableAdded` - `Zone.Event.DRAWABLE_REMOVED`: `DrawableRemoved` - `Zone.Event.FOG_CHANGED`: `FogChanged` - `Zone.Event.LABEL_ADDED`: `LabelAdded` - `Zone.Event.LABEL_REMOVED`: `LabelRemoved` - `Zone.Event.LABEL_CHANGED`: `LabelChanged` - `Zone.Event.TOPOLOGY_CHANGED`: `TopologyChanged` - `Zone.Event.INITIATIVE_LIST_CHANGED`: `InitiativeListChanged` - `Zone.Event.BOARD_CHANGED`: `BoardChanged` - `Zone.Event.TOKEN_EDITED`: `TokenEdited` - `Zone.Event.TOKEN_MACRO_CHANGED`: `TokenMacroChanged` - `Zone.Event.TOKEN_PANEL_CHANGED`: `TokenPanelChanged` There were some existing events for EventBus that have been replaced with easier-to-use alternatives that are consistent with the other events: - `TokensAddedEvent`: `TokensAdded` - `TokensRemovedEvent`: `TokensRemoved` - `TokensChangedEvent`: `TokensChanged` In conjunction with that, the `TokenEventBusBridge` is no more. There was some important functionality in there to post token events in response to corresponding zone events, but that is now handled by posting the token events at the some point that the zone events are posted. This functionality was also added to `ServeMessageHandler` for good measure. Finally, since `BaseModel` only offered functionality for model events, it has been removed and existing uses (`Zone`, `Token`) no longer have a base class. Of course, `ModelChangeListener` is also gone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 52 of 52 files at r1, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @kwvanderlinde)
@kwvanderlinde need a spotless check |
Formatting is fine (or so spotless says on my end). The JAR download just failed on Github:
Reran and everything checked out. |
Identify the Bug or Feature request
Relates to #1827
Description of the Change
This change moves the remaining from legacy event models to
EventBus
. The two legacy event models are:Observable
/Observer
BaseModel
/ModelChangeListener
One use of
Observable
/Observer
was removed as being unnecessary (ChatTyperObserver
), while the remaining uses are now covered by these new events:ChatMessageAdded
PlayerConnected
PlayerDisconnected
ServerStopped
With that gone, our custom
ObservableList
or the relatedPlayerListModel
could be deleted in favour of plain lists.The remainder and bulk of the change is in removing
ModelChangeListener
, which amounts to replacing eachZone.Event
tag with a corresponding event class. There were some existing event classes (TokensAddedEvent
,TokensRemovedEvent
,TokensChangedEvent
) thatTokenEventBusBridge
translated to, but these have been replaced with new ones that are easier to build and consume, and which are consistent with how the other events works.With all the model events replaced, we could remove these types:
ModelChangeListener
BaseModel
TokenEventBusBridge
Possible Drawbacks
If done correctly, should be nothing. It just requires a bunch of testing
Documentation Notes
N/A (refactoring)
Release Notes
N/A
This change is