Socket
Socket
Sign inDemoInstall

@open-wc/dedupe-mixin

Package Overview
Dependencies
0
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.18 to 1.3.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [1.3.0](https://github.com/open-wc/open-wc/compare/@open-wc/dedupe-mixin@1.2.18...@open-wc/dedupe-mixin@1.3.0) (2020-08-05)
### Features
* **dedupe-mixin:** improve performance by simplifying the code ([#1708](https://github.com/open-wc/open-wc/issues/1708)) ([0ac7fff](https://github.com/open-wc/open-wc/commit/0ac7fffe26fffb5bcd8dcf457b185774efb2d395))
## [1.2.18](https://github.com/open-wc/open-wc/compare/@open-wc/dedupe-mixin@1.2.17...@open-wc/dedupe-mixin@1.2.18) (2020-07-08)

@@ -8,0 +19,0 @@

4

package.json
{
"name": "@open-wc/dedupe-mixin",
"version": "1.2.18",
"version": "1.3.0",
"publishConfig": {

@@ -38,3 +38,3 @@ "access": "public"

"sideEffects": false,
"gitHead": "72c70d66fcc65b6395442a177a1a5220d261e8bf"
"gitHead": "ac212af3eef63c8cdb442a75e63428d9634309d9"
}
const appliedClassMixins = new WeakMap();
function getPrototypeChain(obj) {
const chain = [];
let proto = obj;
while (proto) {
chain.push(proto);
proto = Object.getPrototypeOf(proto);
}
return chain;
}
function wasApplied(mixin, superClass) {
const classes = getPrototypeChain(superClass);
for (const klass of classes) {
/** Vefify if the Mixin was previously applyed
* @private
* @param {function} mixin Mixin being applyed
* @param {object} superClass Class receiving the new mixin
* @returns {boolean}
*/
function wasMixinPreviouslyApplied(mixin, superClass) {
let klass = superClass;
while (klass) {
if (appliedClassMixins.get(klass) === mixin) {
return true;
}
klass = Object.getPrototypeOf(klass);
}

@@ -23,5 +20,10 @@ return false;

/** Apply each mixin in the chain to make sure they are not applied more than once to the final class.
* @export
* @param {function} mixin Mixin to be applyed
* @returns {object} Mixed class with mixin applied
*/
export function dedupeMixin(mixin) {
return superClass => {
if (wasApplied(mixin, superClass)) {
if (wasMixinPreviouslyApplied(mixin, superClass)) {
return superClass;

@@ -28,0 +30,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc