monaco-editor-core
Version:
A browser based code editor
62 lines • 2.8 kB
JavaScript
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 __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { isHotReloadEnabled } from '../../../base/common/hotReload.js';
import { autorunWithStore } from '../../../base/common/observable.js';
import { IInstantiationService } from '../../instantiation/common/instantiation.js';
export function hotClassGetOriginalInstance(value) {
if (value instanceof BaseClass) {
// eslint-disable-next-line local/code-no-any-casts
return value._instance;
}
return value;
}
class BaseClass {
constructor(instantiationService) {
this.instantiationService = instantiationService;
}
init(...params) { }
}
function createWrapper(clazz, B) {
// eslint-disable-next-line local/code-no-any-casts
return (class ReloadableWrapper extends B {
constructor() {
super(...arguments);
this._autorun = undefined;
}
init(...params) {
this._autorun = autorunWithStore((reader, store) => {
const clazz_ = clazz.read(reader);
this._instance = store.add(this.instantiationService.createInstance(clazz_, ...params));
});
}
dispose() {
this._autorun?.dispose();
}
});
}
/**
* Wrap a class in a reloadable wrapper.
* When the wrapper is created, the original class is created.
* When the original class changes, the instance is re-created.
*/
export function wrapInHotClass1(clazz) {
return !isHotReloadEnabled() ? clazz.get() : createWrapper(clazz, BaseClass1);
}
let BaseClass1 = class BaseClass1 extends BaseClass {
constructor(param1, i) { super(i); this.init(param1); }
};
BaseClass1 = __decorate([
__param(1, IInstantiationService)
], BaseClass1);
//# sourceMappingURL=wrapInHotClass.js.map