@eclipse-emfcloud/model-service-theia
Version:
Model service Theia
124 lines • 5.35 kB
JavaScript
;
// *****************************************************************************
// Copyright (C) 2023-2024 STMicroelectronics.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: MIT License which is
// available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: EPL-2.0 OR MIT
// *****************************************************************************
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FrontendModelHubImpl = exports.FrontendModelHubContext = exports.FrontendModelHubProvider = void 0;
const core_1 = require("@theia/core");
const inversify_1 = require("@theia/core/shared/inversify");
const common_1 = require("../common");
const frontend_model_accessor_bus_1 = require("./frontend-model-accessor-bus");
const frontend_model_hub_subscriber_1 = require("./frontend-model-hub-subscriber");
/**
* Dependency injection key for the Frontend Model Hub provider.
*/
exports.FrontendModelHubProvider = Symbol('FrontendModelHubProvider');
exports.FrontendModelHubContext = Symbol('FrontendModelHubContext');
let FrontendModelHubImpl = class FrontendModelHubImpl {
constructor() {
this.disposed = false;
}
initialize() {
this.doInitialize().catch((reason) => this.logger.error('Failed to initialize FrontendModelHub.', reason));
}
async doInitialize() {
// Self-subscribe to learn of disposal
const sub = await this.subscriber.subscribe(this.context);
sub.onModelHubDisposed = () => (this.disposed = true);
}
//
// Model Hub protocol
//
get isDisposed() {
return this.disposed;
}
async subscribe(...modelIds) {
const subscription = this.subscriber.subscribe(this.context, ...modelIds);
return subscription;
}
//
// Model Accessor Bus getter
//
getModelAccessorBus() {
this.modelAccessorBus.setContext(this.context);
return this.modelAccessorBus;
}
//
// Model Hub protocol by simple delegation
//
async getModel(modelId) {
return this.subscriber.getModel(this.context, modelId);
}
validateModels(...modelIds) {
return this.delegate.validateModels(this.context, ...modelIds);
}
getValidationState(...modelIds) {
return this.delegate.getValidationState(this.context, ...modelIds);
}
save(...commandStackIds) {
return this.delegate.save(this.context, ...commandStackIds);
}
isDirty(commandStackId) {
return this.delegate.isDirty(this.context, commandStackId);
}
undo(commandStackId) {
return this.delegate.undo(this.context, commandStackId);
}
redo(commandStackId) {
return this.delegate.redo(this.context, commandStackId);
}
flush(commandStackId) {
return this.delegate.flush(this.context, commandStackId);
}
};
exports.FrontendModelHubImpl = FrontendModelHubImpl;
__decorate([
(0, inversify_1.inject)(exports.FrontendModelHubContext),
__metadata("design:type", String)
], FrontendModelHubImpl.prototype, "context", void 0);
__decorate([
(0, inversify_1.inject)(common_1.ModelHubProtocol),
__metadata("design:type", Object)
], FrontendModelHubImpl.prototype, "delegate", void 0);
__decorate([
(0, inversify_1.inject)(frontend_model_hub_subscriber_1.FrontendModelHubSubscriber),
__metadata("design:type", Object)
], FrontendModelHubImpl.prototype, "subscriber", void 0);
__decorate([
(0, inversify_1.inject)(frontend_model_accessor_bus_1.FrontendModelAccessorBus),
__metadata("design:type", frontend_model_accessor_bus_1.FrontendModelAccessorBusImpl)
], FrontendModelHubImpl.prototype, "modelAccessorBus", void 0);
__decorate([
(0, inversify_1.inject)(core_1.ILogger),
__metadata("design:type", Object)
], FrontendModelHubImpl.prototype, "logger", void 0);
__decorate([
(0, inversify_1.postConstruct)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], FrontendModelHubImpl.prototype, "initialize", null);
exports.FrontendModelHubImpl = FrontendModelHubImpl = __decorate([
(0, inversify_1.injectable)()
], FrontendModelHubImpl);
//# sourceMappingURL=frontend-model-hub.js.map