From 4bcb6417cf49270d680ea2b2d52a19fe6fc25836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Marie=20De=20Mey?= Date: Sun, 3 Nov 2024 07:37:11 +0200 Subject: [PATCH] - prototype-edt --- src/helpers.ts | 21 --------------------- test/utils.test.ts | 38 -------------------------------------- 2 files changed, 59 deletions(-) delete mode 100644 test/utils.test.ts diff --git a/src/helpers.ts b/src/helpers.ts index 29de7d4..0313e87 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -25,24 +25,3 @@ export function instanceOf(obj: any, ctor: Ctor) { if (base === ctor || base.prototype instanceof ctor) return true return false } - -type Method = ( - this: InstanceType, - ...args: Args -) => Return - -/** - * - * @param target - * @param factory - * @deprecated Not deprecated but incomplete - just pushed away with other changes : *unreliable!* - */ -export function overrideMethods( - target: Class, - factory: (source: InstanceType) => Record> -) { - Object.defineProperties( - target.prototype, - Object.getOwnPropertyDescriptors(factory(Object.getPrototypeOf(target.prototype))) - ) -} diff --git a/test/utils.test.ts b/test/utils.test.ts deleted file mode 100644 index 07c0a01..0000000 --- a/test/utils.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { overrideMethods } from '~/helpers' -import { log, logs } from './logger' - -beforeEach(() => { - logs() -}) -test('overrideMethods', () => { - class A { - method() { - log('A', 'method') - } - get value() { - return 42 - } - } - class B extends A { - method() { - log('B', 'method') - super.method() - } - get value() { - return 5 + super.value - } - } - const b = new B() - b.method() - expect(logs()).toEqual(['B method', 'A method']) - expect(b.value).toBe(47) - overrideMethods(B, (source) => ({ - method() { - log('B', 'modified method') - source.method() - } /* - get value() { - return 15 + source.value - }*/ - })) -})