From 744dab5601ed0a4d639334aeb4af9e304f13b288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 16 Feb 2021 18:54:44 +0100 Subject: [PATCH] remove proxy --- packages/core/src/Editor.ts | 27 ++-------------- packages/core/src/utilities/magicMethods.ts | 34 --------------------- 2 files changed, 3 insertions(+), 58 deletions(-) delete mode 100644 packages/core/src/utilities/magicMethods.ts diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index e4b7ca7d..91c2a2c3 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -1,7 +1,6 @@ import { EditorState, Plugin, Transaction } from 'prosemirror-state' import { EditorView } from 'prosemirror-view' import { Schema, DOMParser, Node } from 'prosemirror-model' -import magicMethods from './utilities/magicMethods' import elementFromString from './utilities/elementFromString' import getNodeAttributes from './helpers/getNodeAttributes' import getMarkAttributes from './helpers/getMarkAttributes' @@ -29,11 +28,8 @@ export interface HTMLElement { editor?: Editor } -@magicMethods export class Editor extends EventEmitter { - private proxy!: Editor - private commandManager!: CommandManager public extensionManager!: ExtensionManager @@ -69,13 +65,6 @@ export class Editor extends EventEmitter { constructor(options: Partial = {}) { super() this.options = { ...this.options, ...options } - this.on('createdProxy', this.init) - } - - /** - * This method is called after the proxy is initialized. - */ - private init(): void { this.createExtensionManager() this.createCommandManager() this.createSchema() @@ -95,16 +84,6 @@ export class Editor extends EventEmitter { }, 0) } - /** - * A magic method to call commands. - * - * @param name The name of the command - */ - // eslint-disable-next-line - private __get(name: string) { - // TODO: maybe remove proxy - } - /** * An object of all registered commands. */ @@ -201,14 +180,14 @@ export class Editor extends EventEmitter { return ['extension', 'node', 'mark'].includes(extension?.type) }) - this.extensionManager = new ExtensionManager(allExtensions, this.proxy) + this.extensionManager = new ExtensionManager(allExtensions, this) } /** * Creates an command manager. */ private createCommandManager(): void { - this.commandManager = new CommandManager(this.proxy, this.extensionManager.commands) + this.commandManager = new CommandManager(this, this.extensionManager.commands) } /** @@ -243,7 +222,7 @@ export class Editor extends EventEmitter { // Let’s store the editor instance in the DOM element. // So we’ll have access to it for tests. const dom = this.view.dom as HTMLElement - dom.editor = this.proxy + dom.editor = this } /** diff --git a/packages/core/src/utilities/magicMethods.ts b/packages/core/src/utilities/magicMethods.ts deleted file mode 100644 index 7c5f790c..00000000 --- a/packages/core/src/utilities/magicMethods.ts +++ /dev/null @@ -1,34 +0,0 @@ -export default function magicMethods(Clazz: any): any { - const classHandler = Object.create(null) - - classHandler.construct = (_: any, args: any) => { - const instance = new Clazz(...args) - const instanceHandler = Object.create(null) - const get = Object.getOwnPropertyDescriptor(Clazz.prototype, '__get') - - if (get) { - instanceHandler.get = (target: any, name: any) => { - if (typeof name !== 'string') { - return - } - - const exists = name in target - || name.startsWith('_') - || ['then', 'catch'].includes(name) - - if (exists) { - return target[name] - } - - return get.value.call(target, name) - } - } - - instance.proxy = new Proxy(instance, instanceHandler) - instance.emit('createdProxy') - - return instance.proxy - } - - return new Proxy(Clazz, classHandler) -}