2
\$\begingroup\$
@Effect()
createQuiz$: Observable<Action> = this.actions$.pipe(
    ofType<quizAction.CreateQuiz>(quizAction.CREATE_QUIZ),
    switchMap((action) => {
        return this.quizService.createQuiz(action.payload)
        .pipe(
        map(() => {
            return new quizAction.CreateQuizCompleted()
        }),
        catchError(error => {
            console.log(error);
            return of(new quizAction.CreateQuizCompleted());
        })
        );

    })
);
    

export class QuizComponent implements OnInit {

  constructor(
    private quizService: QuizService, 
    private store:Store<{app: fromApp.State}>,
  ) { }

  ngOnInit(): void {
  }

  trackByIdx = (index: number): number => index;

  onCreate(): void {
    this.store.select(fromApp.selectUserId).pipe(
      take(1)
    ).subscribe(userId => this.handleCreate(userId));
  }

  handleCreate(userId: string): void {
    let value = this.quizService.createDefaultQuiz();
    if (this.quizService.hasPermission(userId) && this.quizService.validateQuiz(value)) {
      this.store.dispatch(new quizAction.CreateQuiz(value));
    }
  }
}

I am wondering if there's any memory leak that can occur or any non-idiomatic patterns that I am using without knowing. Does everything look fine?

\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.