K
K
Konstantin2020-03-05 14:30:16
Angular
Konstantin, 2020-03-05 14:30:16

How does the following code work and what are the two taps for?

There is such a code.

public FormSub$: Subscription;
    public Form$: Subject<DynamicForm>;
    public Form: FormGroup;
    
    this.Form$ = new Subject<DynamicForm>();
    this.Form = new FormGroup({});
    ngOnInit(): void {
    		this.dynamicFormSub$ = this.dynamicFormService.getDynamicForm()
    			.pipe(
    				tap(response => this.dynamicForm.next(response)),
    				tap(response => {}));
    }).subscribe();


If I understood this code correctly, it expects data from `this.dynamic Form Service.getDynamicFrame()` then I don't understand why we use tap twice and what do we expect on the second tap?

Where `getDynamicForm` is:

getDynamicForm(): Observable<DynamicForm> {
    		return this.http.get<DynamicForm>(`form`, {
    		})
    		.pipe(
    			map(response => this.get(response)),
    
    		);
    	}


Why do we use a file read subscription if it only happens once:

this.dynamicFormService.getDynamicForm()
      .pipe()).subscribe() {})
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2020-03-05
@Junart1

why do we use tap twice and what do we expect on the second tap?

nothing. worth removing.
And generally enough
this.dynamicFormSub$ = this.dynamicFormService.getDynamicForm().subscribe(this.dynamicForm);

Although the subject in the component is also not needed, this is shit code.
Why do we use a file read subscription if it only happens once

For the request to be fulfilled, it is necessary to subscribe. Subscription "launches" a cold observable.
Worth reading https://habr.com/en/post/490988/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question