-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: Refactor lodash #627
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -837,3 +837,28 @@ export function getClosestPageToPinch(x, y, visiblePages) { | |
|
||
return closestPage; | ||
} | ||
|
||
/** | ||
* Simplified lodash.get, this returns the value of a nested property with string path `propPath`. If that property | ||
* does not exist on the object, then return `defaultValue`. | ||
* | ||
* @param {Object} object - Object to fetch property from | ||
* @param {string} propPath - String path to property, e.g. 'b.c' if you are trying to fetch a.b.c | ||
* @param {*} defaultValue - Default value if property is undefined | ||
* @return {*} Value of prop if defined, defaultValue otherwise | ||
*/ | ||
export function getProp(object, propPath, defaultValue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 |
||
let value = object; | ||
const path = propPath.split('.'); | ||
|
||
for (let i = 0; i < path.length; i++) { | ||
if (value == null) { | ||
// Checks against null or undefined | ||
return defaultValue; | ||
} | ||
|
||
value = value[path[i]]; | ||
} | ||
|
||
return value !== undefined ? value : defaultValue; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import EventEmitter from 'events'; | ||
import debounce from 'lodash.debounce'; | ||
import cloneDeep from 'lodash.clonedeep'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import debounce from 'lodash/debounce'; | ||
import fullscreen from '../Fullscreen'; | ||
import RepStatus from '../RepStatus'; | ||
import { | ||
getProp, | ||
appendQueryParams, | ||
appendAuthParams, | ||
getHeaders, | ||
|
@@ -577,14 +578,12 @@ class BaseViewer extends EventEmitter { | |
* | ||
* @protected | ||
* @param {string} option - to get | ||
* @return {Object} Value of a viewer option | ||
* @return {Object|undefined} Value of a viewer option | ||
*/ | ||
getViewerOption(option) { | ||
const { viewers, viewer } = this.options; | ||
if (viewers && viewers[viewer.NAME]) { | ||
return viewers[viewer.NAME][option]; | ||
} | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any chance changing from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked through where we use |
||
const viewerName = getProp(viewer, 'NAME'); | ||
return getProp(viewers, `${viewerName}.${option}`); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4864,18 +4864,14 @@ lodash.camelcase@^4.3.0: | |
version "4.3.0" | ||
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" | ||
|
||
lodash.clonedeep@^4.3.2, lodash.clonedeep@^4.5.0: | ||
lodash.clonedeep@^4.3.2: | ||
version "4.5.0" | ||
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" | ||
|
||
lodash.cond@^4.3.0: | ||
version "4.5.2" | ||
resolved "https://registry.yarnpkg.com/lodash.cond/-/lodash.cond-4.5.2.tgz#f471a1da486be60f6ab955d17115523dd1d255d5" | ||
|
||
lodash.debounce@^4.0.8: | ||
version "4.0.8" | ||
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" | ||
|
||
lodash.get@^3.7.0: | ||
version "3.7.0" | ||
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-3.7.0.tgz#3ce68ae2c91683b281cc5394128303cbf75e691f" | ||
|
@@ -4920,10 +4916,6 @@ lodash.templatesettings@^4.0.0: | |
dependencies: | ||
lodash._reinterpolate "~3.0.0" | ||
|
||
lodash.throttle@^4.1.1: | ||
version "4.1.1" | ||
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4" | ||
|
||
[email protected]: | ||
version "4.0.1" | ||
resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c" | ||
|
@@ -4940,6 +4932,10 @@ lodash@^3.10.1, lodash@^3.8.0: | |
version "3.10.1" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" | ||
|
||
lodash@^4.17.5: | ||
version "4.17.5" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511" | ||
|
||
log-symbols@^1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also use getProp(file, [permissions, operation]) without combined string. Might perform a bit better? Unsure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went to custom lodash.get implementation because lodash.get is 4.8KB un-gzipped.