Skip to content

Commit

Permalink
tabs instead of spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
DreadKnight committed Jan 14, 2023
1 parent 9e4d6d7 commit 905dcba
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions src/assetLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,43 @@ const cache = {};
*/

export function getUrl(path) {
// Convert path to an array if it is a string
if (typeof path === 'string') {
path = path.split('/');
}

// Check if path is empty
if (path.length === 0) {
throw new Error('Path cannot be empty');
}

// Check if the result is already in the cache
const cacheKey = path.join('/');
if (cache[cacheKey]) {
return cache[cacheKey];
}

// prev = children (starts with the assets)
// current = what we are looking at now
const result = path.reduce((prev, current) => {
const entity = prev.find((e) => e.id === current);
if (entity === undefined) {
throw new Error(`Could not find asset with path: ${path.join('/')}`);
}

if (entity.children) {
// If there are still children left, return the children
return entity.children;
} else if (entity.url) {
// When there are no more children left, return the url
return entity.url;
} else {
throw new Error('Entity is of wrong type: ' + entity);
}
}, Assets);

// Add the result to the cache
cache[cacheKey] = result;

return result;
// Convert path to an array if it is a string
if (typeof path === 'string') {
path = path.split('/');
}

// Check if path is empty
if (path.length === 0) {
throw new Error('Path cannot be empty');
}

// Check if the result is already in the cache
const cacheKey = path.join('/');
if (cache[cacheKey]) {
return cache[cacheKey];
}

// prev = children (starts with the assets)
// current = what we are looking at now
const result = path.reduce((prev, current) => {
const entity = prev.find((e) => e.id === current);
if (entity === undefined) {
throw new Error(`Could not find asset with path: ${path.join('/')}`);
}

if (entity.children) {
// If there are still children left, return the children
return entity.children;
} else if (entity.url) {
// When there are no more children left, return the url
return entity.url;
} else {
throw new Error('Entity is of wrong type: ' + entity);
}
}, Assets);

// Add the result to the cache
cache[cacheKey] = result;

return result;
}

1 comment on commit 905dcba

@vercel
Copy link

@vercel vercel bot commented on 905dcba Jan 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.