de-lodashify
This commit is contained in:
parent
9648e45341
commit
2db420ac54
7 changed files with 44 additions and 56 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { concat, last } from 'lodash'
|
import { last } from 'lodash'
|
||||||
|
|
||||||
import { paramsString, promisedRequest } from './helpers.js'
|
import { paramsString, promisedRequest } from './helpers.js'
|
||||||
import { fetchFriends, MASTODON_STATUS_URL } from './public.js'
|
import { fetchFriends, MASTODON_STATUS_URL } from './public.js'
|
||||||
|
|
@ -412,7 +412,7 @@ export const exportFriends = ({ id, credentials }) => {
|
||||||
credentials,
|
credentials,
|
||||||
withRelationships: true,
|
withRelationships: true,
|
||||||
})
|
})
|
||||||
friends = concat(friends, users)
|
friends = [...friends, ...users]
|
||||||
if (users.length === 0) {
|
if (users.length === 0) {
|
||||||
more = false
|
more = false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,12 @@ import {
|
||||||
find,
|
find,
|
||||||
findIndex,
|
findIndex,
|
||||||
first,
|
first,
|
||||||
isArray,
|
|
||||||
last,
|
last,
|
||||||
maxBy,
|
maxBy,
|
||||||
merge,
|
merge,
|
||||||
minBy,
|
minBy,
|
||||||
omitBy,
|
omitBy,
|
||||||
remove,
|
remove,
|
||||||
slice,
|
|
||||||
} from 'lodash'
|
} from 'lodash'
|
||||||
|
|
||||||
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
|
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
|
||||||
|
|
@ -206,7 +204,7 @@ const addNewStatuses = (
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if (!isArray(statuses)) {
|
if (!Array.isArray(statuses)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -410,7 +408,7 @@ export const mutations = {
|
||||||
const oldTimeline = state.timelines[timeline]
|
const oldTimeline = state.timelines[timeline]
|
||||||
|
|
||||||
oldTimeline.newStatusCount = 0
|
oldTimeline.newStatusCount = 0
|
||||||
oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50)
|
oldTimeline.visibleStatuses = oldTimeline.statuses.slice(0, 50)
|
||||||
oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id
|
oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id
|
||||||
oldTimeline.minId = oldTimeline.minVisibleId
|
oldTimeline.minId = oldTimeline.minVisibleId
|
||||||
oldTimeline.visibleStatusesObject = {}
|
oldTimeline.visibleStatusesObject = {}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,5 @@
|
||||||
import Cookies from 'js-cookie'
|
import Cookies from 'js-cookie'
|
||||||
import {
|
import { compact, each, last, map, mergeWith } from 'lodash'
|
||||||
compact,
|
|
||||||
concat,
|
|
||||||
each,
|
|
||||||
isArray,
|
|
||||||
last,
|
|
||||||
map,
|
|
||||||
mergeWith,
|
|
||||||
uniq,
|
|
||||||
} from 'lodash'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
registerPushNotifications,
|
registerPushNotifications,
|
||||||
|
|
@ -76,7 +67,7 @@ export const mergeOrAdd = (arr, obj, item) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mergeArrayLength = (oldValue, newValue) => {
|
const mergeArrayLength = (oldValue, newValue) => {
|
||||||
if (isArray(oldValue) && isArray(newValue)) {
|
if (Array.isArray(oldValue) && Array.isArray(newValue)) {
|
||||||
oldValue.length = newValue.length
|
oldValue.length = newValue.length
|
||||||
return mergeWith(oldValue, newValue, mergeArrayLength)
|
return mergeWith(oldValue, newValue, mergeArrayLength)
|
||||||
}
|
}
|
||||||
|
|
@ -234,11 +225,11 @@ export const mutations = {
|
||||||
},
|
},
|
||||||
saveFriendIds(state, { id, friendIds }) {
|
saveFriendIds(state, { id, friendIds }) {
|
||||||
const user = state.usersObject[id]
|
const user = state.usersObject[id]
|
||||||
user.friendIds = uniq(concat(user.friendIds || [], friendIds))
|
user.friendIds = [...new Set([...(user.friendIds || []), ...friendIds])]
|
||||||
},
|
},
|
||||||
saveFollowerIds(state, { id, followerIds }) {
|
saveFollowerIds(state, { id, followerIds }) {
|
||||||
const user = state.usersObject[id]
|
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
|
// Because frontend doesn't have a reason to keep these stuff in memory
|
||||||
// outside of viewing someones user profile.
|
// outside of viewing someones user profile.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import { uniq } from 'lodash'
|
|
||||||
|
|
||||||
import * as DateUtils from 'src/services/date_utils/date_utils.js'
|
import * as DateUtils from 'src/services/date_utils/date_utils.js'
|
||||||
|
|
||||||
const pollFallbackValues = {
|
const pollFallbackValues = {
|
||||||
|
|
@ -19,9 +17,9 @@ export const pollFormToMasto = (poll) => {
|
||||||
pollFallback(poll, 'expiryAmount'),
|
pollFallback(poll, 'expiryAmount'),
|
||||||
)
|
)
|
||||||
|
|
||||||
const options = uniq(
|
const options = [...new Set(
|
||||||
pollFallback(poll, 'options').filter((option) => option !== ''),
|
pollFallback(poll, 'options').filter((option) => option !== ''),
|
||||||
)
|
)]
|
||||||
if (options.length < 2) {
|
if (options.length < 2) {
|
||||||
return { errorKey: 'polls.not_enough_options' }
|
return { errorKey: 'polls.not_enough_options' }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 { defineStore } from 'pinia'
|
||||||
|
|
||||||
import { useOAuthStore } from 'src/stores/oauth.js'
|
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||||
|
|
@ -209,11 +209,11 @@ export const useAdminSettingsStore = defineStore('adminSettings', {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting all group-keys used in config
|
// Getting all group-keys used in config
|
||||||
const allGroupKeys = flatten(
|
const allGroupKeys = Object.entries(this.config)
|
||||||
Object.entries(this.config).map(([group, lv1data]) =>
|
.map(([group, lv1data]) =>
|
||||||
Object.keys(lv1data).map((key) => ({ group, key })),
|
Object.keys(lv1data).map((key) => ({ group, key })),
|
||||||
),
|
)
|
||||||
)
|
.flat()
|
||||||
|
|
||||||
// Only using group-keys where there are changes detected
|
// Only using group-keys where there are changes detected
|
||||||
const changedGroupKeys = allGroupKeys.filter(({ group, key }) => {
|
const changedGroupKeys = allGroupKeys.filter(({ group, key }) => {
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,12 @@ import {
|
||||||
clamp,
|
clamp,
|
||||||
cloneDeep,
|
cloneDeep,
|
||||||
findLastIndex,
|
findLastIndex,
|
||||||
flatten,
|
|
||||||
get,
|
get,
|
||||||
groupBy,
|
groupBy,
|
||||||
isEqual,
|
isEqual,
|
||||||
set,
|
set,
|
||||||
take,
|
take,
|
||||||
takeRight,
|
last,
|
||||||
uniqWith,
|
uniqWith,
|
||||||
unset,
|
unset,
|
||||||
} from 'lodash'
|
} from 'lodash'
|
||||||
|
|
@ -222,15 +221,16 @@ export const _mergeFlags = (recent, stale, allFlagKeys) => {
|
||||||
|
|
||||||
export const _mergeJournal = (...journals) => {
|
export const _mergeJournal = (...journals) => {
|
||||||
// Ignore invalid journal entries
|
// Ignore invalid journal entries
|
||||||
const allJournals = flatten(
|
const allJournals = journals
|
||||||
journals.map((j) => (Array.isArray(j) ? j : [])),
|
.map((j) => (Array.isArray(j) ? j : []))
|
||||||
).filter(
|
.flat()
|
||||||
(entry) =>
|
.filter(
|
||||||
Object.hasOwn(entry, 'path') &&
|
(entry) =>
|
||||||
Object.hasOwn(entry, 'operation') &&
|
Object.hasOwn(entry, 'path') &&
|
||||||
Object.hasOwn(entry, 'args') &&
|
Object.hasOwn(entry, 'operation') &&
|
||||||
Object.hasOwn(entry, 'timestamp'),
|
Object.hasOwn(entry, 'args') &&
|
||||||
)
|
Object.hasOwn(entry, 'timestamp'),
|
||||||
|
)
|
||||||
const grouped = groupBy(allJournals, 'path')
|
const grouped = groupBy(allJournals, 'path')
|
||||||
const trimmedGrouped = Object.entries(grouped).map(([path, rawJournal]) => {
|
const trimmedGrouped = Object.entries(grouped).map(([path, rawJournal]) => {
|
||||||
const journal = rawJournal
|
const journal = rawJournal
|
||||||
|
|
@ -271,13 +271,14 @@ export const _mergeJournal = (...journals) => {
|
||||||
})
|
})
|
||||||
} else if (path.startsWith('simple')) {
|
} else if (path.startsWith('simple')) {
|
||||||
// Only the last record is important
|
// Only the last record is important
|
||||||
return takeRight(journal)
|
return [last(journal)]
|
||||||
} else {
|
} else {
|
||||||
return journal
|
return journal
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const flat = flatten(trimmedGrouped)
|
const flat = trimmedGrouped
|
||||||
|
.flat()
|
||||||
.map((data, index) => ({ data, index }))
|
.map((data, index) => ({ data, index }))
|
||||||
.toSorted(({ data: a, index: ai }, { data: b, index: bi }) => {
|
.toSorted(({ data: a, index: ai }, { data: b, index: bi }) => {
|
||||||
if (a.timestamp === b.timestamp) {
|
if (a.timestamp === b.timestamp) {
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,9 @@ import {
|
||||||
merge as _merge,
|
merge as _merge,
|
||||||
clone,
|
clone,
|
||||||
cloneDeep,
|
cloneDeep,
|
||||||
flatten,
|
|
||||||
groupBy,
|
groupBy,
|
||||||
isEqual,
|
isEqual,
|
||||||
takeRight,
|
last,
|
||||||
} from 'lodash'
|
} from 'lodash'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { toRaw } from 'vue'
|
import { toRaw } from 'vue'
|
||||||
|
|
@ -117,25 +116,26 @@ export const _getRecentData = (cache, live, isTest) => {
|
||||||
|
|
||||||
const _mergeJournal = (...journals) => {
|
const _mergeJournal = (...journals) => {
|
||||||
// Ignore invalid journal entries
|
// Ignore invalid journal entries
|
||||||
const allJournals = flatten(
|
const allJournals = journals
|
||||||
journals.map((j) => (Array.isArray(j) ? j : [])),
|
.map((j) => (Array.isArray(j) ? j : []))
|
||||||
).filter(
|
.flat()
|
||||||
(entry) =>
|
.filter(
|
||||||
Object.hasOwn(entry, 'user') &&
|
(entry) =>
|
||||||
Object.hasOwn(entry, 'operation') &&
|
Object.hasOwn(entry, 'user') &&
|
||||||
Object.hasOwn(entry, 'args') &&
|
Object.hasOwn(entry, 'operation') &&
|
||||||
Object.hasOwn(entry, 'timestamp'),
|
Object.hasOwn(entry, 'args') &&
|
||||||
)
|
Object.hasOwn(entry, 'timestamp'),
|
||||||
|
)
|
||||||
const grouped = groupBy(allJournals, 'user')
|
const grouped = groupBy(allJournals, 'user')
|
||||||
const trimmedGrouped = Object.entries(grouped).map(([user, journal]) => {
|
const trimmedGrouped = Object.entries(grouped).map(([user, journal]) => {
|
||||||
// side effect
|
// side effect
|
||||||
journal.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
|
journal.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
|
||||||
|
|
||||||
return takeRight(journal)
|
return [last(journal)]
|
||||||
})
|
})
|
||||||
return flatten(trimmedGrouped).sort((a, b) =>
|
return trimmedGrouped
|
||||||
a.timestamp > b.timestamp ? 1 : -1,
|
.flat()
|
||||||
)
|
.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const _mergeHighlights = (recent, stale) => {
|
export const _mergeHighlights = (recent, stale) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue