feat(reducers): Introduce unique id to reducer actions

This commit is contained in:
Kai Moseley 2017-05-07 18:59:48 +01:00
parent 231fd8bd53
commit a5875b273f
5 changed files with 12 additions and 11 deletions

View File

@ -48,11 +48,6 @@ export function buildStoreChunk(name: string, structure: any, {
//at the top level. If the structure is a function (i.e. not nested reducers) then return //at the top level. If the structure is a function (i.e. not nested reducers) then return
//the actions, and selectors as the top level of their respective objects. //the actions, and selectors as the top level of their respective objects.
if (isFunction(structure)) { if (isFunction(structure)) {
console.log(111, processedStructure, {
reducers: processedStructure.reducers,
actions: processedStructure.actions[name],
selectors: processedStructure.selectors[name],
});
return { return {
reducers: processedStructure.reducers, reducers: processedStructure.reducers,
actions: processedStructure.actions[name], actions: processedStructure.actions[name],

View File

@ -52,6 +52,9 @@ export const REDUCER_CREATOR_MAPPING: { [key: PropTypeKeys]: any } = {
}; };
export const createUniqueString = Math.random().toString(36).substring(7);
export function determineReducerType(reducerDescriptor: ReducerType, { export function determineReducerType(reducerDescriptor: ReducerType, {
name, name,
locationString, locationString,

View File

@ -134,11 +134,12 @@ export function createArrayReducer(arrayTypeDescription: ArrayStructureType, {
locationString, locationString,
name, name,
}: ArrayReducerOptions) { }: ArrayReducerOptions) {
const uniqueId = Math.random().toString(36).substring(5);
return { return {
reducers: { reducers: {
[name]: createReducer(arrayTypeDescription, createReducerBehaviors(DEFAULT_ARRAY_BEHAVIORS, locationString)) [name]: createReducer(arrayTypeDescription, createReducerBehaviors(DEFAULT_ARRAY_BEHAVIORS, `${uniqueId}-${locationString}`))
}, },
actions: createActions(DEFAULT_ARRAY_BEHAVIORS, locationString, {}), actions: createActions(DEFAULT_ARRAY_BEHAVIORS, `${uniqueId}-${locationString}`, {}),
}; };
} }

View File

@ -81,11 +81,12 @@ export function createShapeReducer(reducerShape: StructureType, {
locationString, locationString,
name, name,
}: ShapeReducerOptions) { }: ShapeReducerOptions) {
const uniqueId = Math.random().toString(36).substring(5);
return { return {
reducers: { reducers: {
[name]: createReducer(reducerShape, createReducerBehaviors(DEFAULT_SHAPE_BEHAVIORS, locationString)), [name]: createReducer(reducerShape, createReducerBehaviors(DEFAULT_SHAPE_BEHAVIORS, `${uniqueId}-${locationString}`)),
}, },
actions: createActions(DEFAULT_SHAPE_BEHAVIORS, locationString), actions: createActions(DEFAULT_SHAPE_BEHAVIORS, `${uniqueId}-${locationString}`),
}; };
} }

View File

@ -69,11 +69,12 @@ export function createPrimitiveReducer(primitiveType: PrimitiveType, {
locationString, locationString,
name, name,
}: PrimitiveReducerOptions) { }: PrimitiveReducerOptions) {
const uniqueId = Math.random().toString(36).substring(5);
return { return {
reducers: { reducers: {
[name]: createReducer(primitiveType, createReducerBehaviors(DEFAULT_PRIMITIVE_BEHAVIORS, locationString)), [name]: createReducer(primitiveType, createReducerBehaviors(DEFAULT_PRIMITIVE_BEHAVIORS, `${uniqueId}-${locationString}`)),
}, },
actions: createActions(DEFAULT_PRIMITIVE_BEHAVIORS, locationString), actions: createActions(DEFAULT_PRIMITIVE_BEHAVIORS, `${uniqueId}-${locationString}`),
}; };
} }