Comparing version 2.5.2 to 2.5.12
@@ -15,3 +15,2 @@ 'use strict'; | ||
exports.abstractMethod = abstractMethod; | ||
exports.collectSuperClassesProperty = collectSuperClassesProperty; | ||
exports.disableCompatibilityMode = disableCompatibilityMode; | ||
@@ -21,2 +20,3 @@ exports.enableCompatibilityMode = enableCompatibilityMode; | ||
exports.getFunctionName = getFunctionName; | ||
exports.getStaticProperty = getStaticProperty; | ||
exports.getUid = getUid; | ||
@@ -36,3 +36,2 @@ exports.identityFunction = identityFunction; | ||
exports.isString = isString; | ||
exports.mergeSuperClassesProperty = mergeSuperClassesProperty; | ||
exports.nullFunction = nullFunction; | ||
@@ -70,20 +69,2 @@ var compatibilityModeData_ = void 0; | ||
/** | ||
* Loops constructor super classes collecting its properties values. If | ||
* property is not available on the super class `undefined` will be | ||
* collected as value for the class hierarchy position. | ||
* @param {!function()} constructor Class constructor. | ||
* @param {string} propertyName Property name to be collected. | ||
* @return {Array.<*>} Array of collected values. | ||
* TODO(*): Rethink superclass loop. | ||
*/ | ||
function collectSuperClassesProperty(constructor, propertyName) { | ||
var propertyValues = [constructor[propertyName]]; | ||
while (constructor.__proto__ && !constructor.__proto__.isPrototypeOf(Function)) { | ||
constructor = constructor.__proto__; | ||
propertyValues.push(constructor[propertyName]); | ||
} | ||
return propertyValues; | ||
} | ||
/** | ||
* Disables Metal.js's compatibility mode. | ||
@@ -133,2 +114,13 @@ */ | ||
/** | ||
* Returns the first argument if it's truthy, or the second otherwise. | ||
* @param {*} a | ||
* @param {*} b | ||
* @return {*} | ||
* @protected | ||
*/ | ||
function getFirstTruthy_(a, b) { | ||
return a || b; | ||
} | ||
/** | ||
* Gets the name of the given function. If the current browser doesn't | ||
@@ -149,2 +141,29 @@ * support the `name` property, this will calculate it from the function's | ||
/** | ||
* Gets the value of a static property in the given class. The value will be | ||
* inherited from ancestors as expected, unless a custom merge function is given, | ||
* which can change how the super classes' value for that property will be merged | ||
* together. | ||
* The final merged value will be stored in another property, so that it won't | ||
* be recalculated even if this function is called multiple times. | ||
* @param {!function()} ctor Class constructor. | ||
* @param {string} propertyName Property name to be merged. | ||
* @param {function(*, *):*=} opt_mergeFn Function that receives the merged | ||
* value of the property so far and the next value to be merged to it. | ||
* Should return these two merged together. If not passed the final property | ||
* will be the first truthy value among ancestors. | ||
*/ | ||
function getStaticProperty(ctor, propertyName, opt_mergeFn) { | ||
var mergedName = propertyName + '_MERGED'; | ||
if (!ctor.hasOwnProperty(mergedName)) { | ||
var merged = ctor.hasOwnProperty(propertyName) ? ctor[propertyName] : null; | ||
if (ctor.__proto__ && !ctor.__proto__.isPrototypeOf(Function)) { | ||
var mergeFn = opt_mergeFn || getFirstTruthy_; | ||
merged = mergeFn(merged, getStaticProperty(ctor.__proto__, propertyName, mergeFn)); | ||
} | ||
ctor[mergedName] = merged; | ||
} | ||
return ctor[mergedName]; | ||
} | ||
/** | ||
* Gets an unique id. If `opt_object` argument is passed, the object is | ||
@@ -291,28 +310,2 @@ * mutated with an unique id. Consecutive calls with the same object | ||
/** | ||
* Merges the values of a export function property a class with the values of that | ||
* property for all its super classes, and stores it as a new static | ||
* property of that class. If the export function property already existed, it won't | ||
* be recalculated. | ||
* @param {!function()} constructor Class constructor. | ||
* @param {string} propertyName Property name to be collected. | ||
* @param {function(*, *):*=} opt_mergeFn Function that receives an array filled | ||
* with the values of the property for the current class and all its super classes. | ||
* Should return the merged value to be stored on the current class. | ||
* @return {boolean} Returns true if merge happens, false otherwise. | ||
*/ | ||
function mergeSuperClassesProperty(constructor, propertyName, opt_mergeFn) { | ||
var mergedName = propertyName + '_MERGED'; | ||
if (constructor.hasOwnProperty(mergedName)) { | ||
return false; | ||
} | ||
var merged = collectSuperClassesProperty(constructor, propertyName); | ||
if (opt_mergeFn) { | ||
merged = opt_mergeFn(merged); | ||
} | ||
constructor[mergedName] = merged; | ||
return true; | ||
} | ||
/** | ||
* Null function used for default values of callbacks, etc. | ||
@@ -319,0 +312,0 @@ * @return {void} Nothing. |
{ | ||
"name": "metal", | ||
"version": "2.5.2", | ||
"version": "2.5.12", | ||
"description": "Core functions from Metal.js, with utilities for dealing with arrays, objects and others.", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
@@ -39,20 +39,2 @@ 'use strict'; | ||
/** | ||
* Loops constructor super classes collecting its properties values. If | ||
* property is not available on the super class `undefined` will be | ||
* collected as value for the class hierarchy position. | ||
* @param {!function()} constructor Class constructor. | ||
* @param {string} propertyName Property name to be collected. | ||
* @return {Array.<*>} Array of collected values. | ||
* TODO(*): Rethink superclass loop. | ||
*/ | ||
export function collectSuperClassesProperty(constructor, propertyName) { | ||
var propertyValues = [constructor[propertyName]]; | ||
while (constructor.__proto__ && !constructor.__proto__.isPrototypeOf(Function)) { | ||
constructor = constructor.__proto__; | ||
propertyValues.push(constructor[propertyName]); | ||
} | ||
return propertyValues; | ||
} | ||
/** | ||
* Disables Metal.js's compatibility mode. | ||
@@ -100,2 +82,13 @@ */ | ||
/** | ||
* Returns the first argument if it's truthy, or the second otherwise. | ||
* @param {*} a | ||
* @param {*} b | ||
* @return {*} | ||
* @protected | ||
*/ | ||
function getFirstTruthy_(a, b) { | ||
return a || b; | ||
} | ||
/** | ||
* Gets the name of the given function. If the current browser doesn't | ||
@@ -116,2 +109,32 @@ * support the `name` property, this will calculate it from the function's | ||
/** | ||
* Gets the value of a static property in the given class. The value will be | ||
* inherited from ancestors as expected, unless a custom merge function is given, | ||
* which can change how the super classes' value for that property will be merged | ||
* together. | ||
* The final merged value will be stored in another property, so that it won't | ||
* be recalculated even if this function is called multiple times. | ||
* @param {!function()} ctor Class constructor. | ||
* @param {string} propertyName Property name to be merged. | ||
* @param {function(*, *):*=} opt_mergeFn Function that receives the merged | ||
* value of the property so far and the next value to be merged to it. | ||
* Should return these two merged together. If not passed the final property | ||
* will be the first truthy value among ancestors. | ||
*/ | ||
export function getStaticProperty(ctor, propertyName, opt_mergeFn) { | ||
var mergedName = propertyName + '_MERGED'; | ||
if (!ctor.hasOwnProperty(mergedName)) { | ||
let merged = ctor.hasOwnProperty(propertyName) ? ctor[propertyName] : null; | ||
if (ctor.__proto__ && !ctor.__proto__.isPrototypeOf(Function)) { | ||
const mergeFn = opt_mergeFn || getFirstTruthy_; | ||
merged = mergeFn( | ||
merged, | ||
getStaticProperty(ctor.__proto__, propertyName, mergeFn) | ||
); | ||
} | ||
ctor[mergedName] = merged; | ||
} | ||
return ctor[mergedName]; | ||
} | ||
/** | ||
* Gets an unique id. If `opt_object` argument is passed, the object is | ||
@@ -258,28 +281,2 @@ * mutated with an unique id. Consecutive calls with the same object | ||
/** | ||
* Merges the values of a export function property a class with the values of that | ||
* property for all its super classes, and stores it as a new static | ||
* property of that class. If the export function property already existed, it won't | ||
* be recalculated. | ||
* @param {!function()} constructor Class constructor. | ||
* @param {string} propertyName Property name to be collected. | ||
* @param {function(*, *):*=} opt_mergeFn Function that receives an array filled | ||
* with the values of the property for the current class and all its super classes. | ||
* Should return the merged value to be stored on the current class. | ||
* @return {boolean} Returns true if merge happens, false otherwise. | ||
*/ | ||
export function mergeSuperClassesProperty(constructor, propertyName, opt_mergeFn) { | ||
var mergedName = propertyName + '_MERGED'; | ||
if (constructor.hasOwnProperty(mergedName)) { | ||
return false; | ||
} | ||
var merged = collectSuperClassesProperty(constructor, propertyName); | ||
if (opt_mergeFn) { | ||
merged = opt_mergeFn(merged); | ||
} | ||
constructor[mergedName] = merged; | ||
return true; | ||
} | ||
/** | ||
* Null function used for default values of callbacks, etc. | ||
@@ -286,0 +283,0 @@ * @return {void} Nothing. |
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
58122
1687