Skip to content

Instantly share code, notes, and snippets.

@Shelob9 Shelob9/1.js
Created Jun 28, 2018

Embed
What would you like to do?
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;
}
};
//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
};
};
export const getPost = (state,ID) => {
return state.posts.find( post => { return ID === post.ID } );
};
/**
* 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 } );
}
};
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
You can’t perform that action at this time.