-
Notifications
You must be signed in to change notification settings - Fork 63
Conversation
@@ -134,7 +134,7 @@ export const initFilters = () => | |||
checked: false, | |||
})), | |||
}), | |||
{} as Record<FilterCategory, FilterItem> | |||
{} as Filters |
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.
👍
src/stores/search.ts
Outdated
@@ -4,7 +4,9 @@ import { defineStore } from 'pinia' | |||
// https://github.com/WordPress/openverse-frontend/issues/1103 | |||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | |||
// @ts-ignore | |||
import clonedeep from 'lodash.clonedeep' | |||
import { deepclone } from '~/utils/clone' |
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.
We can remove the ts-ignore and the comments on lines 4-6! 🙂
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.
Oops, I removed them from the other one 🤦 Thanks for catching this one!
@@ -0,0 +1,3 @@ | |||
import rfdc from 'rfdc' |
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.
Why do this instead of simply using rfdc
? To be able to add types?
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.
The rfdc
module exports a function by default that you can pass configuration details to. So instead of having to re-create the default clone
function each time, we can just export it from this module. And if we end up needing to change the configuration of how the clone function works, we'll be able to do it in just one place.
@@ -0,0 +1 @@ | |||
export type DeepWriteable<T> = { -readonly [P in keyof T]: DeepWriteable<T[P]> } |
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.
Where can I read on the meaning of -
here? -readonly
?
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.
It's a "mapping modifier": https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#mapping-modifiers
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.
LGTM!
@WordPress/openverse-developers this would be an easy to review PR for anyone on the team, including non-frontend folks, and is an easy win for our bundle size. |
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.
I'm always up for a 4x improvement 😄 one question on naming, but nothing to stop a merge!
src/utils/clone.ts
Outdated
@@ -0,0 +1,3 @@ | |||
import rfdc from 'rfdc' | |||
|
|||
export const deepclone = rfdc() |
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.
Forgive me, I'm not super clear on naming conventions or whether this qualifies 😅 - should this be deepClone
?
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.
I guess! The lodash one was clonedeep so thats why I kept the flattened casing.
aebcf10
to
651a1e7
Compare
Storybook and Tailwind configuration previews: Updating |
Size Change: +8.39 kB (+1%) Total Size: 1.4 MB
ℹ️ View Unchanged
|
Fixes
Fixes #1103 by @sarayourfriend
Description
Compare the bundle sizes:
https://bundlephobia.com/package/lodash.clonedeep@4.5.0
and
https://bundlephobia.com/package/rfdc@1.3.0
Also compare execution speed (from rfdc README):
Literally a 4x improvement on speed and downloaded size over the lodash implementation 🎉
Testing Instructions
Run the app and check that filters in particular are still working as expected.
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin