Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query select fires twice and collects observables #1071

Open
VolvoTruckExpress opened this issue Sep 11, 2023 · 0 comments
Open

Query select fires twice and collects observables #1071

VolvoTruckExpress opened this issue Sep 11, 2023 · 0 comments

Comments

@VolvoTruckExpress
Copy link

VolvoTruckExpress commented Sep 11, 2023

Is this a regression?

Yes

Description

I have a simple query:

@Injectable({ providedIn: 'root' })
export class BufferDataImportQuery extends QueryEntity<BufferDataImportState, IBufferDataImport> {
  document$ = this.select(t => t.document);
  originalDocument$ = this.select(t => t.originalDocument);
  xmlDocument$ = this.select(t => t.xmlDocument);
  documentPartner$ = this.select(t => t.document.partner);
  partnerName$ = this.select(t => t.document.partner.name);
  documentDetails$ = this.select(t => t.document?.details);
    ...
  constructor(protected store: BufferDataImportStore) {
    super(store);
  }
}

and a simple store:

@Injectable({ providedIn: 'root' })
@StoreConfig({ name: 'buffer-data-import' })
export class BufferDataImportStore extends EntityStore<BufferDataImportState, IBufferDataImport> {
  constructor() {
    super();
  }

  public updateDetail(detailId: number, detail: DocumentDetailUI) {
    this.update({ document: { ...this.getValue().document, details: arrayUpdate(this.getValue().document.details, detailId, { ...detail, detail }) } });
  }
}

and in some component:

export class DocumentImportDetailsListComponent implements OnInit, OnDestroy {
  detailsQuery$ = this.query.documentDetails$;
  document$ = this.query.document$;
  readonly$ = this.query.readonly$;

  constructor(
    private service: BufferDataImportService,
    private query: BufferDataImportQuery,
    ...
    ) {

    this.sub.add(this.detailsQuery$.subscribe({
      next: (details) => {
        console.log("test");
        ...
      }
    }));
  }
  ngOnDestroy(): void {
    this.sub.unsubscribe();
  }

The problem is that in the component, the next callback is triggered twice with the same value. This wouldn't be such a trouble since I could use take(1) . However I noticed that this.detailsQuery(Observable).source.source(Observable).source(BehaviorSubject).observers[] array keeps increasing to the order of thousands.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in

"@datorama/akita": "^8.0.0",
"@datorama/akita-ng-effects": "^1.0.6",
"@datorama/akita-ng-entity-service": "^8.0.0",
"rxjs": "^7.8.1",
"tslib": "^2.3.0",
"zone.js": "~0.11.8"

Anything else?

The console is spammed with hundreds of messages:

You need to enable the reset functionality:
reset | @ | datorama-akita.js:1105
-- | -- | --
  | (anonymous) | @ | layout-customizations.service.ts:23
  | __tryOrUnsub | @ | Subscriber.js:183
  | next | @ | Subscriber.js:122
  | _next | @ | Subscriber.js:72
  | next | @ | Subscriber.js:49
  | next | @ | Subject.js:39
  | next | @ | BehaviorSubject.js:30
....

Do you want to create a pull request?

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant