Skip to content

Commit

Permalink
Merge pull request stream-labs#1472 from stream-labs/sb_remove_unders…
Browse files Browse the repository at this point in the history
…core

Remove references to underscore
  • Loading branch information
gettinToasty authored Mar 8, 2019
2 parents 0d614e4 + 3a1af40 commit f4fc16c
Show file tree
Hide file tree
Showing 46 changed files with 106 additions and 137 deletions.
18 changes: 4 additions & 14 deletions app/components/Selector.vue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Vue from 'vue';
import _ from 'lodash';
import { Component, Prop } from 'vue-property-decorator';
import draggable from 'vuedraggable';

Expand All @@ -24,14 +23,9 @@ export default class Selector extends Vue {
draggableSelector: string = this.draggable ? '.selector-item' : 'none';

handleChange(change: any) {
const order = _.map(this.normalizedItems, item => {
return item.value;
});
const order = this.normalizedItems.map(item => item.value);

this.$emit('sort', {
change,
order,
});
this.$emit('sort', { change, order });
}

handleSelect(ev: MouseEvent, index: number) {
Expand Down Expand Up @@ -60,14 +54,10 @@ export default class Selector extends Vue {
* array of objects, so we normalize those here.
*/
get normalizedItems(): ISelectorItem[] {
return _.map(this.items, item => {
return this.items.map(item => {
if (typeof item === 'string') {
return {
name: item,
value: item,
};
return { name: item, value: item };
}

return item;
});
}
Expand Down
16 changes: 9 additions & 7 deletions app/components/StudioEditor.vue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vue from 'vue';
import { Component } from 'vue-property-decorator';
import _ from 'lodash';
import clamp from 'lodash/clamp';
import { DragHandler } from 'util/DragHandler';
import { Inject } from 'util/injector';
import { Scene, SceneItem, ScenesService, TSceneNode } from 'services/scenes';
Expand Down Expand Up @@ -226,7 +226,9 @@ export default class StudioEditor extends Vue {
this.dragHandler.move(event);
} else if (event.buttons === 1) {
// We might need to start dragging
const sourcesInPriorityOrder = _.compact(this.activeSources.concat(this.sceneItems));
const sourcesInPriorityOrder = this.activeSources
.concat(this.sceneItems)
.filter(item => item);

const overSource = sourcesInPriorityOrder.find(source => {
return this.isOverSource(event, source);
Expand Down Expand Up @@ -262,28 +264,28 @@ export default class StudioEditor extends Vue {
case AnchorPoint.East: {
const croppableWidth = rect.width - rect.crop.right - 2;
const distance = croppableWidth * rect.scaleX - (rect.x - x);
rect.crop.left = Math.round(_.clamp(distance / rect.scaleX, 0, croppableWidth));
rect.crop.left = Math.round(clamp(distance / rect.scaleX, 0, croppableWidth));
break;
}

case AnchorPoint.West: {
const croppableWidth = rect.width - rect.crop.left - 2;
const distance = croppableWidth * rect.scaleX + (rect.x - x);
rect.crop.right = Math.round(_.clamp(distance / rect.scaleX, 0, croppableWidth));
rect.crop.right = Math.round(clamp(distance / rect.scaleX, 0, croppableWidth));
break;
}

case AnchorPoint.South: {
const croppableHeight = rect.height - rect.crop.bottom - 2;
const distance = croppableHeight * rect.scaleY - (rect.y - y);
rect.crop.top = Math.round(_.clamp(distance / rect.scaleY, 0, croppableHeight));
rect.crop.top = Math.round(clamp(distance / rect.scaleY, 0, croppableHeight));
break;
}

case AnchorPoint.North: {
const croppableHeight = rect.height - rect.crop.top - 2;
const distance = croppableHeight * rect.scaleY + (rect.y - y);
rect.crop.bottom = Math.round(_.clamp(distance / rect.scaleY, 0, croppableHeight));
rect.crop.bottom = Math.round(clamp(distance / rect.scaleY, 0, croppableHeight));
break;
}
}
Expand Down Expand Up @@ -437,7 +439,7 @@ export default class StudioEditor extends Vue {
// of the active source's resize regions.
isOverResize(event: MouseEvent) {
if (this.activeSources.length > 0) {
return _.find(this.resizeRegions, region => {
return this.resizeRegions.find(region => {
return this.isOverBox(event, region.x, region.y, region.width, region.height);
});
}
Expand Down
5 changes: 2 additions & 3 deletions app/components/obs/inputs/ObsColorInput.vue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import { Component, Watch, Prop } from 'vue-property-decorator';
import { debounce } from 'lodash-decorators';
import { TObsType, IObsInput, ObsInput } from './ObsInput';
Expand Down Expand Up @@ -29,7 +28,7 @@ class ObsColorInput extends ObsInput<IObsInput<number>> {

@debounce(500)
setValue(rgba: IColor) {
if (!_.isEqual(rgba, this.obsColor)) {
if (!Object.keys(rgba).every(key => rgba[key] === this.obsColor[key])) {
const intColor = Utils.rgbaToInt(rgba.r, rgba.g, rgba.b, Math.round(255 * rgba.a));
this.emitInput({ ...this.value, value: intColor });
}
Expand All @@ -41,7 +40,7 @@ class ObsColorInput extends ObsInput<IObsInput<number>> {

get hexAlpha() {
const alpha = this.obsColor.a;
return _.padStart(Math.floor(alpha * 255).toString(16), 2, '0');
return `00${Math.floor(alpha * 255).toString(16)}`;
}

get hexColor() {
Expand Down
8 changes: 4 additions & 4 deletions app/components/obs/inputs/ObsEditableListInput.vue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import electron from 'electron';
import cloneDeep from 'lodash/cloneDeep';
import Selector from '../../Selector.vue';
import { Component, Prop } from 'vue-property-decorator';
import { IObsEditableListInputValue, ObsInput, TObsType } from './ObsInput';
Expand Down Expand Up @@ -47,7 +47,7 @@ class ObsEditableListProperty extends ObsInput<IObsEditableListInputValue> {
}

handleRemove() {
this.setList(_.without(this.list, this.activeItem));
this.setList(this.list.filter(item => item !== this.activeItem));
}

handleEdit() {
Expand All @@ -62,7 +62,7 @@ class ObsEditableListProperty extends ObsInput<IObsEditableListInputValue> {
});

if (files) {
const activeIndex = _.indexOf(this.list, this.activeItem);
const activeIndex = this.list.indexOf(this.activeItem);

this.list[activeIndex] = files[0];

Expand Down Expand Up @@ -101,7 +101,7 @@ class ObsEditableListProperty extends ObsInput<IObsEditableListInputValue> {

get list(): string[] {
const items = this.value.value || [];
return _.cloneDeep(items.map(item => item.value));
return cloneDeep(items.map(item => item.value));
}
}

Expand Down
5 changes: 2 additions & 3 deletions app/components/obs/inputs/ObsInput.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import Vue from 'vue';
import { Prop } from 'vue-property-decorator';
import * as obs from '../../../../obs-api';
Expand Down Expand Up @@ -114,7 +113,7 @@ export interface IElectronOpenDialogFilter {
}

function parsePathFilters(filterStr: string): IElectronOpenDialogFilter[] {
const filters = _.compact(filterStr.split(';;'));
const filters = filterStr.split(';;').filter(item => item);

// Browser source uses *.*
if (filterStr === '*.*') {
Expand All @@ -128,7 +127,7 @@ function parsePathFilters(filterStr: string): IElectronOpenDialogFilter[] {

return filters.map(filter => {
const match = filter.match(/^(.*)\((.*)\)$/);
const desc = _.trim(match[1]);
const desc = match[1].replace(/^\s+/, '').replace(/\s+$/, '');
let types = match[2].split(' ');

types = types.map(type => {
Expand Down
3 changes: 1 addition & 2 deletions app/components/page-components/Chatbot/ChatbotBase.vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Tabs from 'components/Tabs.vue';
import DropdownMenu from 'components/shared/DropdownMenu.vue';
import { inputComponents } from 'components/widgets/inputs';
import VFormGroup from 'components/shared/inputs/VFormGroup.vue';
import * as _ from 'lodash';
import {
ChatbotApiService,
ChatbotPermissionsEnums,
Expand Down Expand Up @@ -38,7 +37,7 @@ export default class ChatbotBase extends Vue {
}

get chatbotPermissions() {
const keys = _.difference(Object.keys(ChatbotPermissionsEnums), ['None']);
const keys = Object.keys(ChatbotPermissionsEnums).filter(key => key !== 'None');

const permissions = keys.reduce((a: IListOption<number>[], b: string) => {
if (typeof ChatbotPermissionsEnums[b] === 'number') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ChatbotBase from 'components/page-components/Chatbot/ChatbotBase.vue';
import { Component, Prop } from 'vue-property-decorator';
import { throttle } from 'lodash-decorators';
import sumBy from 'lodash/sumBy';
import ChatbotBase from 'components/page-components/Chatbot/ChatbotBase.vue';
import ChatbotVoteTracker from './ChatbotVoteTracker.vue';
import * as _ from 'lodash';
import ChatbotGenericModalWindow from '../windows/ChatbotGenericModalWindow.vue';
import { ChatbotSettingSlug } from 'services/chatbot';

Expand All @@ -22,8 +23,7 @@ export default class ChatbotActivePoll extends ChatbotBase {
get isCancelable() {
if (this.type === 'poll') {
return (
_.sumBy(this.chatbotApiService.Poll.state.activePollResponse.settings.options, 'votes') ===
0
sumBy(this.chatbotApiService.Poll.state.activePollResponse.settings.options, 'votes') === 0
);
}
return this.chatbotApiService.Betting.state.activeBettingResponse.status !== 'Picked';
Expand All @@ -38,13 +38,13 @@ export default class ChatbotActivePoll extends ChatbotBase {

get total() {
if (this.type === 'poll') {
return _.sumBy(this.active.settings.options, 'votes');
return sumBy(this.active.settings.options, 'votes');
}
return _.sumBy(this.active.settings.options, 'bets');
return sumBy(this.active.settings.options, 'bets');
}

get loyalty() {
return _.sumBy(this.active.settings.options, 'loyalty');
return sumBy(this.active.settings.options, 'loyalty');
}

get active() {
Expand All @@ -65,12 +65,7 @@ export default class ChatbotActivePoll extends ChatbotBase {
return this.chatbotApiService.Betting.state.timeRemaining;
}

mounted() {
this.onToggleStateHandler = _.throttle(this.onToggleStateHandler, 1000);
this.onCancelHandler = _.throttle(this.onCancelHandler, 1000);
this.onCompleteHandler = _.throttle(this.onCompleteHandler, 1000);
}

@throttle(1000)
onToggleStateHandler() {
if (this.type === 'poll') {
this.togglePoll();
Expand All @@ -95,11 +90,13 @@ export default class ChatbotActivePoll extends ChatbotBase {
}
}

@throttle(1000)
onCancelHandler() {
this.$modal.show(this.CANCEL_MODAL);
this.chatbotApiService.Common.closeChatbotChildWindow();
}

@throttle(1000)
onCompleteHandler() {
if (this.type === 'poll') {
this.chatbotApiService.Poll.completePoll();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import ChatbotBase from 'components/page-components/Chatbot/ChatbotBase.vue';
import { Component, Prop } from 'vue-property-decorator';
import orderBy from 'lodash/orderBy';
import map from 'lodash/map';
import ChatbotBase from 'components/page-components/Chatbot/ChatbotBase.vue';
import { IPollProfile, DELETE_MODAL, ChatbotSettingSlug, IBettingProfile } from 'services/chatbot';
import moment from 'moment';
import * as _ from 'lodash';
import ChatbotGenericModalWindow from '../windows/ChatbotGenericModalWindow.vue';
import ChatbotVoteTracker from './ChatbotVoteTracker.vue';

Expand All @@ -18,7 +19,7 @@ export default class ChatbotPollProfile extends ChatbotBase {
}

get options() {
return _.map(this.profile.options, 'name').join(', ');
return map(this.profile.options, 'name').join(', ');
}

get timeRemaining() {
Expand Down Expand Up @@ -74,11 +75,11 @@ export default class ChatbotPollProfile extends ChatbotBase {
get topThreeOptions() {
if (this.type === 'poll') {
const active = this.chatbotApiService.Poll.state.activePollResponse;
return _.orderBy(active.settings.options.slice(0, 5), 'votes', 'desc');
return orderBy(active.settings.options.slice(0, 5), 'votes', 'desc');
}

const active = this.chatbotApiService.Betting.state.activeBettingResponse;
return _.orderBy(active.settings.options.slice(0, 5), 'bets', 'desc');
return orderBy(active.settings.options.slice(0, 5), 'bets', 'desc');
}

onEditProfileHandler() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ChatbotBase from 'components/page-components/Chatbot/ChatbotBase.vue';
import { Component, Prop } from 'vue-property-decorator';
import sumBy from 'lodash/sumBy';
import ChatbotBase from 'components/page-components/Chatbot/ChatbotBase.vue';
import { IPollOption, ChatbotSettingSlug, IBettingOption } from 'services/chatbot';
import * as _ from 'lodash';

@Component({})
export default class ChatbotVoteTracker extends ChatbotBase {
Expand Down Expand Up @@ -53,9 +53,9 @@ export default class ChatbotVoteTracker extends ChatbotBase {

get total() {
if (this.type === 'poll') {
return _.sumBy(this.activeSettings.options, 'votes');
return sumBy(this.activeSettings.options, 'votes');
}
return _.sumBy(this.activeSettings.options, 'bets');
return sumBy(this.activeSettings.options, 'bets');
}

get settings() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloneDeep } from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import { Component } from 'vue-property-decorator';
import ChatbotWindowsBase from 'components/page-components/Chatbot/windows/ChatbotWindowsBase.vue';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloneDeep } from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import { Component, Watch } from 'vue-property-decorator';
import ChatbotWindowsBase from 'components/page-components/Chatbot/windows/ChatbotWindowsBase.vue';
import { $t } from 'services/i18n';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Component, Prop, Watch } from 'vue-property-decorator';
import { Component, Watch } from 'vue-property-decorator';
import cloneDeep from 'lodash/cloneDeep';
import ChatbotWindowsBase from 'components/page-components/Chatbot/windows/ChatbotWindowsBase.vue';
import { $t } from 'services/i18n';
import * as _ from 'lodash';
import ValidatedForm from 'components/shared/inputs/ValidatedForm.vue';

import { IBettingPreferencesResponse } from 'services/chatbot';

import { EInputType, metadata, formMetadata } from 'components/shared/inputs/index';
import { metadata, formMetadata } from 'components/shared/inputs/index';
import { ITab } from 'components/Tabs.vue';
import { debounce } from 'lodash-decorators';

Expand Down Expand Up @@ -104,7 +104,7 @@ export default class ChatbotBettingPreferencesWindow extends ChatbotWindowsBase
}

mounted() {
this.newBettingPreferences = _.cloneDeep(this.pollPreferences);
this.newBettingPreferences = cloneDeep(this.pollPreferences);
}

onSelectTabHandler(tab: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Component, Prop, Watch } from 'vue-property-decorator';
import ChatbotWindowsBase from 'components/page-components/Chatbot/windows/ChatbotWindowsBase.vue';
import { Component } from 'vue-property-decorator';
import cloneDeep from 'lodash/cloneDeep';
import { $t } from 'services/i18n';
import * as _ from 'lodash';
import { IChatbotErrorResponse, IBettingProfile, IBettingOption } from 'services/chatbot';
import { EInputType, metadata, formMetadata } from 'components/shared/inputs/index';
import { IBettingProfile, IBettingOption } from 'services/chatbot';
import { metadata, formMetadata } from 'components/shared/inputs/index';
import ValidatedForm from 'components/shared/inputs/ValidatedForm.vue';
import { ITab } from 'components/Tabs.vue';
import { debounce } from 'lodash-decorators';
import ChatbotBetOptionModal from '../Bet/ChatbotBetOptionModal.vue';
import ChatbotPollProfileWindow from './ChatbotPollProfileWindow.vue';

Expand Down Expand Up @@ -77,7 +74,7 @@ export default class ChatbotBettingProfileWindow extends ChatbotPollProfileWindo
mounted() {
// if editing existing custom command
if (this.isEdit) {
this.newProfile = _.cloneDeep(this.profileToUpdate);
this.newProfile = cloneDeep(this.profileToUpdate);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Prop } from 'vue-property-decorator';
import ChatbotWindowsBase from 'components/page-components/Chatbot/windows/ChatbotWindowsBase.vue';
import { cloneDeep } from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import { $t } from 'services/i18n';
import { metadata as metadataHelper } from 'components/widgets/inputs';
import ValidatedForm from 'components/shared/inputs/ValidatedForm.vue';
Expand Down
Loading

0 comments on commit f4fc16c

Please sign in to comment.