de-lodashify

This commit is contained in:
Henry Jameson 2026-08-04 16:36:27 +03:00
commit 2db420ac54
7 changed files with 44 additions and 56 deletions

View file

@ -1,4 +1,4 @@
import { concat, last } from 'lodash'
import { last } from 'lodash'
import { paramsString, promisedRequest } from './helpers.js'
import { fetchFriends, MASTODON_STATUS_URL } from './public.js'
@ -412,7 +412,7 @@ export const exportFriends = ({ id, credentials }) => {
credentials,
withRelationships: true,
})
friends = concat(friends, users)
friends = [...friends, ...users]
if (users.length === 0) {
more = false
}

View file

@ -3,14 +3,12 @@ import {
find,
findIndex,
first,
isArray,
last,
maxBy,
merge,
minBy,
omitBy,
remove,
slice,
} from 'lodash'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
@ -206,7 +204,7 @@ const addNewStatuses = (
},
) => {
// Sanity check
if (!isArray(statuses)) {
if (!Array.isArray(statuses)) {
return false
}
@ -410,7 +408,7 @@ export const mutations = {
const oldTimeline = state.timelines[timeline]
oldTimeline.newStatusCount = 0
oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50)
oldTimeline.visibleStatuses = oldTimeline.statuses.slice(0, 50)
oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id
oldTimeline.minId = oldTimeline.minVisibleId
oldTimeline.visibleStatusesObject = {}

View file

@ -1,14 +1,5 @@
import Cookies from 'js-cookie'
import {
compact,
concat,
each,
isArray,
last,
map,
mergeWith,
uniq,
} from 'lodash'
import { compact, each, last, map, mergeWith } from 'lodash'
import {
registerPushNotifications,
@ -76,7 +67,7 @@ export const mergeOrAdd = (arr, obj, item) => {
}
const mergeArrayLength = (oldValue, newValue) => {
if (isArray(oldValue) && isArray(newValue)) {
if (Array.isArray(oldValue) && Array.isArray(newValue)) {
oldValue.length = newValue.length
return mergeWith(oldValue, newValue, mergeArrayLength)
}
@ -234,11 +225,11 @@ export const mutations = {
},
saveFriendIds(state, { id, friendIds }) {
const user = state.usersObject[id]
user.friendIds = uniq(concat(user.friendIds || [], friendIds))
user.friendIds = [...new Set([...(user.friendIds || []), ...friendIds])]
},
saveFollowerIds(state, { id, followerIds }) {
const user = state.usersObject[id]
user.followerIds = uniq(concat(user.followerIds || [], followerIds))
user.followerIds = [...new Set([user.followerIds || [], ...followerIds])]
},
// Because frontend doesn't have a reason to keep these stuff in memory
// outside of viewing someones user profile.

View file

@ -1,5 +1,3 @@
import { uniq } from 'lodash'
import * as DateUtils from 'src/services/date_utils/date_utils.js'
const pollFallbackValues = {
@ -19,9 +17,9 @@ export const pollFormToMasto = (poll) => {
pollFallback(poll, 'expiryAmount'),
)
const options = uniq(
const options = [...new Set(
pollFallback(poll, 'options').filter((option) => option !== ''),
)
)]
if (options.length < 2) {
return { errorKey: 'polls.not_enough_options' }
}

View file

@ -1,4 +1,4 @@
import { cloneDeep, differenceWith, flatten, get, isEqual, set } from 'lodash'
import { cloneDeep, differenceWith, get, isEqual, set } from 'lodash'
import { defineStore } from 'pinia'
import { useOAuthStore } from 'src/stores/oauth.js'
@ -209,11 +209,11 @@ export const useAdminSettingsStore = defineStore('adminSettings', {
}
// Getting all group-keys used in config
const allGroupKeys = flatten(
Object.entries(this.config).map(([group, lv1data]) =>
const allGroupKeys = Object.entries(this.config)
.map(([group, lv1data]) =>
Object.keys(lv1data).map((key) => ({ group, key })),
),
)
)
.flat()
// Only using group-keys where there are changes detected
const changedGroupKeys = allGroupKeys.filter(({ group, key }) => {

View file

@ -4,13 +4,12 @@ import {
clamp,
cloneDeep,
findLastIndex,
flatten,
get,
groupBy,
isEqual,
set,
take,
takeRight,
last,
uniqWith,
unset,
} from 'lodash'
@ -222,15 +221,16 @@ export const _mergeFlags = (recent, stale, allFlagKeys) => {
export const _mergeJournal = (...journals) => {
// Ignore invalid journal entries
const allJournals = flatten(
journals.map((j) => (Array.isArray(j) ? j : [])),
).filter(
(entry) =>
Object.hasOwn(entry, 'path') &&
Object.hasOwn(entry, 'operation') &&
Object.hasOwn(entry, 'args') &&
Object.hasOwn(entry, 'timestamp'),
)
const allJournals = journals
.map((j) => (Array.isArray(j) ? j : []))
.flat()
.filter(
(entry) =>
Object.hasOwn(entry, 'path') &&
Object.hasOwn(entry, 'operation') &&
Object.hasOwn(entry, 'args') &&
Object.hasOwn(entry, 'timestamp'),
)
const grouped = groupBy(allJournals, 'path')
const trimmedGrouped = Object.entries(grouped).map(([path, rawJournal]) => {
const journal = rawJournal
@ -271,13 +271,14 @@ export const _mergeJournal = (...journals) => {
})
} else if (path.startsWith('simple')) {
// Only the last record is important
return takeRight(journal)
return [last(journal)]
} else {
return journal
}
})
const flat = flatten(trimmedGrouped)
const flat = trimmedGrouped
.flat()
.map((data, index) => ({ data, index }))
.toSorted(({ data: a, index: ai }, { data: b, index: bi }) => {
if (a.timestamp === b.timestamp) {

View file

@ -2,10 +2,9 @@ import {
merge as _merge,
clone,
cloneDeep,
flatten,
groupBy,
isEqual,
takeRight,
last,
} from 'lodash'
import { defineStore } from 'pinia'
import { toRaw } from 'vue'
@ -117,25 +116,26 @@ export const _getRecentData = (cache, live, isTest) => {
const _mergeJournal = (...journals) => {
// Ignore invalid journal entries
const allJournals = flatten(
journals.map((j) => (Array.isArray(j) ? j : [])),
).filter(
(entry) =>
Object.hasOwn(entry, 'user') &&
Object.hasOwn(entry, 'operation') &&
Object.hasOwn(entry, 'args') &&
Object.hasOwn(entry, 'timestamp'),
)
const allJournals = journals
.map((j) => (Array.isArray(j) ? j : []))
.flat()
.filter(
(entry) =>
Object.hasOwn(entry, 'user') &&
Object.hasOwn(entry, 'operation') &&
Object.hasOwn(entry, 'args') &&
Object.hasOwn(entry, 'timestamp'),
)
const grouped = groupBy(allJournals, 'user')
const trimmedGrouped = Object.entries(grouped).map(([user, journal]) => {
// side effect
journal.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
return takeRight(journal)
return [last(journal)]
})
return flatten(trimmedGrouped).sort((a, b) =>
a.timestamp > b.timestamp ? 1 : -1,
)
return trimmedGrouped
.flat()
.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
}
export const _mergeHighlights = (recent, stale) => {