|
|
|
|
@ -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<ReplaceableComponents.ReplaceableComponent[]>;
|
|
|
|
|
|
|
|
|
|
get replaceableComponents$(): Observable<ReplaceableComponents.ReplaceableComponent[]> {
|
|
|
|
|
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<ReplaceableComponents.ReplaceableComponent[]> {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|