Merge pull request #6936 from epixa/uiletconst11
[internal] Replace var with const/let in ui/public/utils/lodash-mixins
This commit is contained in:
commit
176d271a20
|
@ -3,7 +3,7 @@ import expect from 'expect.js';
|
||||||
describe('_.move', function () {
|
describe('_.move', function () {
|
||||||
|
|
||||||
it('accepts previous from->to syntax', function () {
|
it('accepts previous from->to syntax', function () {
|
||||||
let list = [
|
const list = [
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
|
@ -27,7 +27,7 @@ describe('_.move', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('moves an object up based on a function callback', function () {
|
it('moves an object up based on a function callback', function () {
|
||||||
let list = [
|
const list = [
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
|
@ -55,7 +55,7 @@ describe('_.move', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('moves an object down based on a function callback', function () {
|
it('moves an object down based on a function callback', function () {
|
||||||
let list = [
|
const list = [
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
|
@ -83,7 +83,7 @@ describe('_.move', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('moves an object up based on a where callback', function () {
|
it('moves an object up based on a where callback', function () {
|
||||||
let list = [
|
const list = [
|
||||||
{ v: 1 },
|
{ v: 1 },
|
||||||
{ v: 1 },
|
{ v: 1 },
|
||||||
{ v: 1 },
|
{ v: 1 },
|
||||||
|
@ -110,7 +110,7 @@ describe('_.move', function () {
|
||||||
|
|
||||||
|
|
||||||
it('moves an object up based on a where callback', function () {
|
it('moves an object up based on a where callback', function () {
|
||||||
let list = [
|
const list = [
|
||||||
{ v: 1 },
|
{ v: 1 },
|
||||||
{ v: 1 },
|
{ v: 1 },
|
||||||
{ v: 1 },
|
{ v: 1 },
|
||||||
|
@ -136,7 +136,7 @@ describe('_.move', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('moves an object down based on a pluck callback', function () {
|
it('moves an object down based on a pluck callback', function () {
|
||||||
let list = [
|
const list = [
|
||||||
{ id: 0, normal: true },
|
{ id: 0, normal: true },
|
||||||
{ id: 1, normal: true },
|
{ id: 1, normal: true },
|
||||||
{ id: 2, normal: true },
|
{ id: 2, normal: true },
|
||||||
|
|
|
@ -3,7 +3,7 @@ import expect from 'expect.js';
|
||||||
describe('_.organize', function () {
|
describe('_.organize', function () {
|
||||||
|
|
||||||
it('it works', function () {
|
it('it works', function () {
|
||||||
let col = [
|
const col = [
|
||||||
{
|
{
|
||||||
name: 'one',
|
name: 'one',
|
||||||
roles: ['user', 'admin', 'owner']
|
roles: ['user', 'admin', 'owner']
|
||||||
|
@ -22,7 +22,7 @@ describe('_.organize', function () {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let resp = _.organizeBy(col, 'roles');
|
const resp = _.organizeBy(col, 'roles');
|
||||||
expect(resp).to.have.property('user');
|
expect(resp).to.have.property('user');
|
||||||
expect(resp.user).to.have.length(4);
|
expect(resp.user).to.have.length(4);
|
||||||
|
|
||||||
|
@ -34,15 +34,15 @@ describe('_.organize', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('behaves just like groupBy in normal scenarios', function () {
|
it('behaves just like groupBy in normal scenarios', function () {
|
||||||
let col = [
|
const col = [
|
||||||
{ name: 'one' },
|
{ name: 'one' },
|
||||||
{ name: 'two' },
|
{ name: 'two' },
|
||||||
{ name: 'three' },
|
{ name: 'three' },
|
||||||
{ name: 'four' }
|
{ name: 'four' }
|
||||||
];
|
];
|
||||||
|
|
||||||
let orgs = _.organizeBy(col, 'name');
|
const orgs = _.organizeBy(col, 'name');
|
||||||
let groups = _.groupBy(col, 'name');
|
const groups = _.groupBy(col, 'name');
|
||||||
expect(orgs).to.eql(groups);
|
expect(orgs).to.eql(groups);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,10 +3,10 @@ import expect from 'expect.js';
|
||||||
describe('_.pushAll', function () {
|
describe('_.pushAll', function () {
|
||||||
|
|
||||||
it('pushes an entire array into another', function () {
|
it('pushes an entire array into another', function () {
|
||||||
let a = [1, 2, 3, 4];
|
const a = [1, 2, 3, 4];
|
||||||
let b = [5, 6, 7, 8];
|
const b = [5, 6, 7, 8];
|
||||||
|
|
||||||
let output = _.pushAll(b, a);
|
const output = _.pushAll(b, a);
|
||||||
expect(output).to.be(a);
|
expect(output).to.be(a);
|
||||||
expect(a).to.eql([1, 2, 3, 4, 5, 6, 7, 8]);
|
expect(a).to.eql([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||||
expect(b).to.eql([5, 6, 7, 8]);
|
expect(b).to.eql([5, 6, 7, 8]);
|
||||||
|
|
|
@ -15,7 +15,7 @@ export default function (_) {
|
||||||
* @return {array} - the objs argument
|
* @return {array} - the objs argument
|
||||||
*/
|
*/
|
||||||
move: function (objs, obj, below, qualifier) {
|
move: function (objs, obj, below, qualifier) {
|
||||||
var origI = _.isNumber(obj) ? obj : objs.indexOf(obj);
|
const origI = _.isNumber(obj) ? obj : objs.indexOf(obj);
|
||||||
if (origI === -1) return objs;
|
if (origI === -1) return objs;
|
||||||
|
|
||||||
if (_.isNumber(below)) {
|
if (_.isNumber(below)) {
|
||||||
|
@ -27,11 +27,11 @@ export default function (_) {
|
||||||
below = !!below;
|
below = !!below;
|
||||||
qualifier = _.callback(qualifier);
|
qualifier = _.callback(qualifier);
|
||||||
|
|
||||||
var above = !below;
|
const above = !below;
|
||||||
var finder = below ? _.findIndex : _.findLastIndex;
|
const finder = below ? _.findIndex : _.findLastIndex;
|
||||||
|
|
||||||
// find the index of the next/previous obj that meets the qualifications
|
// find the index of the next/previous obj that meets the qualifications
|
||||||
var targetI = finder(objs, function (otherAgg, otherI) {
|
const targetI = finder(objs, function (otherAgg, otherI) {
|
||||||
if (below && otherI <= origI) return;
|
if (below && otherI <= origI) return;
|
||||||
if (above && otherI >= origI) return;
|
if (above && otherI >= origI) return;
|
||||||
return !!qualifier(otherAgg, otherI);
|
return !!qualifier(otherAgg, otherI);
|
||||||
|
@ -58,8 +58,8 @@ export default function (_) {
|
||||||
* @return {object}
|
* @return {object}
|
||||||
*/
|
*/
|
||||||
organizeBy: function (collection, callback) {
|
organizeBy: function (collection, callback) {
|
||||||
var buckets = {};
|
const buckets = {};
|
||||||
var prop = typeof callback === 'function' ? false : callback;
|
const prop = typeof callback === 'function' ? false : callback;
|
||||||
|
|
||||||
function add(key, obj) {
|
function add(key, obj) {
|
||||||
if (!buckets[key]) buckets[key] = [];
|
if (!buckets[key]) buckets[key] = [];
|
||||||
|
@ -67,14 +67,14 @@ export default function (_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_.each(collection, function (obj) {
|
_.each(collection, function (obj) {
|
||||||
var keys = prop === false ? callback(obj) : obj[prop];
|
const keys = prop === false ? callback(obj) : obj[prop];
|
||||||
|
|
||||||
if (!_.isArray(keys)) {
|
if (!_.isArray(keys)) {
|
||||||
add(keys, obj);
|
add(keys, obj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var length = keys.length;
|
let length = keys.length;
|
||||||
while (length-- > 0) {
|
while (length-- > 0) {
|
||||||
add(keys[length], obj);
|
add(keys[length], obj);
|
||||||
}
|
}
|
||||||
|
@ -108,14 +108,14 @@ export default function (_) {
|
||||||
* @return {Array} dest
|
* @return {Array} dest
|
||||||
*/
|
*/
|
||||||
pushAll: function (source, dest) {
|
pushAll: function (source, dest) {
|
||||||
var start = dest.length;
|
const start = dest.length;
|
||||||
var adding = source.length;
|
const adding = source.length;
|
||||||
|
|
||||||
// allocate - http://goo.gl/e2i0S0
|
// allocate - http://goo.gl/e2i0S0
|
||||||
dest.length = start + adding;
|
dest.length = start + adding;
|
||||||
|
|
||||||
// fill sparse positions
|
// fill sparse positions
|
||||||
var i = -1;
|
let i = -1;
|
||||||
while (++i < adding) dest[start + i] = source[i];
|
while (++i < adding) dest[start + i] = source[i];
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
|
|
|
@ -13,11 +13,11 @@ export default function (_) {
|
||||||
* @return {Function} - the wrapper method
|
* @return {Function} - the wrapper method
|
||||||
*/
|
*/
|
||||||
onceWithCb: function (fn) {
|
onceWithCb: function (fn) {
|
||||||
var callbacks = [];
|
const callbacks = [];
|
||||||
|
|
||||||
// on initial flush, call the init function, but ensure
|
// on initial flush, call the init function, but ensure
|
||||||
// that it only happens once
|
// that it only happens once
|
||||||
var flush = _.once(function (cntx, args) {
|
let flush = _.once(function (cntx, args) {
|
||||||
args.push(function finishedOnce() {
|
args.push(function finishedOnce() {
|
||||||
// override flush to simply schedule an asynchronous clear
|
// override flush to simply schedule an asynchronous clear
|
||||||
flush = function () {
|
flush = function () {
|
||||||
|
@ -33,8 +33,8 @@ export default function (_) {
|
||||||
});
|
});
|
||||||
|
|
||||||
return function runOnceWithCb() {
|
return function runOnceWithCb() {
|
||||||
var args = [].slice.call(arguments, 0);
|
let args = [].slice.call(arguments, 0);
|
||||||
var cb = args[args.length - 1];
|
const cb = args[args.length - 1];
|
||||||
|
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
callbacks.push(cb);
|
callbacks.push(cb);
|
||||||
|
|
|
@ -18,8 +18,8 @@ export default function (_) {
|
||||||
* @return {object}
|
* @return {object}
|
||||||
*/
|
*/
|
||||||
flattenWith: function (dot, nestedObj, flattenArrays) {
|
flattenWith: function (dot, nestedObj, flattenArrays) {
|
||||||
var stack = []; // track key stack
|
const stack = []; // track key stack
|
||||||
var flatObj = {};
|
const flatObj = {};
|
||||||
|
|
||||||
(function flattenObj(obj) {
|
(function flattenObj(obj) {
|
||||||
_.keys(obj).forEach(function (key) {
|
_.keys(obj).forEach(function (key) {
|
||||||
|
|
|
@ -11,10 +11,10 @@ export default function (_) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var props = {
|
const props = {
|
||||||
inherits: describeConst(function (SuperClass) {
|
inherits: describeConst(function (SuperClass) {
|
||||||
|
|
||||||
var prototype = Object.create(SuperClass.prototype, {
|
const prototype = Object.create(SuperClass.prototype, {
|
||||||
constructor: describeConst(this),
|
constructor: describeConst(this),
|
||||||
superConstructor: describeConst(SuperClass)
|
superConstructor: describeConst(SuperClass)
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export default function (_) {
|
export default function (_) {
|
||||||
|
|
||||||
var DOT_PREFIX_RE = /(.).+?\./g;
|
const DOT_PREFIX_RE = /(.).+?\./g;
|
||||||
|
|
||||||
_.mixin({
|
_.mixin({
|
||||||
|
|
||||||
|
@ -39,10 +39,10 @@ export default function (_) {
|
||||||
commaSeperatedList: function (input) {
|
commaSeperatedList: function (input) {
|
||||||
if (_.isArray(input)) return input;
|
if (_.isArray(input)) return input;
|
||||||
|
|
||||||
var source = String(input || '').split(',');
|
const source = String(input || '').split(',');
|
||||||
var list = [];
|
const list = [];
|
||||||
while (source.length) {
|
while (source.length) {
|
||||||
var item = source.shift().trim();
|
const item = source.shift().trim();
|
||||||
if (item) list.push(item);
|
if (item) list.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue