client/general: reduce lodash usages
This commit is contained in:
parent
a32c5d1399
commit
bae238794a
3 changed files with 38 additions and 37 deletions
|
@ -1,6 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const lodash = require('lodash');
|
||||
const views = require('../util/views.js');
|
||||
|
||||
const KEY_TAB = 9;
|
||||
|
@ -27,7 +26,8 @@ function _getSelectionStart(input) {
|
|||
class AutoCompleteControl {
|
||||
constructor(sourceInputNode, options) {
|
||||
this._sourceInputNode = sourceInputNode;
|
||||
this._options = lodash.extend({}, {
|
||||
this._options = {};
|
||||
Object.assign(this._options, {
|
||||
verticalShift: 2,
|
||||
source: null,
|
||||
maxResults: 15,
|
||||
|
@ -202,7 +202,9 @@ class AutoCompleteControl {
|
|||
this._results =
|
||||
this._options.getMatches(textToFind)
|
||||
.slice(0, this._options.maxResults);
|
||||
if (!lodash.isEqual(oldResults, this._results)) {
|
||||
const oldResultsHash = JSON.stringify(oldResults);
|
||||
const newResultsHash = JSON.stringify(this._results);
|
||||
if (oldResultsHash !== newResultsHash) {
|
||||
this._activeResult = -1;
|
||||
}
|
||||
}
|
||||
|
@ -216,9 +218,7 @@ class AutoCompleteControl {
|
|||
while (this._suggestionList.firstChild) {
|
||||
this._suggestionList.removeChild(this._suggestionList.firstChild);
|
||||
}
|
||||
lodash.each(
|
||||
this._results,
|
||||
(resultItem, resultIndex) => {
|
||||
for (let [resultIndex, resultItem] of this._results.entries()) {
|
||||
const listItem = document.createElement('li');
|
||||
const link = document.createElement('a');
|
||||
link.href = '#';
|
||||
|
@ -241,7 +241,7 @@ class AutoCompleteControl {
|
|||
});
|
||||
listItem.appendChild(link);
|
||||
this._suggestionList.appendChild(listItem);
|
||||
});
|
||||
}
|
||||
this._refreshActiveResult();
|
||||
|
||||
// display the suggestions offscreen to get the height
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const unindent = require('../util/misc.js').unindent;
|
||||
const lodash = require('lodash');
|
||||
const tags = require('../tags.js');
|
||||
const AutoCompleteControl = require('./auto_complete_control.js');
|
||||
|
||||
|
@ -16,13 +15,15 @@ class TagAutoCompleteControl extends AutoCompleteControl {
|
|||
}
|
||||
|
||||
options.getMatches = text => {
|
||||
const regex = new RegExp(
|
||||
text.length < minLengthForPartialSearch ?
|
||||
'^' + lodash.escapeRegExp(text) :
|
||||
lodash.escapeRegExp(text),
|
||||
caseSensitive ? '' : 'i');
|
||||
const transform = caseSensitive ?
|
||||
x => x :
|
||||
x => x.toLowerCase();
|
||||
const match = text.length < minLengthForPartialSearch ?
|
||||
(a, b) => a.startsWith(b) :
|
||||
(a, b) => a.includes(b);
|
||||
text = transform(text);
|
||||
return Array.from(allTags.entries())
|
||||
.filter(kv => kv[0].match(regex))
|
||||
.filter(kv => match(transform(kv[0]), text))
|
||||
.sort((kv1, kv2) => {
|
||||
return kv2[1].usages - kv1[1].usages;
|
||||
})
|
||||
|
|
|
@ -243,7 +243,7 @@ function getTemplate(templatePath) {
|
|||
if (!ctx) {
|
||||
ctx = {};
|
||||
}
|
||||
lodash.extend(ctx, {
|
||||
Object.assign(ctx, {
|
||||
makeRelativeTime: makeRelativeTime,
|
||||
makeThumbnail: makeThumbnail,
|
||||
makeRadio: makeRadio,
|
||||
|
|
Loading…
Reference in a new issue