Skip to content
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

Pause WindowSynchronizerService #51

Closed
mcdenhoed opened this issue Jan 23, 2020 · 4 comments
Closed

Pause WindowSynchronizerService #51

mcdenhoed opened this issue Jan 23, 2020 · 4 comments

Comments

@mcdenhoed
Copy link

Hi!

I'm using ngx-golden-layout in a project that is not using GL's pop-out feature. As such, I don't need synchronization of Angular services between windows. I notice while profiling my app that the service is ticking in the background when the app is idle. Is it possible to configure ngx-golden-layout to disable popouts/turn off the sync service?

Thanks for writing these bindings, they're awesome!

@martin31821
Copy link
Member

Can you elaborate on this a bit? If you don't add the @MultiWindowService to your services, then the multiwindow functionality should be completely disabled and not cause any overhead.

@mcdenhoed
Copy link
Author

Sure!

I have a <golden-layout-root> element in an Angular Component. I'm initializing it with the following settings:

settings: {
      showPopoutIcon: false,
      showMaximiseIcon: false,
      showCloseIcon: false
    }

When I profile in Chrome, I see this timer firing occasionally:

this.appref.tick = (): void => {
for (const ar of (this.topWindow as any).__apprefs) {
ar._zone.run(() => ar.__tick());
}
};

It's a very small amount of CPU utilization, but figured it would be nice to turn it off if I didn't need it.

I don't see any references to MultiWindowService or WindowSynchronizationService in my code; is there something I need to do to opt out of them?

@martin31821
Copy link
Member

That's not a concern, since these are the times, angular would tick anyway.

// attach the application reference to the root window, save the original 'tick' method
anyWin.__apprefs.push(this.appref);
(this.appref as any).__tick = this.appref.tick;
// Overwrite the tick method running all apprefs in their zones.
this.appref.tick = (): void => {
for (const ar of (this.topWindow as any).__apprefs) {
ar._zone.run(() => ar.__tick());
}
};

What I'm doing here is overwriting the tick method of the original angular ApplicationRef (see: https://angular.io/api/core/ApplicationRef#tick)

I need to do that in all windows and whenever any of the windows occurs to have a tick, share this tick between all windows. This infers calling the original tick method (here, this is __tick) on all windows in their corresponding zones.

As long as you have a single window, all ticks originate from some interaction on your site (you might want to read a bit on zone.js for this matter).

For more information about performance and alternatives to broadcasting, consider #14.

@mcdenhoed
Copy link
Author

Ahhh, I understand; that makes sense. Thanks for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants