only import required underscore functions

this requires updating the library
This commit is contained in:
Leo McArdle 2021-10-28 14:05:12 +01:00 коммит произвёл Leo McArdle
Родитель 4ecb30b8ea
Коммит f18c0e9c4d
16 изменённых файлов: 56 добавлений и 36 удалений

Просмотреть файл

@ -1,3 +1,5 @@
import _filter from "underscore/modules/filter";
/* jshint esnext: true */
export default class Chart {
@ -129,7 +131,7 @@ export default class Chart {
populateData(filter) {
let self = this;
let kindFilter = filter;
let filteredData = _.filter(this.data, function(datum, index) {
let filteredData = _filter(this.data, function(datum, index) {
return datum.kind === kindFilter;
});

Просмотреть файл

@ -1,4 +1,8 @@
import Chart from './components/Chart.es6';
import _each from "underscore/modules/each";
import _range from "underscore/modules/range";
import _uniq from "underscore/modules/uniq";
import _pluck from "underscore/modules/pluck";
let chartSetups = {
'retention': {
@ -7,7 +11,7 @@ let chartSetups = {
xAxis: {
labels() {
let labelsArray = [];
_.each(_.range(1, 13), function(val) {
_each(_range(1, 13), function(val) {
labelsArray.push(gettext('Week') + ' ' + val);
});
return labelsArray;
@ -254,7 +258,7 @@ function makeRetentionChart(settings) {
fetchDataset.done(data => {
retentionChart.data = data;
retentionChart.axes.yAxis.labels = _.uniq(_.pluck(data, 'start'));
retentionChart.axes.yAxis.labels = _uniq(_pluck(data, 'start'));
retentionChart.setupAxis('yAxis');
retentionChart.populateData(defaultContributorType);

Просмотреть файл

@ -1,3 +1,5 @@
import _reduce from "underscore/modules/reduce";
/* Detect the set of OSes and browsers we care about in the wiki and AAQ.
* Adapted from http://www.quirksmode.org/js/detect.html with these changes:
*
@ -44,7 +46,7 @@ var BrowserDetect = window.BrowserDetect = {
this.versionSearchString = data[i].versionSearch || data[i].identity;
// Check if all subStrings are in the dataString.
matchedAll = _.reduce(data[i].subStrings, function(memo, sub) {
matchedAll = _reduce(data[i].subStrings, function(memo, sub) {
if (sub instanceof RegExp) {
return memo && sub.exec(dataString);
} else {

Просмотреть файл

@ -1,3 +1,6 @@
import _each from "underscore/modules/each";
import _reduce from "underscore/modules/reduce";
/*
* Wrapper around diff_match_patch. or something like that.
*/
@ -53,7 +56,7 @@
var toContinued = false;
var line, fromLine, toLine, sectionLines, i, l, op, data, text;
_.each(self.rawDiffs, function(diff) {
_each(self.rawDiffs, function(diff) {
op = diff[0]; // Operation (insert, delete, equal)
data = diff[1]; // Text of change.
text = data
@ -184,9 +187,9 @@
html.push('<table><tbody>');
_.each(self.lineDiffs, function(line) {
_each(self.lineDiffs, function(line) {
// Check if the line has non-whitespace changes.
line.changes = _.reduce(line.parts, function(memo, part) {
line.changes = _reduce(line.parts, function(memo, part) {
return memo || (((part[0] === DIFF_DELETE) || (part[0] === DIFF_INSERT)) && part[1].length > 0);
}, false);
@ -227,7 +230,7 @@
html.push('<td class="num">', line.toLineNum, '</td>');
html.push('<td class="mark"></td>');
html.push('<td>');
_.each(line.parts, function(part) {
_each(line.parts, function(part) {
op = part[0];
if (op === DIFF_INSERT) {
html.push('<ins>' + part[1] + '</ins>');
@ -248,7 +251,7 @@
html.push('<td class="num"></td>');
html.push('<td class="mark">-</td>');
html.push('<td>');
_.each(line.parts, function(part) {
_each(line.parts, function(part) {
op = part[0];
if (op === DIFF_DELETE) {
html.push('<del>' + part[1] + '</del>');
@ -267,7 +270,7 @@
html.push('<td class="num">', line.toLineNum, '</td>');
html.push('<td class="mark">+</td>');
html.push('<td>');
_.each(line.parts, function(part) {
_each(line.parts, function(part) {
op = part[0];
if (op === DIFF_INSERT) {
html.push('<ins>' + part[1] + '</ins>');

Просмотреть файл

@ -1,5 +1,6 @@
import "sumo/js/libs/jquery.cookie";
import "sumo/js/libs/jquery.placeholder";
import _each from "underscore/modules/each";
// Use a global k to share data accross JS files
window.k = window.k || {};
@ -36,7 +37,7 @@ window.k = window.k || {};
k.queryParamStringFromDict = function(obj) {
var qs = '';
_.forEach(obj, function(value, key) {
_each(obj, function(value, key) {
if (value === undefined || value === null) {
return;
}

Просмотреть файл

@ -1,5 +1,6 @@
import questionmarkIcon from "sumo/img/questions/icon.questionmark.png";
import "sumo/js/libs/jquery.cookie";
import _throttle from "underscore/modules/throttle";
/*
* questions.js
@ -63,7 +64,7 @@ import "sumo/js/libs/jquery.cookie";
}
}
$('#id_content').on('keyup', _.throttle(takeQuestion, 60000));
$('#id_content').on('keyup', _throttle(takeQuestion, 60000));
$(document).on('click', '#details-edit', function(ev) {
ev.preventDefault();

Просмотреть файл

@ -1,5 +1,8 @@
import "jquery-ui/ui/widgets/datepicker";
import "jquery-ui/ui/widgets/slider";
import _filter from "underscore/modules/filter";
import _map from "underscore/modules/map";
import _each from "underscore/modules/each";
(function () {
'use strict';
@ -165,7 +168,7 @@ import "jquery-ui/ui/widgets/slider";
// Get midnight of today (ie, the boundary between today and yesterday)
chopLimit = new Date(now.getFullYear(), now.getMonth(), now.getDate());
}
bucketed = _.filter(bucketed, function (datum) {
bucketed = _filter(bucketed, function (datum) {
return datum.date < chopLimit / 1000;
});
@ -198,7 +201,7 @@ import "jquery-ui/ui/widgets/slider";
for (i = 0; i < this.data.series.length; i += 1) {
series = this.data.series[i];
axisGroup = this.axisGroups[series.axisGroup];
series.data = _.map(series.data, mapHandler);
series.data = _map(series.data, mapHandler);
series.scale = axisGroup.max;
axis = this.d3.axises[series.axisGroup];
if (axis) {
@ -268,7 +271,7 @@ import "jquery-ui/ui/widgets/slider";
max = -Infinity;
desc = descriptors[i];
data = _.map(objects, mapHandler);
data = _map(objects, mapHandler);
if (max <= 0 || isNaN(max) || !isFinite(max)) {
max = 1;
@ -815,7 +818,7 @@ import "jquery-ui/ui/widgets/slider";
var allKeys = Array.prototype.slice.call(arguments);
return function (d) {
var sum = 0;
_.each(allKeys, function (key) {
_each(allKeys, function (key) {
sum += d[key];
});
return d[partKey] / sum;

Просмотреть файл

@ -1,4 +1,6 @@
import "jquery-ui/ui/widgets/autocomplete";
import _each from "underscore/modules/each";
import _keys from "underscore/modules/keys";
/*
* A tag filtering form.
@ -18,7 +20,7 @@ import "jquery-ui/ui/widgets/autocomplete";
}
// Create a lower case vocab for case insensitive match.
_.each(_.keys(vocab), function(name) {
_each(_keys(vocab), function(name) {
lowerVocab[name.toLowerCase()] = vocab[name];
});
@ -41,7 +43,7 @@ import "jquery-ui/ui/widgets/autocomplete";
// Skip if the autocomplete plugin isn't available (unit tests).
if ($tags.autocomplete) {
$tags.autocomplete({
source: _.keys(vocab),
source: _keys(vocab),
delay: 0,
minLength: 1
});
@ -56,7 +58,7 @@ import "jquery-ui/ui/widgets/autocomplete";
invalid = false;
// For each tag name, find the slug.
_.each(tagNames.split(','), function(tag) {
_each(tagNames.split(','), function(tag) {
var trimmed = $.trim(tag),
slug = lowerVocab[trimmed.toLowerCase()];
if (slug) {

Просмотреть файл

@ -1,4 +1,5 @@
import "jquery-ui/ui/widgets/autocomplete";
import _keys from "underscore/modules/keys";
/*
* tags.js
@ -22,7 +23,7 @@ import "jquery-ui/ui/widgets/autocomplete";
function() {
var $tagContainer = $(this);
var parsedVocab = $tagContainer.data('tag-vocab-json');
$tagContainer.data('tagVocab', _.keys(parsedVocab));
$tagContainer.data('tagVocab', _keys(parsedVocab));
}
);
}

Просмотреть файл

@ -1,4 +1,5 @@
import "jquery-ui/ui/widgets/datepicker";
import _throttle from "underscore/modules/throttle";
(function($) {
'use strict';
@ -17,7 +18,7 @@ import "jquery-ui/ui/widgets/datepicker";
}
});
$(window).scroll(_.throttle(function() {
$(window).scroll(_throttle(function() {
if ($(window).scrollTop() > $('body > header').outerHeight()) {
$('body').addClass('scroll-header');
} else {

Просмотреть файл

@ -1,4 +1,7 @@
import "jquery-ui/ui/widgets/datepicker";
import _values from "underscore/modules/values";
import _each from "underscore/modules/each";
import _map from "underscore/modules/map";
/*
* kb dashboard chart
@ -125,7 +128,7 @@ import "jquery-ui/ui/widgets/datepicker";
],
'mini',
true,
_.values(l10nByDate)
_values(l10nByDate)
);
}
@ -140,7 +143,7 @@ import "jquery-ui/ui/widgets/datepicker";
],
false,
false,
_.values(contributorsByDate)
_values(contributorsByDate)
);
});
@ -226,10 +229,10 @@ import "jquery-ui/ui/widgets/datepicker";
}
// Create the graphs.
_.each(graphConfigs, function (config) {
_each(graphConfigs, function (config) {
graphs.push(makeWikiMetricGraph(
$(config.selector),
_.map(locales, function (locale) {
_map(locales, function (locale) {
return {
name: locale,
slug: locale,
@ -238,20 +241,20 @@ import "jquery-ui/ui/widgets/datepicker";
}),
false,
false,
_.values(resultsByCode[config.code])
_values(resultsByCode[config.code])
));
});
var updateGraphLocales = function() {
// Update the locale series based on the selected locales.
var selectedLocales = _.map($('#locale-picker :checked'), function (el) {
var selectedLocales = _map($('#locale-picker :checked'), function (el) {
return $(el).val();
});
// Loop through all the graphs...
_.each(graphs, function (graph) {
_each(graphs, function (graph) {
// And all the series (locales) in each graph...
_.each(graph.data.series, function (series, index) {
_each(graph.data.series, function (series, index) {
if (selectedLocales.indexOf(locales[index]) >= 0) {
// The locale is selected, show it.
series.disabled = false;

6
package-lock.json сгенерированный
Просмотреть файл

@ -19115,9 +19115,9 @@
}
},
"underscore": {
"version": "1.8.2",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.2.tgz",
"integrity": "sha1-ZN8utZCJnelQeC83NRkLpC6/MR0="
"version": "1.13.1",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz",
"integrity": "sha512-hzSoAVtJF+3ZtiFX0VgfFPHEDRm7Y/QPjGyNo4TVdnDTdft3tr8hEkD25a1jC+TjTuE7tkHGKkhwCgs9dgBB2g=="
},
"unherit": {
"version": "1.1.2",

Просмотреть файл

@ -49,7 +49,7 @@
"modernizr": "3.3.1",
"nunjucks": "^1.3.4",
"react": "0.13.3",
"underscore": "1.8.2"
"underscore": "^1.13.1"
},
"devDependencies": {
"@babel/cli": "^7.12.16",

Просмотреть файл

@ -2,7 +2,6 @@ const entrypoints = {
screen: ["sumo/scss/screen.scss"],
common: [
"sumo/js/i18n.js",
"underscore/underscore.js",
"sumo/js/templates/macros.js",
"sumo/js/templates/search-results-list.js",
"sumo/js/templates/search-results.js",

Просмотреть файл

@ -25,7 +25,6 @@ module.exports = {
],
"globals": {
// globals exposed in webpack/global-expose-rules.js
"_": "readonly",
"nunjucks": "readonly",
"CodeMirror": "readonly",
"Rickshaw": "readonly",

Просмотреть файл

@ -4,7 +4,6 @@
// we have to expose each of these variables manually:
module.exports = [
// expose these library exports globally:
expose("underscore/underscore.js", "_"),
expose("nunjucks/browser/nunjucks-slim.js", "nunjucks"),
expose("codemirror/lib/codemirror.js", "CodeMirror"),
expose("../kitsune/sumo/static/sumo/js/libs/rickshaw.js", "Rickshaw"),