Skip to content

Commit

Permalink
fix(LayerContext): subscribe once with first operator (#1272)
Browse files Browse the repository at this point in the history
* fix(LayerContext): subscribe once with first operator

* fix(ObjectUtils): remove negative variant #1271
  • Loading branch information
alecarn authored Jun 14, 2023
1 parent bc40e5c commit b83ec47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Directive, OnInit, OnDestroy, Optional, Input } from '@angular/core';

import { Subscription, merge } from 'rxjs';
import { buffer, debounceTime, filter } from 'rxjs/operators';
import { buffer, debounceTime, filter, first } from 'rxjs/operators';

import { RouteService, ConfigService } from '@igo2/core';
import {
Expand All @@ -13,6 +13,7 @@ import {
StyleService
} from '@igo2/geo';
import type { IgoMap } from '@igo2/geo';
import { ObjectUtils } from '@igo2/utils';

import { ContextService } from './context.service';
import { DetailedContext } from './context.interface';
Expand Down Expand Up @@ -58,12 +59,11 @@ export class LayerContextDirective implements OnInit, OnDestroy {
this.route.options.visibleOffLayersKey &&
this.route.options.contextKey
) {
const queryParams$$ = this.route.queryParams.subscribe((params) => {
if (Object.keys(params).length > 0) {
this.queryParams = params;
queryParams$$.unsubscribe();
}
});
this.route.queryParams
.pipe(first(params => !ObjectUtils.isEmpty(params)))
.subscribe((params) => {
this.queryParams = params;
});
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/utils/src/lib/object-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,8 @@ export class ObjectUtils {

return newObj;
}

static isEmpty(obj: object): boolean {
return Object.keys(obj).length === 0;
}
}

0 comments on commit b83ec47

Please sign in to comment.