Skip to content

Commit

Permalink
🐛 FIX: trigger password score on init (#717)
Browse files Browse the repository at this point in the history
* 🐛 FIX: trigger password score on init

* 🚀 RELEASE: bump version
  • Loading branch information
antoantonyk committed Nov 5, 2023
1 parent 25adc10 commit 9234511
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "password-strength-meter",
"version": "9.0.0",
"version": "9.0.1",
"scripts": {
"ng": "ng",
"serve": "ng serve",
Expand Down
2 changes: 1 addition & 1 deletion projects/password-strength-meter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-password-strength-meter",
"version": "9.0.0",
"version": "9.0.1",
"dependencies": {
"tslib": "^2.5.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
EventEmitter,
HostBinding,
OnInit,
inject,
DestroyRef,
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import {
Expand All @@ -30,9 +28,7 @@ import {
templateUrl: './password-strength-meter.component.html',
styleUrls: ['./password-strength-meter.component.scss'],
})
export class PasswordStrengthMeterComponent implements OnInit, OnChanges {
private destroyRef = inject(DestroyRef);

export class PasswordStrengthMeterComponent implements OnChanges {
@Input() password: string;

@Input() minPasswordLength = 8;
Expand All @@ -58,9 +54,17 @@ export class PasswordStrengthMeterComponent implements OnInit, OnChanges {

constructor(
private passwordStrengthMeterService: IPasswordStrengthMeterService
) {}
) {
this.init();
}

ngOnChanges(changes: SimpleChanges) {
if (changes.password) {
this.passwordChangeObservable$.next(this.password);
}
}

ngOnInit(): void {
private init(): void {
this.passwordChangeObservable$
.pipe(
distinctUntilChanged(),
Expand All @@ -81,7 +85,7 @@ export class PasswordStrengthMeterComponent implements OnInit, OnChanges {
const result = this.calculateScore(value);
return of(result);
}),
takeUntilDestroyed(this.destroyRef)
takeUntilDestroyed()
)
.subscribe((result: FeedbackResult) => {
this.passwordStrength = result.score;
Expand All @@ -95,12 +99,6 @@ export class PasswordStrengthMeterComponent implements OnInit, OnChanges {
});
}

ngOnChanges(changes: SimpleChanges) {
if (changes.password) {
this.passwordChangeObservable$.next(this.password);
}
}

private calculateScore(value: string): FeedbackResult {
if (this.enableFeedback) {
return this.passwordStrengthMeterService.scoreWithFeedback(value);
Expand Down

0 comments on commit 9234511

Please sign in to comment.