Merge pull request #5162 from matrix-org/t3chguy/lodash

Consolidate Lodash files in bundle
This commit is contained in:
Michael Telatynski 2020-09-03 15:54:43 +01:00 committed by GitHub
commit 97ebfa02c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 20 additions and 22 deletions

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import commonmark from 'commonmark'; import commonmark from 'commonmark';
import escape from 'lodash/escape'; import {escape} from "lodash";
const ALLOWED_HTML_TAGS = ['sub', 'sup', 'del', 'u']; const ALLOWED_HTML_TAGS = ['sub', 'sup', 'del', 'u'];

View file

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import _clamp from 'lodash/clamp'; import {clamp} from "lodash";
export default class SendHistoryManager { export default class SendHistoryManager {
history: Array<HistoryItem> = []; history: Array<HistoryItem> = [];
@ -54,7 +54,7 @@ export default class SendHistoryManager {
} }
getItem(offset: number): ?HistoryItem { getItem(offset: number): ?HistoryItem {
this.currentIndex = _clamp(this.currentIndex + offset, 0, this.history.length - 1); this.currentIndex = clamp(this.currentIndex + offset, 0, this.history.length - 1);
return this.history[this.currentIndex]; return this.history[this.currentIndex];
} }
} }

View file

@ -23,7 +23,7 @@ import {MatrixClientPeg} from '../MatrixClientPeg';
import QueryMatcher from './QueryMatcher'; import QueryMatcher from './QueryMatcher';
import {PillCompletion} from './Components'; import {PillCompletion} from './Components';
import * as sdk from '../index'; import * as sdk from '../index';
import _sortBy from 'lodash/sortBy'; import {sortBy} from "lodash";
import {makeGroupPermalink} from "../utils/permalinks/Permalinks"; import {makeGroupPermalink} from "../utils/permalinks/Permalinks";
import {ICompletion, ISelectionRange} from "./Autocompleter"; import {ICompletion, ISelectionRange} from "./Autocompleter";
import FlairStore from "../stores/FlairStore"; import FlairStore from "../stores/FlairStore";
@ -81,7 +81,7 @@ export default class CommunityProvider extends AutocompleteProvider {
const matchedString = command[0]; const matchedString = command[0];
completions = this.matcher.match(matchedString); completions = this.matcher.match(matchedString);
completions = _sortBy(completions, [ completions = sortBy(completions, [
(c) => score(matchedString, c.groupId), (c) => score(matchedString, c.groupId),
(c) => c.groupId.length, (c) => c.groupId.length,
]).map(({avatarUrl, groupId, name}) => ({ ]).map(({avatarUrl, groupId, name}) => ({

View file

@ -23,8 +23,7 @@ import AutocompleteProvider from './AutocompleteProvider';
import QueryMatcher from './QueryMatcher'; import QueryMatcher from './QueryMatcher';
import {PillCompletion} from './Components'; import {PillCompletion} from './Components';
import {ICompletion, ISelectionRange} from './Autocompleter'; import {ICompletion, ISelectionRange} from './Autocompleter';
import _uniq from 'lodash/uniq'; import {uniq, sortBy} from 'lodash';
import _sortBy from 'lodash/sortBy';
import SettingsStore from "../settings/SettingsStore"; import SettingsStore from "../settings/SettingsStore";
import { shortcodeToUnicode } from '../HtmlUtils'; import { shortcodeToUnicode } from '../HtmlUtils';
import { EMOJI, IEmoji } from '../emoji'; import { EMOJI, IEmoji } from '../emoji';
@ -115,7 +114,7 @@ export default class EmojiProvider extends AutocompleteProvider {
} }
// Finally, sort by original ordering // Finally, sort by original ordering
sorters.push((c) => c._orderBy); sorters.push((c) => c._orderBy);
completions = _sortBy(_uniq(completions), sorters); completions = sortBy(uniq(completions), sorters);
completions = completions.map(({shortname}) => { completions = completions.map(({shortname}) => {
const unicode = shortcodeToUnicode(shortname); const unicode = shortcodeToUnicode(shortname);

View file

@ -16,8 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import _at from 'lodash/at'; import {at, uniq} from 'lodash';
import _uniq from 'lodash/uniq';
import {removeHiddenChars} from "matrix-js-sdk/src/utils"; import {removeHiddenChars} from "matrix-js-sdk/src/utils";
interface IOptions<T extends {}> { interface IOptions<T extends {}> {
@ -73,7 +72,7 @@ export default class QueryMatcher<T extends Object> {
// type for their values. We assume that those values who's keys have // type for their values. We assume that those values who's keys have
// been specified will be string. Also, we cannot infer all the // been specified will be string. Also, we cannot infer all the
// types of the keys of the objects at compile. // types of the keys of the objects at compile.
const keyValues = _at<string>(<any>object, this._options.keys); const keyValues = at<string>(<any>object, this._options.keys);
if (this._options.funcs) { if (this._options.funcs) {
for (const f of this._options.funcs) { for (const f of this._options.funcs) {
@ -137,7 +136,7 @@ export default class QueryMatcher<T extends Object> {
}); });
// Now map the keys to the result objects. Also remove any duplicates. // Now map the keys to the result objects. Also remove any duplicates.
return _uniq(matches.map((match) => match.object)); return uniq(matches.map((match) => match.object));
} }
private processQuery(query: string): string { private processQuery(query: string): string {

View file

@ -27,7 +27,7 @@ import {PillCompletion} from './Components';
import * as sdk from '../index'; import * as sdk from '../index';
import {makeRoomPermalink} from "../utils/permalinks/Permalinks"; import {makeRoomPermalink} from "../utils/permalinks/Permalinks";
import {ICompletion, ISelectionRange} from "./Autocompleter"; import {ICompletion, ISelectionRange} from "./Autocompleter";
import { uniqBy, sortBy } from 'lodash'; import {uniqBy, sortBy} from "lodash";
const ROOM_REGEX = /\B#\S*/g; const ROOM_REGEX = /\B#\S*/g;

View file

@ -23,7 +23,7 @@ import AutocompleteProvider from './AutocompleteProvider';
import {PillCompletion} from './Components'; import {PillCompletion} from './Components';
import * as sdk from '../index'; import * as sdk from '../index';
import QueryMatcher from './QueryMatcher'; import QueryMatcher from './QueryMatcher';
import _sortBy from 'lodash/sortBy'; import {sortBy} from 'lodash';
import {MatrixClientPeg} from '../MatrixClientPeg'; import {MatrixClientPeg} from '../MatrixClientPeg';
import MatrixEvent from "matrix-js-sdk/src/models/event"; import MatrixEvent from "matrix-js-sdk/src/models/event";
@ -156,7 +156,7 @@ export default class UserProvider extends AutocompleteProvider {
const currentUserId = MatrixClientPeg.get().credentials.userId; const currentUserId = MatrixClientPeg.get().credentials.userId;
this.users = this.room.getJoinedMembers().filter(({userId}) => userId !== currentUserId); this.users = this.room.getJoinedMembers().filter(({userId}) => userId !== currentUserId);
this.users = _sortBy(this.users, (member) => 1E20 - lastSpoken[member.userId] || 1E20); this.users = sortBy(this.users, (member) => 1E20 - lastSpoken[member.userId] || 1E20);
this.matcher.setObjects(this.users); this.matcher.setObjects(this.users);
} }

View file

@ -20,7 +20,7 @@ import createReactClass from 'create-react-class';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Key } from '../../Keyboard'; import { Key } from '../../Keyboard';
import dis from '../../dispatcher/dispatcher'; import dis from '../../dispatcher/dispatcher';
import { throttle } from 'lodash'; import {throttle} from 'lodash';
import AccessibleButton from '../../components/views/elements/AccessibleButton'; import AccessibleButton from '../../components/views/elements/AccessibleButton';
import classNames from 'classnames'; import classNames from 'classnames';

View file

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { debounce } from 'lodash'; import {debounce} from "lodash";
import classNames from 'classnames'; import classNames from 'classnames';
import React from 'react'; import React from 'react';
import PropTypes from "prop-types"; import PropTypes from "prop-types";

View file

@ -17,7 +17,7 @@ limitations under the License.
import React, {InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes} from 'react'; import React, {InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes} from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import * as sdk from '../../../index'; import * as sdk from '../../../index';
import { debounce } from 'lodash'; import {debounce} from "lodash";
import {IFieldState, IValidationResult} from "./Validation"; import {IFieldState, IValidationResult} from "./Validation";
// Invoke validation from user input (when typing, etc.) at most once every N ms. // Invoke validation from user input (when typing, etc.) at most once every N ms.

View file

@ -17,7 +17,7 @@ limitations under the License.
import React, {createRef, KeyboardEvent} from 'react'; import React, {createRef, KeyboardEvent} from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import flatMap from 'lodash/flatMap'; import {flatMap} from "lodash";
import {ICompletion, ISelectionRange, IProviderCompletions} from '../../../autocomplete/Autocompleter'; import {ICompletion, ISelectionRange, IProviderCompletions} from '../../../autocomplete/Autocompleter';
import {Room} from 'matrix-js-sdk/src/models/room'; import {Room} from 'matrix-js-sdk/src/models/room';

View file

@ -26,7 +26,7 @@ limitations under the License.
* on unmount or similar to cancel any pending update. * on unmount or similar to cancel any pending update.
*/ */
import { throttle } from "lodash"; import {throttle} from "lodash";
export default function ratelimitedfunc(fn, time) { export default function ratelimitedfunc(fn, time) {
const throttledFn = throttle(fn, time, { const throttledFn = throttle(fn, time, {

View file

@ -16,7 +16,7 @@ limitations under the License.
*/ */
import {MatrixClientPeg} from '../MatrixClientPeg'; import {MatrixClientPeg} from '../MatrixClientPeg';
import _uniq from 'lodash/uniq'; import {uniq} from "lodash";
import {Room} from "matrix-js-sdk/src/matrix"; import {Room} from "matrix-js-sdk/src/matrix";
/** /**
@ -111,7 +111,7 @@ export default class DMRoomMap {
userToRooms[userId] = [roomId]; userToRooms[userId] = [roomId];
} else { } else {
roomIds.push(roomId); roomIds.push(roomId);
userToRooms[userId] = _uniq(roomIds); userToRooms[userId] = uniq(roomIds);
} }
}); });
return true; return true;