UNPKG

monaco-editor-core

Version:

A browser based code editor

55 lines (54 loc) 2.6 kB
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 { readHotReloadableExport } from '../../../base/common/hotReloadHelpers.js'; import { autorunWithStore } from '../../../base/common/observable.js'; import { IInstantiationService } from '../../instantiation/common/instantiation.js'; class BaseClass { constructor(instantiationService) { this.instantiationService = instantiationService; } init(...params) { } } function createWrapper(getClass, B) { return (class ReloadableWrapper extends B { constructor() { super(...arguments); this._autorun = undefined; } init(...params) { this._autorun = autorunWithStore((reader, store) => { const clazz = readHotReloadableExport(getClass(), reader); 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 wrapInReloadableClass1(getClass) { return !isHotReloadEnabled() ? getClass() : createWrapper(getClass, BaseClass1); } let BaseClass1 = class BaseClass1 extends BaseClass { constructor(param1, i) { super(i); this.init(param1); } }; BaseClass1 = __decorate([ __param(1, IInstantiationService) ], BaseClass1);