@pixi/extensions
Advanced tools
Comparing version 7.1.0-alpha to 7.1.0
@@ -99,7 +99,8 @@ /** | ||
* @param list - The list of extensions. | ||
* @param defaultPriority - The default priority to use if none is specified. | ||
* @returns {PIXI.extensions} For chaining. | ||
*/ | ||
handleByList(type: ExtensionType, list: any[]): any; | ||
handleByList(type: ExtensionType, list: any[], defaultPriority?: number): any; | ||
}; | ||
export { extensions, ExtensionType, }; | ||
export type { ExtensionHandler, ExtensionMetadata, ExtensionFormatLoose, ExtensionFormat, }; | ||
export type { ExtensionFormat, ExtensionFormatLoose, ExtensionHandler, ExtensionMetadata, }; |
@@ -21,2 +21,5 @@ 'use strict'; | ||
if (typeof ext === "function" || typeof ext === "object" && ext.extension) { | ||
if (!ext.extension) { | ||
throw new Error("Extension class must have an extension object"); | ||
} | ||
const metadata = typeof ext.extension !== "object" ? { type: ext.extension } : ext.extension; | ||
@@ -35,2 +38,3 @@ ext = { ...metadata, ref: ext }; | ||
}; | ||
const normalizePriority = (ext, defaultPriority) => normalizeExtension(ext).priority ?? defaultPriority; | ||
const extensions = { | ||
@@ -64,2 +68,5 @@ _addHandlers: {}, | ||
const removeHandlers = this._removeHandlers; | ||
if (addHandlers[type] || removeHandlers[type]) { | ||
throw new Error(`Extension type ${type} already has a handler`); | ||
} | ||
addHandlers[type] = onAdd; | ||
@@ -81,3 +88,3 @@ removeHandlers[type] = onRemove; | ||
}, | ||
handleByList(type, list) { | ||
handleByList(type, list, defaultPriority = -1) { | ||
return this.handle(type, (extension) => { | ||
@@ -88,3 +95,3 @@ if (list.includes(extension.ref)) { | ||
list.push(extension.ref); | ||
list.sort((a, b) => (b.priority ?? -1) - (a.priority ?? -1)); | ||
list.sort((a, b) => normalizePriority(b, defaultPriority) - normalizePriority(a, defaultPriority)); | ||
}, (extension) => { | ||
@@ -91,0 +98,0 @@ const index = list.indexOf(extension.ref); |
{ | ||
"name": "@pixi/extensions", | ||
"version": "7.1.0-alpha", | ||
"version": "7.1.0", | ||
"main": "lib/index.js", | ||
@@ -22,7 +22,7 @@ "module": "lib/index.mjs", | ||
"homepage": "http://pixijs.com/", | ||
"bugs": "https://github.com/pixijs/pixi.js/issues", | ||
"bugs": "https://github.com/pixijs/pixijs/issues", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/pixijs/pixi.js.git" | ||
"url": "https://github.com/pixijs/pixijs.git" | ||
}, | ||
@@ -36,3 +36,3 @@ "publishConfig": { | ||
], | ||
"gitHead": "0fb26a500c738cb550da277c112d15d9dd3f87b6" | ||
"gitHead": "4079e92895ecb692afe9f0b15d3e48ee40852ada" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
37221
302
0