mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-05 07:54:04 +01:00
Move extend and inherits helpers in helpers.core.js (#4878)
Fix Rollup issue caused by early access of the `extend` and `inherits` helpers not yet part of the `helpers/index` import. Also added (basic) unit tests for whose methods.
This commit is contained in:
@@ -10,16 +10,6 @@ module.exports = function(Chart) {
|
||||
|
||||
// -- Basic js utility methods
|
||||
|
||||
helpers.extend = function(base) {
|
||||
var setFn = function(value, key) {
|
||||
base[key] = value;
|
||||
};
|
||||
for (var i = 1, ilen = arguments.length; i < ilen; i++) {
|
||||
helpers.each(arguments[i], setFn);
|
||||
}
|
||||
return base;
|
||||
};
|
||||
|
||||
helpers.configMerge = function(/* objects ... */) {
|
||||
return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
|
||||
merger: function(key, target, source, options) {
|
||||
@@ -125,29 +115,7 @@ module.exports = function(Chart) {
|
||||
}
|
||||
}
|
||||
};
|
||||
helpers.inherits = function(extensions) {
|
||||
// Basic javascript inheritance based on the model created in Backbone.js
|
||||
var me = this;
|
||||
var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
|
||||
return me.apply(this, arguments);
|
||||
};
|
||||
|
||||
var Surrogate = function() {
|
||||
this.constructor = ChartElement;
|
||||
};
|
||||
Surrogate.prototype = me.prototype;
|
||||
ChartElement.prototype = new Surrogate();
|
||||
|
||||
ChartElement.extend = helpers.inherits;
|
||||
|
||||
if (extensions) {
|
||||
helpers.extend(ChartElement.prototype, extensions);
|
||||
}
|
||||
|
||||
ChartElement.__super__ = me.prototype;
|
||||
|
||||
return ChartElement;
|
||||
};
|
||||
// -- Math methods
|
||||
helpers.isNumber = function(n) {
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
|
||||
@@ -250,6 +250,48 @@ var helpers = {
|
||||
*/
|
||||
mergeIf: function(target, source) {
|
||||
return helpers.merge(target, source, {merger: helpers._mergerIf});
|
||||
},
|
||||
|
||||
/**
|
||||
* Applies the contents of two or more objects together into the first object.
|
||||
* @param {Object} target - The target object in which all objects are merged into.
|
||||
* @param {Object} arg1 - Object containing additional properties to merge in target.
|
||||
* @param {Object} argN - Additional objects containing properties to merge in target.
|
||||
* @returns {Object} The `target` object.
|
||||
*/
|
||||
extend: function(target) {
|
||||
var setFn = function(value, key) {
|
||||
target[key] = value;
|
||||
};
|
||||
for (var i = 1, ilen = arguments.length; i < ilen; ++i) {
|
||||
helpers.each(arguments[i], setFn);
|
||||
}
|
||||
return target;
|
||||
},
|
||||
|
||||
/**
|
||||
* Basic javascript inheritance based on the model created in Backbone.js
|
||||
*/
|
||||
inherits: function(extensions) {
|
||||
var me = this;
|
||||
var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
|
||||
return me.apply(this, arguments);
|
||||
};
|
||||
|
||||
var Surrogate = function() {
|
||||
this.constructor = ChartElement;
|
||||
};
|
||||
|
||||
Surrogate.prototype = me.prototype;
|
||||
ChartElement.prototype = new Surrogate();
|
||||
ChartElement.extend = helpers.inherits;
|
||||
|
||||
if (extensions) {
|
||||
helpers.extend(ChartElement.prototype, extensions);
|
||||
}
|
||||
|
||||
ChartElement.__super__ = me.prototype;
|
||||
return ChartElement;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user