Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Load listeners on demand #287

Merged
merged 4 commits into from
Jun 10, 2018
Merged

Load listeners on demand #287

merged 4 commits into from
Jun 10, 2018

Conversation

bruiztorres
Copy link
Contributor

@bruiztorres bruiztorres commented Mar 29, 2018

I'm using your library in order to display some widgets within a dashboard. Since the dashboard in my app is just for displaying information (there is no way to edit the position and size of the widgets) it doesn't make sense to load some listeners that are not going to be fired.

AFAIK there is no "angular" way to attach/detach listeners conditionally (angular/angular#7626). It seems it won't be implemented in short time so I just implemented this solution as proposed in the thread.

I experienced an improvement in terms of performance so I guess it could be useful for others. @BTMorton I have tried to add some unit tests but I'm unable to run them locally. Am I missing something? Maybe you can give me a clue about that. Thanks in advance.

Please let me know your questions/concerns.

private _enableResizeListeners(): void {
const resizeSubs = this._resize$.subscribe((e: MouseEvent) => this.resizeEventHandler(e));

this._subscriptions.push(resizeSubs);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a standalone listener, rather than kept in the subscriptions method? Otherwise, it would be unsubscribed if the drag/resize config is not used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. I was trying to manage all listeners in the same way but since this listener must be always loaded I guess standalone listener is the best option. I will update it ASAP.

private _enableResizeListeners(): void {
const resizeSubs = this._resize$.subscribe((e: MouseEvent) => this.resizeEventHandler(e));

this._subscriptions.push(resizeSubs);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the testing, could you guide me in order to add some unit tests? I was unable to run them. I think I'm missing something.

@BTMorton BTMorton merged commit 8108cc9 into BTMorton:master Jun 10, 2018
@bruiztorres bruiztorres changed the title Manage listeners in order to load them when needed Load listeners on demand Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants