Skip to content

Commit

Permalink
Do not flatten deep objects
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Nov 9, 2023
1 parent 5c46f44 commit 5d5bcee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 1 addition & 7 deletions src/store/files.js
Expand Up @@ -50,13 +50,7 @@ const mutations = {
}

if (file.fileid >= 0) {
file.metadataPhotosSize = {}
if (file.width && file.height) {
file.metadataPhotosSize.width = file.width
file.metadataPhotosSize.height = file.height
} else {
file.metadataPhotosSize = { width: 256, height: 256 }
}
file.metadataPhotosSize ??= { width: 256, height: 256 }
}

// Make the fileId a string once and for all.
Expand Down
10 changes: 5 additions & 5 deletions src/utils/fileUtils.js
Expand Up @@ -103,7 +103,7 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
* @param {object} obj - object to flatten and format.
*/
function genFileInfo(obj) {
const fileInfo = flattenAndFormatObject(obj, genFileInfo)
const fileInfo = flattenAndFormatObject(obj, flattenAndFormatObject)

if (fileInfo.filename) {
// Adding context
Expand All @@ -117,19 +117,19 @@ function genFileInfo(obj) {
* @param {object} obj - object to flatten and format.
*/
function extractTagInfo(obj) {
return flattenAndFormatObject(obj, extractTagInfo)
return flattenAndFormatObject(obj, flattenAndFormatObject)
}

/**
*
* @param obj
* @param callback
* @param {object} obj
* @param {Function|null} callback
*/
function flattenAndFormatObject(obj, callback) {
return Object.entries(obj).reduce((resultObj, [key, data]) => {
// flatten object if any
if (!!data && typeof data === 'object' && !Array.isArray(data)) {
return { ...resultObj, ...callback(data) }
return { ...resultObj, ...(callback ? callback(data) : { [camelcase(key)]: data }) }
}

// format key and add it to the tagInfo
Expand Down

0 comments on commit 5d5bcee

Please sign in to comment.