actions.js
2 years ago
constants.js
2 years ago
dispatchers.js
2 years ago
getPreparedBlocks.js
2 years ago
index.js
2 years ago
reducer.js
2 years ago
selectors.js
2 years ago
actions.js
33 lines
| 1 | import constants from './constants'; |
| 2 | import getPreparedBlocks from './getPreparedBlocks'; |
| 3 | import { storeName } from './index'; |
| 4 | |
| 5 | const { |
| 6 | select, |
| 7 | dispatch, |
| 8 | } = wp.data; |
| 9 | |
| 10 | export default { |
| 11 | setBlocks( action = null ) { |
| 12 | if ( null === action ) { |
| 13 | action = getPreparedBlocks(); |
| 14 | } |
| 15 | |
| 16 | const hasExecuted = select( storeName ).isExecuted(); |
| 17 | |
| 18 | if ( !hasExecuted ) { |
| 19 | dispatch( storeName ).toggleExecute(); |
| 20 | } |
| 21 | |
| 22 | return { |
| 23 | type: hasExecuted ? constants.setBlocks : constants.setBlocksFirst, |
| 24 | blocks: action.blocks, |
| 25 | blockMap: action.blockMap, |
| 26 | }; |
| 27 | }, |
| 28 | toggleExecute() { |
| 29 | return { |
| 30 | type: constants.toggleExecute, |
| 31 | }; |
| 32 | }, |
| 33 | }; |