refactor state handling to make application available independent of the state
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
import { Component, Vue } from 'vue-property-decorator';
|
||||
import { AsyncLazy } from '@/infrastructure/Threading/AsyncLazy';
|
||||
import { IApplicationContext } from '@/application/Context/IApplicationContext';
|
||||
import { buildContext } from '@/application/Context/ApplicationContextProvider';
|
||||
import { buildContextAsync } from '@/application/Context/ApplicationContextFactory';
|
||||
import { IApplicationContextChangedEvent } from '@/application/Context/IApplicationContext';
|
||||
import { IApplication } from '@/domain/IApplication';
|
||||
import { ICategoryCollectionState } from '@/application/Context/State/ICategoryCollectionState';
|
||||
import { EventSubscriptionCollection } from '../infrastructure/Events/EventSubscriptionCollection';
|
||||
|
||||
// @ts-ignore because https://github.com/vuejs/vue-class-component/issues/91
|
||||
@Component
|
||||
export abstract class StatefulVue extends Vue {
|
||||
public static instance = new AsyncLazy<IApplicationContext>(
|
||||
() => Promise.resolve(buildContext()));
|
||||
private static readonly instance = new AsyncLazy<IApplicationContext>(() => buildContextAsync());
|
||||
|
||||
protected readonly events = new EventSubscriptionCollection();
|
||||
|
||||
@@ -20,7 +18,6 @@ export abstract class StatefulVue extends Vue {
|
||||
public async mounted() {
|
||||
const context = await this.getCurrentContextAsync();
|
||||
this.ownEvents.register(context.contextChanged.on((event) => this.handleStateChangedEvent(event)));
|
||||
this.initialize(context.app);
|
||||
this.handleCollectionState(context.state, undefined);
|
||||
}
|
||||
public destroyed() {
|
||||
@@ -28,7 +25,6 @@ export abstract class StatefulVue extends Vue {
|
||||
this.events.unsubscribeAll();
|
||||
}
|
||||
|
||||
protected abstract initialize(app: IApplication): void;
|
||||
protected abstract handleCollectionState(
|
||||
newState: ICategoryCollectionState, oldState: ICategoryCollectionState | undefined): void;
|
||||
protected getCurrentContextAsync(): Promise<IApplicationContext> {
|
||||
|
||||
Reference in New Issue
Block a user