Your IP : 216.73.216.1


Current Path : /proc/self/cwd/wp-content/plugins/leadin/scripts/utils/
Upload File :
Current File : //proc/self/cwd/wp-content/plugins/leadin/scripts/utils/withMetaData.ts

import { withSelect, withDispatch } from '@wordpress/data';

const applyWithSelect = withSelect((select: Function, props: any): any => {
  return {
    metaValue: select('core/editor').getEditedPostAttribute('meta')[
      props.metaKey
    ],
  };
});

const applyWithDispatch = withDispatch(
  (dispatch: Function, props: any): any => {
    return {
      setMetaValue(value: string) {
        dispatch('core/editor').editPost({ meta: { [props.metaKey]: value } });
      },
    };
  }
);

function apply<T>(el: T): T {
  return applyWithSelect(applyWithDispatch(el));
}

export default apply;