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
feat(angular): add support for onpush change detection strategy #4997
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 5ff9e7c The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
||
it('callback is called when interpreted authservice changes', () => { |
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.
We no longer return the facade from the subscribe function, instead it just invokes a callback so testing that the callback gets called.
@@ -64,6 +69,7 @@ export class SetupTotpComponent implements OnInit { | |||
|
|||
logger.info('totp code was generated:', totpCode); | |||
this.qrCodeSource = await QRCode.toDataURL(totpCode); | |||
this.qrCodeSource$.next(this.qrCodeSource); |
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.
BehaviorSubject
is a type of observable that takes an initial value and emits current value to observers. Using it with the async pipe like"qrCodeSource$ | async"
will automatically subscribe to new values and mark component for check when qrCodeSource
changes, and will automatically unsubscribe when component is destroyed. It's a cleaner way of subscribing to an observable and then running change detection.
Description of changes
Changes authenticator component to use
OnPush
strategy, which means it can be consumed by components that use eitherOnPush
orDefault
strategy.e.g.
works the same as
Because authenticator now uses
OnPush
, we run change detection manually (changeDetector.detectChanges()
) whenever theauthService
updates. This is achieved by creating an observable from the auth serviceusing rxjs, which can then be natively subscribed to emit events when
authService
updates.Issue #, if available
fixes #4899
Description of how you validated changes
Checklist
yarn test
passes and tests are updated/addedsideEffects
field updatedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.