-
-
Save Shelob9/2a21abf9283de2005498ecf6d6d07816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ADD_PROCESSOR} from './actions'; | |
/** | |
* Reducer for managing a collection of processors | |
* | |
* State is the processors collection, as a map. | |
* | |
* @param {Object} state | |
* @param {Object} action | |
* @returns {Object} | |
*/ | |
export const processorsReducer = (state = {processors: []}, action) => { | |
switch (action.type) { | |
case ADD_PROCESSOR: | |
return { | |
...state, | |
processors: [...state.processors, action.processor] | |
}; | |
default: | |
return state; | |
} | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A consistent prefix for all actions for this store | |
const CALDERA_FORMS_PROCESSORS_STORE_SLUG = 'CALDERA_FORMS_PROCESSORS_STORE'; | |
/** | |
* The name of the action to add processor to the collection | |
* @type {string} | |
*/ | |
export const ADD_PROCESSOR = `${CALDERA_FORMS_PROCESSORS_STORE_SLUG}/NEW_PROCESSOR`; | |
/** | |
* Creates an action to create a new, empty processor and add it to the collection | |
* @param {Object} processor Processor config | |
* @returns {{type: string, processor: Object}} | |
*/ | |
export const addProcessor = (processor) => { | |
return { | |
type: NEW_PROCESSOR, | |
processor | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getPost = (state,ID) => { | |
return state.posts.find( post => { return ID === post.ID } ); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get one processor from the processors collection reducer processorsReducer | |
* @param {Object} state | |
* @param {String} processorId | |
*/ | |
export const getProcessorFromCollection = (state, processorId) => { | |
if( state.processors.length ){ | |
return state.processor.find( processor => { return processorId === processor.ID } ); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function requestForm(formId) { | |
return await formsAdminApiClient.getForm(formId); | |
}; | |
export const STORE = { | |
selectors: { | |
getForm(state, formId){ | |
return Object.values(forms).find(form => { | |
return formId === form.ID; | |
}); | |
} | |
}, | |
resolvers: { | |
async getForm( state, formId ) { | |
const form = await requestForm(formId); | |
dispatch( CALDERA_FORMS_STORE_NAME ).setForm( form ); | |
}, | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment