-
Notifications
You must be signed in to change notification settings - Fork 0
feat: introduce EventEmitter-based event system #132
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
Conversation
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.
Summary of Changes
Hello @MinCrohn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a comprehensive event-driven system to the patch-map library by integrating a new WildcardEventEmitter. This refactoring significantly enhances the flexibility and extensibility of the library, allowing users and internal components to react to various lifecycle and state changes through a unified event mechanism. Key modules like Patchmap, StateManager, and UndoRedoManager have been updated to leverage this new system, and a dedicated SelectionModel has been added for managing element selections within the Transformer.
Highlights
- Wildcard Event System: Implemented
WildcardEventEmitterto enable namespaced events (e.g.,history:undone) and wildcard subscriptions (e.g.,history:*), providing granular and flexible event handling. - Event-Driven Core Modules:
Patchmap,StateManager, andUndoRedoManagernow extendWildcardEventEmitter, emitting detailed lifecycle and state-change events for better observability and integration. - Dedicated Selection Management: Introduced
SelectionModelto professionally manage the selection state within theTransformer, allowing programmatic control and event-driven responses to selection changes. UndoRedoManagerAPI Update: TheUndoRedoManager's event subscription method has been standardized fromsubscribetoon, aligning with the newEventEmitterpattern.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a powerful EventEmitter-based event system, which is a significant architectural improvement. The refactoring of core modules like Patchmap, StateManager, and UndoRedoManager to be event-driven is well-executed. The addition of the SelectionModel for managing selection state is also a great enhancement. The overall code quality is high, but I've identified a few areas for improvement, mainly concerning data encapsulation in getters and fixing a test case to align with the new event system. Addressing these points will make the implementation more robust.
|
/gemini review |
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.
Code Review
This pull request introduces a robust EventEmitter-based event system, which is a significant architectural improvement. The refactoring of Patchmap, StateManager, and UndoRedoManager to be event-driven is well-implemented, and the new SelectionModel effectively encapsulates selection logic. My review includes a minor documentation correction and a critical fix to prevent a potential memory leak in the Patchmap destroy lifecycle.
📑 Overview
This update focuses on improving the core architecture of the
patch-maplibrary to provide users with more powerful and flexible event-driven interactions. We've introduced aWildcardEventEmitterto refactor key modules (Patchmap,StateManager,UndoRedoManager) to be event-driven and added a newSelectionModelfor managing the selection state within theTransformer.✨ What's New? (New Features)
1. Powerful Wildcard Event System Introduced
The core classes of the library now inherit from
WildcardEventEmitter, which supports namespaces and wildcards (*). This allows users to subscribe to specific events individually or subscribe to all events within a specific feature group at once, making event management more flexible and concise.Code Example:
2. Detailed Lifecycle Events Provided
PatchmapandStateManagernow emit detailed lifecycle events for major operations such as initialization, drawing, updating, and state changes. This makes it easier to implement logic that corresponds to the application's state changes.Code Example:
3. Selection State Management Model (
SelectionModel) AddedA new
SelectionModelclass has been introduced to professionally manage the selection state of theTransformer. You can now easily control selected elements programmatically viatransformer.selectionand handle subsequent actions through events that are triggered whenever the selection state changes.Code Example:
🔄 What's Changed? (Changes & Refactoring)
1.
TransformerInternal Structure ImprovementThe
Transformerhas been refactored to use theSelectionModelinternally. The.elementsproperty is still supported, but it is now recommended to subscribe to events through theselectionmodel.UndoRedoManagerAPI Change:subscribe->onThe event subscription method for
UndoRedoManagerhas been changed to follow the universalEventEmitterpattern. The existingsubscribemethod has been removed, and you must now use theonmethod to subscribe to more specific events.Before:
After:
📢 Full List of Available Events
Here is a list of subscribable events introduced with this update.
Patchmappatchmap:initialized: Fired whenpatchmap.init()completes successfully.patchmap:draw: Fired when new data is rendered viapatchmap.draw().patchmap:updated: Fired when elements are updated viapatchmap.update().patchmap:destroyed: Fired when the instance is destroyed by callingpatchmap.destroy().UndoRedoManagerhistory:executed: Fired when a new command is added to the execution stack.history:undone: Fired whenundo()is executed.history:redone: Fired whenredo()is executed.history:cleared: Fired when all history is deleted withclear().history:destroyed: Fired whendestroy()is called.history:*: Subscribes to all of the abovehistory:namespace events.StateManagerstate:pushed: Fired when a new state is added to the stack.state:popped: Fired when the current state is removed from the stack.state:set: Fired when the state stack is reset and a new state is set viasetState().state:reset: Fired when all states are removed withresetState().state:destroyed: Fired whendestroy()is called.modifier:activated: Fired when a modifier state is activated.modifier:deactivated: Fired when a modifier state is deactivated.state:*: Subscribes to all of the abovestate:namespace events.modifier:*: Subscribes to all of the abovemodifier:namespace events.Transformerupdate_elements: Fired when the content oftransformer.elementsortransformer.selectionchanges.