Add createTypes function

This commit is contained in:
Berkeley Martinez
2016-03-03 18:56:18 -08:00
parent 2df87854c4
commit 4ef15109cd
4 changed files with 22 additions and 20 deletions

View File

@ -1,4 +1,6 @@
const types = [ import createTypes from '../utils/create-types';
export default createTypes([
'updateTitle', 'updateTitle',
'fetchUser', 'fetchUser',
@ -9,8 +11,4 @@ const types = [
'handleError', 'handleError',
// used to hit the server // used to hit the server
'hardGoTo' 'hardGoTo'
]; ], 'app');
export default types
// make into object with signature { type: nameSpace[type] };
.reduce((types, type) => ({ ...types, [type]: `app.${type}` }), {});

View File

@ -1,4 +1,6 @@
const types = [ import createTypes from '../../../utils/create-types';
export default createTypes([
'fetchHikes', 'fetchHikes',
'fetchHikesCompleted', 'fetchHikesCompleted',
'resetHike', 'resetHike',
@ -19,9 +21,4 @@ const types = [
'hikeCompleted', 'hikeCompleted',
'goToNextHike' 'goToNextHike'
]; ], 'videos');
export default types.reduce((types, type) => {
types[type] = `videos.${type}`;
return types;
}, {});

View File

@ -1,4 +1,6 @@
const types = [ import createTypes from '../../../utils/create-types';
export default createTypes([
'fetchJobs', 'fetchJobs',
'fetchJobsCompleted', 'fetchJobsCompleted',
@ -17,9 +19,4 @@ const types = [
'updatePromo', 'updatePromo',
'applyPromo', 'applyPromo',
'applyPromoCompleted' 'applyPromoCompleted'
]; ], 'jobs');
export default types.reduce((types, type) => {
types[type] = `jobs.${type}`;
return types;
}, {});

View File

@ -0,0 +1,10 @@
// createTypes(types: String[], prefix: String) => Object
export default function createTypes(types = [], prefix = '') {
if (!Array.isArray(types) || typeof prefix !== 'string') {
return {};
}
return types.reduce((types, type) => {
types[type] = prefix + '.' + type;
return types;
}, {});
}