Skip to content

Commit

Permalink
fix(nx-plugin): make nx plugin templates compatible with rxjs trpc cl…
Browse files Browse the repository at this point in the history
…ient (#430)
  • Loading branch information
goetzrobin authored May 24, 2023
1 parent 8ddb9ad commit 5748077
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 294 deletions.
11 changes: 7 additions & 4 deletions apps/trpc-app/src/app/pages/index.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { injectTRPCClient } from '../../trpc-client';
import { AsyncPipe, DatePipe, JsonPipe, NgFor, NgIf } from '@angular/common';
import { FormsModule, NgForm } from '@angular/forms';
import { Note } from '../../note';
import { BehaviorSubject, shareReplay, switchMap } from 'rxjs';
import { shareReplay, Subject, switchMap, take } from 'rxjs';
import { waitFor } from '@analogjs/trpc';

const inputTw =
Expand Down Expand Up @@ -93,7 +93,7 @@ const btnTw =
})
export default class HomeComponent {
private _trpc = injectTRPCClient();
public triggerRefresh$ = new BehaviorSubject(true);
public triggerRefresh$ = new Subject<void>();
public notes$ = this.triggerRefresh$.pipe(
switchMap(() => this._trpc.note.list.query()),
shareReplay(1)
Expand All @@ -102,6 +102,7 @@ export default class HomeComponent {

constructor() {
void waitFor(this.notes$);
this.triggerRefresh$.next();
}

public noteTrackBy = (index: number, note: Note) => {
Expand All @@ -115,14 +116,16 @@ export default class HomeComponent {
}
this._trpc.note.create
.mutate({ title: this.newNote })
.subscribe(() => this.triggerRefresh$.next(true));
.pipe(take(1))
.subscribe(() => this.triggerRefresh$.next());
this.newNote = '';
form.form.reset();
}

public removePost(id: number) {
this._trpc.note.remove
.mutate({ id })
.subscribe(() => this.triggerRefresh$.next(true));
.pipe(take(1))
.subscribe(() => this.triggerRefresh$.next());
}
}
Loading

0 comments on commit 5748077

Please sign in to comment.