Skip to content

Instantly share code, notes, and snippets.

@jtomaszewski
Last active June 7, 2018 10:22
Show Gist options
  • Save jtomaszewski/c18bbf53fc8255a45b34672ab0facbc8 to your computer and use it in GitHub Desktop.
Save jtomaszewski/c18bbf53fc8255a45b34672ab0facbc8 to your computer and use it in GitHub Desktop.
// wrong (impure)
class DateTimePickerComponent {
timeZone: string = "Europe/Warsaw";
constructor(private account: AccountService) {
if (this.account.currentUser) {
this.timeZone = this.account.currentUser.timeZone;
}
}
changeTimeZone(timeZone: string) {
this.timeZone = timeZone;
this.account.updateCurrentUser({
timeZone
});
}
}
// good (pure)
class DateTimePickerComponent {
@Input() timeZone: string = "Europe/Warsaw";
@Output() timeZoneChange: EventEmitter<string> = new EventEmitter();
changeTimeZone(timeZone: string) {
this.timeZoneChange.emit(timeZone);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment