Commit a7fc2585 authored by Tobias Spagert's avatar Tobias Spagert Committed by Paul Slaughter

Replace underscore functions with lodash equivalents in ./app/assets/javascripts/vue_shared

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25108
parent 1482aa4a
<script>
import _ from 'underscore';
import { isString, isEmpty } from 'lodash';
import { GlTooltipDirective, GlLink } from '@gitlab/ui';
import { __, sprintf } from '~/locale';
import TooltipOnTruncate from '~/vue_shared/components/tooltip_on_truncate.vue';
......@@ -56,7 +56,7 @@ export default {
required: false,
default: undefined,
validator: ref =>
_.isUndefined(ref) || (_.isFinite(ref.iid) && _.isString(ref.path) && !_.isEmpty(ref.path)),
ref === undefined || (Number.isFinite(ref.iid) && isString(ref.path) && !isEmpty(ref.path)),
},
/**
......
<script>
import _ from 'underscore';
import { throttle } from 'lodash';
import { numberToHumanSize } from '../../../../lib/utils/number_utils';
export default {
......@@ -48,7 +48,7 @@ export default {
mounted() {
// The onImgLoad may have happened before the control was actually mounted
this.onImgLoad();
this.resizeThrottled = _.throttle(this.onImgLoad, 400);
this.resizeThrottled = throttle(this.onImgLoad, 400);
window.addEventListener('resize', this.resizeThrottled, false);
},
methods: {
......
<script>
import _ from 'underscore';
import { throttle } from 'lodash';
import { pixeliseValue } from '../../../lib/utils/dom_utils';
import ImageViewer from '../../../content_viewer/viewers/image_viewer.vue';
......@@ -98,7 +98,7 @@ export default {
this.swipeOldImgInfo = imgInfo;
this.prepareSwipe();
},
resize: _.throttle(function throttledResize() {
resize: throttle(function throttledResize() {
this.swipeBarPos = 0;
this.swipeWrapWidth = 0;
this.prepareSwipe();
......
<script>
import { GlLink } from '@gitlab/ui';
import _ from 'underscore';
import { escape as esc } from 'lodash';
import { __, sprintf } from '~/locale';
import icon from '../../../vue_shared/components/icon.vue';
function buildDocsLinkStart(path) {
return `<a href="${_.escape(path)}" target="_blank" rel="noopener noreferrer">`;
return `<a href="${esc(path)}" target="_blank" rel="noopener noreferrer">`;
}
export default {
......
<script>
import $ from 'jquery';
import '~/behaviors/markdown/render_gfm';
import _ from 'underscore';
import { unescape as unesc } from 'lodash';
import { __, sprintf } from '~/locale';
import { stripHtml } from '~/lib/utils/text_utility';
import Flash from '../../../flash';
......@@ -115,7 +115,7 @@ export default {
return text;
}
return _.unescape(stripHtml(richText).replace(/\n/g, ''));
return unesc(stripHtml(richText).replace(/\n/g, ''));
}
return '';
......
<script>
import { GlButton } from '@gitlab/ui';
import _ from 'underscore';
import { isString } from 'lodash';
import Icon from '~/vue_shared/components/icon.vue';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue';
import highlight from '~/lib/utils/highlight';
......@@ -17,7 +17,7 @@ export default {
project: {
type: Object,
required: true,
validator: p => _.isFinite(p.id) && _.isString(p.name) && _.isString(p.name_with_namespace),
validator: p => Number.isFinite(p.id) && isString(p.name) && isString(p.name_with_namespace),
},
selected: {
type: Boolean,
......
<script>
import _ from 'underscore';
import { debounce } from 'lodash';
import { GlLoadingIcon, GlSearchBoxByType, GlInfiniteScroll } from '@gitlab/ui';
import ProjectListItem from './project_list_item.vue';
......@@ -61,9 +61,9 @@ export default {
this.$emit('bottomReached');
},
isSelected(project) {
return Boolean(_.find(this.selectedProjects, { id: project.id }));
return this.selectedProjects.some(({ id }) => project.id === id);
},
onInput: _.debounce(function debouncedOnInput() {
onInput: debounce(function debouncedOnInput() {
this.$emit('searched', this.searchQuery);
}, SEARCH_INPUT_TIMEOUT_MS),
},
......
<script>
import _ from 'underscore';
import { isString } from 'lodash';
import { GlDropdown, GlDropdownDivider, GlDropdownItem } from '@gitlab/ui';
const isValidItem = item =>
_.isString(item.eventName) && _.isString(item.title) && _.isString(item.description);
isString(item.eventName) && isString(item.title) && isString(item.description);
export default {
components: {
......
import _ from 'underscore';
import { isEmpty } from 'lodash';
import { sprintf, __ } from '~/locale';
import { formatDate } from '~/lib/utils/datetime_utility';
import tooltip from '~/vue_shared/directives/tooltip';
......@@ -130,7 +130,7 @@ const mixins = {
return this.assignees.length > 0;
},
hasMilestone() {
return !_.isEmpty(this.milestone);
return !isEmpty(this.milestone);
},
iconName() {
if (this.isMergeRequest && this.isMerged) {
......
---
title: Replace underscore with lodash for ./app/assets/javascripts/vue_shared
merge_request: 25108
author: Tobias Spagert
type: other
......@@ -22,6 +22,7 @@ describe('ProjectSelector component', () => {
beforeEach(() => {
jasmine.clock().install();
jasmine.clock().mockDate();
wrapper = mount(Vue.extend(ProjectSelector), {
localVue,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment