actions.js
2 years ago
getters.js
2 years ago
index.js
2 years ago
mutations.js
2 years ago
state.js
2 years ago
getters.js
36 lines
| 1 | const { __ } = wp.i18n; |
| 2 | |
| 3 | const getters = { |
| 4 | getAction: state => id => { |
| 5 | return state.actionsList.find( action => id === action.value ); |
| 6 | }, |
| 7 | actionsList: state => { |
| 8 | return state.actionsList; |
| 9 | }, |
| 10 | currentAction: state => { |
| 11 | return state.currentAction; |
| 12 | }, |
| 13 | getActionPromise: state => { |
| 14 | let { action, payload = [] } = state.currentProcess; |
| 15 | |
| 16 | if ( 'function' !== typeof state.actionsPromises[ action ] ) { |
| 17 | throw new Error( __( 'Please choose your action', 'jet-form-builder' ) ); |
| 18 | } |
| 19 | const promise = state.actionsPromises[ action ] ?? false; |
| 20 | |
| 21 | return () => new Promise( ( resolve, reject ) => promise( resolve, reject, ...payload ) ) |
| 22 | }, |
| 23 | processContext: state => { |
| 24 | return state.currentProcess.context; |
| 25 | }, |
| 26 | currentProcess: state => { |
| 27 | return state.currentProcess; |
| 28 | }, |
| 29 | }; |
| 30 | |
| 31 | export default { |
| 32 | ...getters, |
| 33 | getCurrentAction: state => { |
| 34 | return getters.getAction( state )( state.currentAction ); |
| 35 | }, |
| 36 | }; |