-
Notifications
You must be signed in to change notification settings - Fork 9
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
Issue/172 #199
Merged
Merged
Issue/172 #199
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
danielwiehl
added
BREAKING CHANGE
performance
Related to the performance of the platform.
labels
Nov 18, 2022
danielwiehl
force-pushed
the
issue/172
branch
from
November 18, 2022 16:09
87879e0
to
d7eb3a5
Compare
…gateway With the introduction of intent subscriptions, the observable is no longer used outside of the gateway to observe messages received by the broker and has therefore been removed from its API.
The emission context of an Observables may be different than the subscription context, which can lead to unexpected behavior on the subscriber side. For example, Angular uses zones (Zone.js) to trigger change detection. Angular applications expect an RxJS Observable to emit in the same Angular zone in which subscribed to the Observable. That is, if subscribing inside the Angular zone, emissions are expected to be received inside the Angular zone. Otherwise, the UI may not be updated as expected but delayed until the next change detection cycle. Similarly, if subscribing outside the Angular zone, emissions are expected to be received outside the Angular zone. Otherwise, this would cause unnecessary change detection cycles resulting in potential performance degradation. BREAKING CHANGE: For Angular applications, we strongly recommend replacing zone-specific decorators for `MessageClient` and `IntentClient` with an `ObservableDecorator`. See https://scion-microfrontend-platform-developer-guide.vercel.app/#chapter:angular-integration-guide:synchronizing-rxjs-observables-with-angular-zone for an example. It turned out that Angular zone synchronization with decorators for `MessageClient` and `IntentClient` is not sufficient and that observables should emit in the same Angular zone in which the subscription was performed. Using the new `ObservableDecorator` API, Angular zone synchronization can now be performed in a single place for all observables, as follows: - Remove decorators for `MessageClient` and `IntentClient` including their registration in the bean manager. - Provide a `NgZoneObservableDecorator` and register it in the bean manager before starting the platform. Note to register it as a bean, not as a decorator. For a complete example and detailed instructions, see https://scion-microfrontend-platform-developer-guide.vercel.app/#chapter:angular-integration-guide:synchronizing-rxjs-observables-with-angular-zone. ### Example of a decorator for synchronizing the Angular zone ```ts /** * Mirrors the source, but ensures subscription and emission {@link NgZone} to be identical. */ export class NgZoneObservableDecorator implements ObservableDecorator { constructor(private zone: NgZone) { } public decorate$<T>(source$: Observable<T>): Observable<T> { return new Observable<T>(observer => { const insideAngular = NgZone.isInAngularZone(); const subscription = source$ .pipe( subscribeInside(fn => this.zone.runOutsideAngular(fn)), observeInside(fn => insideAngular ? this.zone.run(fn) : this.zone.runOutsideAngular(fn)), ) .subscribe(observer); return () => subscription.unsubscribe(); }); } } ``` ### Registration of the decorator in the bean manager ```ts const zone: NgZone = ...; Beans.register(ObservableDecorator, {useValue: new NgZoneObservableDecorator(zone)}); ```
Optimizations include: - Reducing the number of events for the platform to track focus across microfrontends. - Dispatching of synthetic mouse events only from inactive microfrontends. - Delivery of synthetic mouse events to the active microfrontend only. - Disabling event listeners that are not needed in activators. - Listening to keyboard events only in contexts where keystrokes are registered. closes #172
danielwiehl
force-pushed
the
issue/172
branch
from
November 21, 2022 14:10
d7eb3a5
to
8316d8b
Compare
Marcarrian
approved these changes
Nov 23, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Issue
Issue Number: #172
Does this PR introduce a breaking change?
For Angular applications, we strongly recommend replacing zone-specific decorators for
MessageClient
andIntentClient
with anObservableDecorator
. See https://scion-microfrontend-platform-developer-guide.vercel.app/#chapter:angular-integration-guide:synchronizing-rxjs-observables-with-angular-zone for an example.It turned out that Angular zone synchronization with decorators for
MessageClient
andIntentClient
is not sufficient and that observables should emit in the same Angular zone in which the subscription was performed. Using the newObservableDecorator
API, Angular zone synchronization can now be performed in a single place for all observables, as follows:MessageClient
andIntentClient
including their registration in the bean manager.NgZoneObservableDecorator
and register it in the bean manager before starting the platform. Note to register it as a bean, not as a decorator.For a complete example and detailed instructions, see https://scion-microfrontend-platform-developer-guide.vercel.app/#chapter:angular-integration-guide:synchronizing-rxjs-observables-with-angular-zone.
Example of a decorator for synchronizing the Angular zone
Registration of the decorator in the bean manager