perf: use lodash-lite for some functions (#853)
This commit is contained in:
parent
cf94e7d61e
commit
e666eb5955
|
@ -40,7 +40,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { store } from '../../_store/store'
|
import { store } from '../../_store/store'
|
||||||
import ComposeAutosuggestionList from './ComposeAutosuggestionList.html'
|
import ComposeAutosuggestionList from './ComposeAutosuggestionList.html'
|
||||||
import get from 'lodash-es/get'
|
import { get } from '../../_utils/lodash-lite'
|
||||||
import { selectAutosuggestItem } from '../../_actions/autosuggest'
|
import { selectAutosuggestItem } from '../../_actions/autosuggest'
|
||||||
import { observe } from 'svelte-extras'
|
import { observe } from 'svelte-extras'
|
||||||
import { once } from '../../_utils/once'
|
import { once } from '../../_utils/once'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import get from 'lodash-es/get'
|
import { get } from '../../_utils/lodash-lite'
|
||||||
|
|
||||||
const MIN_PREFIX_LENGTH = 1
|
const MIN_PREFIX_LENGTH = 1
|
||||||
const ACCOUNT_SEARCH_REGEX = new RegExp(`(?:\\s|^)(@\\S{${MIN_PREFIX_LENGTH},})$`)
|
const ACCOUNT_SEARCH_REGEX = new RegExp(`(?:\\s|^)(@\\S{${MIN_PREFIX_LENGTH},})$`)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import get from 'lodash-es/get'
|
import { get } from '../../_utils/lodash-lite'
|
||||||
|
|
||||||
function computeForTimeline (store, key, defaultValue) {
|
function computeForTimeline (store, key, defaultValue) {
|
||||||
store.compute(key,
|
store.compute(key,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import pickBy from 'lodash-es/pickBy'
|
import { pickBy, get } from '../../_utils/lodash-lite'
|
||||||
import get from 'lodash-es/get'
|
|
||||||
|
|
||||||
export function timelineMixins (Store) {
|
export function timelineMixins (Store) {
|
||||||
Store.prototype.setForTimeline = function (instanceName, timelineName, obj) {
|
Store.prototype.setForTimeline = function (instanceName, timelineName, obj) {
|
||||||
|
@ -21,11 +20,6 @@ export function timelineMixins (Store) {
|
||||||
return get(root, [instanceName, timelineName])
|
return get(root, [instanceName, timelineName])
|
||||||
}
|
}
|
||||||
|
|
||||||
Store.prototype.getForCurrentTimeline = function (key) {
|
|
||||||
let { currentInstance, currentTimeline } = this.get()
|
|
||||||
return this.getForTimeline(currentInstance, currentTimeline, key)
|
|
||||||
}
|
|
||||||
|
|
||||||
Store.prototype.getAllTimelineData = function (instanceName, key) {
|
Store.prototype.getAllTimelineData = function (instanceName, key) {
|
||||||
let root = this.get()[`timelineData_${key}`] || {}
|
let root = this.get()[`timelineData_${key}`] || {}
|
||||||
return root[instanceName] || {}
|
return root[instanceName] || {}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Some functions from Lodash that are a bit heavyweight and which
|
||||||
|
// we can just do in idiomatic ES2015+
|
||||||
|
|
||||||
|
export function get (obj, keys, defaultValue) {
|
||||||
|
for (let key of keys) {
|
||||||
|
if (obj && key in obj) {
|
||||||
|
obj = obj[key]
|
||||||
|
} else {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
export function pickBy (obj, predicate) {
|
||||||
|
let res = {}
|
||||||
|
for (let [key, value] of Object.entries(obj)) {
|
||||||
|
if (predicate(value, key)) {
|
||||||
|
res[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
|
@ -47,9 +47,7 @@ module.exports = {
|
||||||
/\/_database\/database\.js$/, // this version plays nicer with IDEs
|
/\/_database\/database\.js$/, // this version plays nicer with IDEs
|
||||||
'./database.prod.js'
|
'./database.prod.js'
|
||||||
),
|
),
|
||||||
new LodashModuleReplacementPlugin({
|
new LodashModuleReplacementPlugin(),
|
||||||
paths: true
|
|
||||||
}),
|
|
||||||
new CircularDependencyPlugin({
|
new CircularDependencyPlugin({
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
failOnError: true,
|
failOnError: true,
|
||||||
|
|
Loading…
Reference in New Issue