@supercharge/macroable
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -6,4 +6,4 @@ /** | ||
export interface MacroableCtor { | ||
macro<T extends typeof Macroable>(this: T, name: string, callback: MacroFn): T; | ||
flushMacros<T extends typeof Macroable>(this: T): T; | ||
macro<T extends MacroableCtor>(this: T, name: string, callback: MacroFn): T; | ||
flushMacros<T extends MacroableCtor>(this: T): T; | ||
hasMacro(name: string): boolean; | ||
@@ -28,3 +28,3 @@ } | ||
*/ | ||
static macro<T extends typeof Macroable>(this: T, name: string, callback: MacroFn): T; | ||
static macro<T extends MacroableCtor>(this: T, name: string, callback: MacroFn): T; | ||
/** | ||
@@ -56,4 +56,4 @@ * Ensures the given `name` and `callback` are valid macro values. | ||
*/ | ||
static flushMacros<T extends typeof Macroable>(this: T): T; | ||
static flushMacros<T extends MacroableCtor>(this: T): T; | ||
} | ||
export {}; |
@@ -18,6 +18,7 @@ 'use strict'; | ||
static macro(name, callback) { | ||
this.validateMacro(name, callback); | ||
const self = this; | ||
self.validateMacro(name, callback); | ||
// @ts-expect-error | ||
this.prototype[name] = callback; | ||
this.macros.set(name, callback); | ||
self.prototype[name] = callback; | ||
self.macros.set(name, callback); | ||
return this; | ||
@@ -63,6 +64,8 @@ } | ||
static flushMacros() { | ||
for (const key of this.macros.keys()) { | ||
const self = this; | ||
for (const key of self.macros.keys()) { | ||
// @ts-expect-error | ||
Reflect.deleteProperty(this.prototype, key); | ||
} | ||
this.macros = new Map(); | ||
self.macros = new Map(); | ||
return this; | ||
@@ -69,0 +72,0 @@ } |
{ | ||
"name": "@supercharge/macroable", | ||
"description": "An elegant way to extend the prototype of ES6 classes", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"author": "Marcus Pöhls <marcus@superchargejs.com>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8137
132