Skip to content
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

192 wc editor create two way sync for the post metadata #21398

Draft
wants to merge 12 commits into
base: feature/woo-new-editor
Choose a base branch
from
Next Next commit
Add createCollectorFromObject
Already added in PoC and in decouple hidden fields (with tests!!)
There should not be any difference in the code itself
  • Loading branch information
igorschoester committed Apr 23, 2024
commit 85f983b924c62cf709a8f2f6adcac33731c6b024
19 changes: 18 additions & 1 deletion packages/js/src/helpers/create-watcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clone, isEqual } from "lodash";
import { clone, isEqual, reduce } from "lodash";

/**
* Creates a getter for an array of getters.
Expand Down Expand Up @@ -40,4 +40,21 @@ const createWatcher = ( getData, onChange ) => {
};
};

/**
* Creates a getter for an object of getters.
*
* Use this if you want to combine getData functions.
*
* @param {Object<string, function>} getters The getters.
* @returns {function} The combined getter.
*/
export const createCollectorFromObject = ( getters ) => () => reduce(
getters,
( result, getData, key ) => {
result[ key ] = getData();
return result;
},
{}
);

export default createWatcher;