Refine lodash import

This commit is contained in:
CzBiX
2020-03-29 18:18:51 +08:00
parent f67bda4f46
commit 860a0aebbe
9 changed files with 21 additions and 26 deletions

View File

@@ -145,7 +145,7 @@
</template>
<script lang="ts">
import _ from 'lodash';
import { isNil } from 'lodash';
import Vue from 'vue';
import { mapState } from 'vuex';
@@ -226,7 +226,7 @@ export default class AddForm extends Vue {
}
setParams(key: string, value: any) {
if (_.isNil(value)) {
if (isNil(value)) {
Vue.delete(this.userParams, key);
} else {
Vue.set(this.userParams, key, value);

View File

@@ -128,7 +128,7 @@
</template>
<script lang="ts">
import _ from 'lodash';
import { sumBy } from 'lodash';
import Vue from 'vue';
import { mapState, mapGetters } from 'vuex';
import api from '../Api';
@@ -180,7 +180,7 @@ export default class Footer extends Vue {
allTorrents!: Torrent[]
get totalSize() {
return _.sumBy(this.allTorrents, 'size');
return sumBy(this.allTorrents, 'size');
}
get speedModeBind() {

View File

@@ -45,7 +45,6 @@
</template>
<script lang="ts">
import _ from 'lodash';
import Vue from 'vue';
import { mapGetters } from 'vuex';

View File

@@ -45,7 +45,6 @@
</template>
<script lang="ts">
import _ from 'lodash';
import Vue from 'vue';
import { mapGetters } from 'vuex';

View File

@@ -91,7 +91,6 @@
</template>
<script lang="ts">
import _ from 'lodash';
import Vue from 'vue';
import TorrentInfo from './TorrentInfo.vue';
import TorrentContent from './TorrentContent.vue';

View File

@@ -1,4 +1,4 @@
import _ from 'lodash';
import { isPlainObject, merge } from 'lodash';
import Vue from 'vue';
import { Module } from 'vuex';
import { ConfigState, ConfigPayload } from './types';
@@ -40,8 +40,8 @@ export const configStore : Module<ConfigState, any> = {
mutations: {
updateConfig(state, payload: ConfigPayload) {
const { key, value } = payload;
if (_.isPlainObject(value)) {
const tmp = _.merge({}, state.userConfig[key], value);
if (isPlainObject(value)) {
const tmp = merge({}, state.userConfig[key], value);
Vue.set(state.userConfig, key, tmp);
} else {
Vue.set(state.userConfig, key, value);
@@ -52,7 +52,7 @@ export const configStore : Module<ConfigState, any> = {
},
getters: {
config(state) {
return _.merge({}, defaultConfig, state.userConfig);
return merge({}, defaultConfig, state.userConfig);
},
},
};

View File

@@ -1,4 +1,4 @@
import _ from 'lodash';
import { cloneDeep, merge, map, groupBy, sortBy } from 'lodash';
import Vue from 'vue';
import Vuex from 'vuex';
import { computed, Ref } from '@vue/composition-api';
@@ -33,7 +33,7 @@ const store = new Vuex.Store<RootState>({
delete payload.full_update;
state.mainData = payload;
} else {
const tmp: any = _.cloneDeep(state.mainData);
const tmp: any = cloneDeep(state.mainData);
if (payload.torrents_removed) {
for (const hash of payload.torrents_removed) {
delete tmp.torrents[hash];
@@ -46,7 +46,7 @@ const store = new Vuex.Store<RootState>({
}
delete payload.categories_removed;
}
state.mainData = _.merge(tmp, payload);
state.mainData = merge(tmp, payload);
}
},
updatePreferences(state, payload) {
@@ -67,23 +67,22 @@ const store = new Vuex.Store<RootState>({
return [];
}
return _.map(state.mainData.torrents,
(value, key) => _.merge({}, value, { hash: key }));
return map(state.mainData.torrents, (value, key) => merge({}, value, { hash: key }));
},
allCategories(state) {
if (!state.mainData) {
return [];
}
const categories = _.map(state.mainData.categories,
(value, key) => _.merge({}, value, { key }));
return _.sortBy(categories, 'name');
const categories = map(state.mainData.categories,
(value, key) => merge({}, value, { key }));
return sortBy(categories, 'name');
},
torrentGroupByCategory(state, getters) {
return _.groupBy(getters.allTorrents, torrent => torrent.category);
return groupBy(getters.allTorrents, torrent => torrent.category);
},
torrentGroupBySite(state, getters) {
return _.groupBy(getters.allTorrents, (torrent) => {
return groupBy(getters.allTorrents, (torrent) => {
if (!torrent.tracker) {
return '';
}

View File

@@ -1,4 +1,4 @@
import _ from 'lodash';
import { cloneDeep, isString } from 'lodash';
import { Module } from 'vuex';
import { SnackBarState } from './types';
@@ -10,12 +10,12 @@ export const snackBarStore : Module<SnackBarState, any> = {
},
mutations: {
showSnackBar(state, payload) {
if (_.isString(payload)) {
if (isString(payload)) {
state.config = {
text: payload,
};
} else {
state.config = _.cloneDeep(payload);
state.config = cloneDeep(payload);
}
},
closeSnackBar(state) {

View File

@@ -1,4 +1,3 @@
import _ from 'lodash';
import { StateType } from './consts';
import { Torrent } from './types';
@@ -73,7 +72,7 @@ export function codeToFlag(code: string) {
export const isWindows = navigator.userAgent.includes('Windows');
export function findSameNamedTorrents(allTorrents: Torrent[], torrents: Torrent[]) {
const hashes = _.map(torrents, t => t.hash);
const hashes = torrents.map(t => t.hash);
const result = [];
for (const t1 of torrents) {
for (const t2 of allTorrents) {