WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.52k stars 4.21k forks source link

Consolidate common utils functions across the repo #54407

Open matiasbenedetto opened 1 year ago

matiasbenedetto commented 1 year ago

What?

There are several common util functions, that are repeated across the repo that could, and probably should be consolidated. One example of this is the functions that previously were imported from lodash package.

Why?

To avoid code repetition, reduce the bundle size, and reduce the potential error surface.

To optimize the bundle size, lodash was removed from Gutenberg but no alternative was provided for functions like _.get() or _.set(). For that reason, we have similar functions (example: search for getNestedValue() or setNestedValue()) across the repo that could be consolidated in one package that can be imported and reused by other modules.

More context

See this comment as example: https://github.com/WordPress/gutenberg/pull/54161#discussion_r1321492693

tyxla commented 1 year ago

Thanks for bringing it up, @matiasbenedetto!

One more existing example that we should consolidate is getValueFromObjectPath(), and perhaps setImmutably().