Skip to content

Commit

Permalink
get rid of util.inherit
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Oct 24, 2016
1 parent 79e40c9 commit 3995086
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
16 changes: 0 additions & 16 deletions js/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,6 @@ exports.extendAll = function (dest, src) {
return dest;
};

/**
* Extend a parent's prototype with all properties in a properties
* object.
*
* @param {Object} parent
* @param {Object} props
* @returns {Object}
* @private
*/
exports.inherit = function (parent, props) {
const parentProto = typeof parent === 'function' ? parent.prototype : parent,
proto = Object.create(parentProto);
exports.extendAll(proto, props);
return proto;
};

/**
* Given an object and a number of properties as strings, return version
* of that object with only those properties.
Expand Down
26 changes: 15 additions & 11 deletions test/js/source/source_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ const util = require('../../../js/util/util');
function MockSourceType(id, sourceOptions) {
// allow tests to override mocked methods/properties by providing
// them in the source definition object that's given to Source.create()
let source = util.extend({
id: id,
minzoom: 0,
maxzoom: 22,
loadTile: function (tile, callback) {
class SourceMock extends Evented {
constructor() {
super();
this.id = id;
this.minzoom = 0;
this.maxzoom = 22;
util.extend(this, sourceOptions);
}
loadTile(tile, callback) {
setTimeout(callback, 0);
},
abortTile: function () {},
unloadTile: function () {},
serialize: function () {}
}, sourceOptions);
source = util.inherit(Evented, source);
}
abortTile() {}
unloadTile() {}
serialize() {}
}
const source = new SourceMock();

if (sourceOptions.noLoad) { return source; }
setTimeout(() => {
Expand Down
15 changes: 0 additions & 15 deletions test/js/util/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ test('util', (t) => {
t.deepEqual(util.pick({a:1, b:2, c:3}, ['a', 'c', 'd']), {a:1, c:3}, 'pick');
t.ok(typeof util.uniqueId() === 'number', 'uniqueId');

t.test('inherit', (t) => {
function Inheritance() { }
Inheritance.prototype.foo = function() { return 42; };
function Child() {}
Child.prototype = util.inherit(Inheritance, {
bar: function() {
return 20;
}
});
const c = new Child();
t.equal(c.foo(), 42);
t.equal(c.bar(), 20);
t.end();
});

t.test('getCoordinatesCenter', (t) => {
t.deepEqual(util.getCoordinatesCenter(
[
Expand Down

0 comments on commit 3995086

Please sign in to comment.