Last active
July 18, 2018 15:43
-
-
Save joostme/5787ee45a6724f6dc755f76470c16f7b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { AutoUnsubscribe, takeWhileAlive } from 'take-while-alive'; | |
| @Component({ | |
| selector: 'edit-form', | |
| templateUrl: './edit-form.component.html', | |
| styleUrls: ['./edit-form.component.scss'] | |
| }) | |
| @AutoUnsubscribe() | |
| export class EditFormComponent { | |
| @ViewChild('form') | |
| form; | |
| constructor( | |
| private actions: Actions, | |
| private router: Router, | |
| private activatedRoute: ActivatedRoute | |
| ) { | |
| this.subscriptions = [ | |
| this.actions | |
| .pipe( | |
| ofType(FormActionType.FormSubmitted), | |
| map((action: FormSubmittedAction) => action.payload), | |
| map(actionResource => { | |
| this.form.reset(); | |
| this.router.navigate(['../'], { relativeTo: this.activatedRoute }); | |
| }), | |
| takeWhileAlive(this) | |
| ) | |
| .subscribe(), | |
| this.actions | |
| .pipe( | |
| ofType(FormActionType.FormSubmissionFailed), | |
| map((action: FormSubmissionFailedAction) => action.payload), | |
| map(issues => this.form.setErrors(toFormErrors(issues))), | |
| takeWhileAlive(this) | |
| ) | |
| .subscribe() | |
| ]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment