| 1 |
import { withSelect, withDispatch } from '@wordpress/data'; |
| 2 |
|
| 3 |
const applyWithSelect = withSelect((select: Function, props: any): any => { |
| 4 |
return { |
| 5 |
metaValue: select('core/editor').getEditedPostAttribute('meta')[ |
| 6 |
props.metaKey |
| 7 |
], |
| 8 |
}; |
| 9 |
}); |
| 10 |
|
| 11 |
const applyWithDispatch = withDispatch( |
| 12 |
(dispatch: Function, props: any): any => { |
| 13 |
return { |
| 14 |
setMetaValue(value: string) { |
| 15 |
dispatch('core/editor').editPost({ meta: { [props.metaKey]: value } }); |
| 16 |
}, |
| 17 |
}; |
| 18 |
} |
| 19 |
); |
| 20 |
|
| 21 |
function apply<T>(el: T): T { |
| 22 |
return applyWithSelect(applyWithDispatch(el)); |
| 23 |
} |
| 24 |
|
| 25 |
export default apply; |
| 26 |
|