Skip to content

Instantly share code, notes, and snippets.

@joostme
Last active July 18, 2018 15:43
Show Gist options
  • Select an option

  • Save joostme/5787ee45a6724f6dc755f76470c16f7b to your computer and use it in GitHub Desktop.

Select an option

Save joostme/5787ee45a6724f6dc755f76470c16f7b to your computer and use it in GitHub Desktop.
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