diff --git a/npm/ng-packs/packages/core/src/lib/services/replaceable-components.service.ts b/npm/ng-packs/packages/core/src/lib/services/replaceable-components.service.ts index 418e608c49..3f2b2cd17c 100644 --- a/npm/ng-packs/packages/core/src/lib/services/replaceable-components.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/replaceable-components.service.ts @@ -4,20 +4,27 @@ import { ReplaceableComponents } from '../models/replaceable-components'; import { BehaviorSubject, Observable } from 'rxjs'; import { noop } from '../utils/common-utils'; import { map, filter } from 'rxjs/operators'; +import { InternalStore } from '../utils/internal-store-utils'; @Injectable({ providedIn: 'root' }) export class ReplaceableComponentsService { - private components$ = new BehaviorSubject([]); + private state: InternalStore; get replaceableComponents$(): Observable { - return this.components$.asObservable(); + return this.state.sliceState(state => state); } get replaceableComponents(): ReplaceableComponents.ReplaceableComponent[] { - return this.components$.value; + return this.state.state; } - constructor(private ngZone: NgZone, private router: Router) {} + get onUpdate$(): Observable { + return this.state.sliceUpdate(state => state); + } + + constructor(private ngZone: NgZone, private router: Router) { + this.state = new InternalStore([]); + } // TODO: Create a shared service for route reload and more private reloadRoute() { @@ -36,7 +43,7 @@ export class ReplaceableComponentsService { } add(replaceableComponent: ReplaceableComponents.ReplaceableComponent, reload?: boolean): void { - let replaceableComponents = this.components$.value; + let replaceableComponents = this.state.state; const index = replaceableComponents.findIndex( component => component.key === replaceableComponent.key, @@ -48,7 +55,7 @@ export class ReplaceableComponentsService { replaceableComponents = [...replaceableComponents, replaceableComponent]; } - this.components$.next(replaceableComponents); + this.state.patch(replaceableComponents); if (reload) this.reloadRoute(); }