@kieler/klighd-core
Version:
Core KLighD diagram visualization with Sprotty
61 lines • 2.63 kB
JavaScript
;
/*
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2021 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Registry = void 0;
const inversify_1 = require("inversify");
/**
* Abstract registry which should be used as a base for registries in the container.
* A registry is supposed to store extra state that is not the diagram model.
* Examples for such state include diagram options or preferences.
*
* The state should be readonly and can only be changed with an {@link Action}.
* This is similar to the flux architecture that is utilized by Sprotty, where a
* view dispatches actions, which can change the state, causing the view to react
* to the changed state and update. Therefore, every registry implements {@link IActionHandler}.
*
* Implementations define how their actions are handled and automatically
* provide a subscription options for listeners, by extending this base class.
* A handled action should call `notifyListeners` to inform them about state changes.
*
* A registry has to be bound to the actions it is supposed to handle in the DI container.
* Sprotty provides a `configureActionHandler` function to simplify this process.
*/
let Registry = class Registry {
constructor() {
this._listeners = [];
}
onChange(handler) {
this._listeners.push(handler);
}
notifyListeners() {
for (const listener of this._listeners) {
listener();
}
}
};
exports.Registry = Registry;
exports.Registry = Registry = __decorate([
(0, inversify_1.injectable)()
], Registry);
//# sourceMappingURL=registry.js.map