From a5875b273fd537328a74eb279303c38cae8b757e Mon Sep 17 00:00:00 2001 From: Kai Moseley Date: Sun, 7 May 2017 18:59:48 +0100 Subject: [PATCH] feat(reducers): Introduce unique id to reducer actions --- src/buildStoreChunk.js | 5 ----- src/reducers.js | 3 +++ src/reducers/arrayReducer.js | 5 +++-- src/reducers/objectReducer.js | 5 +++-- src/reducers/primitiveReducer.js | 5 +++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/buildStoreChunk.js b/src/buildStoreChunk.js index d7eba52..0016b66 100644 --- a/src/buildStoreChunk.js +++ b/src/buildStoreChunk.js @@ -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 //the actions, and selectors as the top level of their respective objects. if (isFunction(structure)) { - console.log(111, processedStructure, { - reducers: processedStructure.reducers, - actions: processedStructure.actions[name], - selectors: processedStructure.selectors[name], - }); return { reducers: processedStructure.reducers, actions: processedStructure.actions[name], diff --git a/src/reducers.js b/src/reducers.js index 36bb74b..3fe4ddb 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -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, { name, locationString, diff --git a/src/reducers/arrayReducer.js b/src/reducers/arrayReducer.js index 1bf7254..86340d7 100644 --- a/src/reducers/arrayReducer.js +++ b/src/reducers/arrayReducer.js @@ -134,11 +134,12 @@ export function createArrayReducer(arrayTypeDescription: ArrayStructureType, { locationString, name, }: ArrayReducerOptions) { + const uniqueId = Math.random().toString(36).substring(5); return { 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}`, {}), }; } diff --git a/src/reducers/objectReducer.js b/src/reducers/objectReducer.js index 0c9b198..2b86e21 100644 --- a/src/reducers/objectReducer.js +++ b/src/reducers/objectReducer.js @@ -81,11 +81,12 @@ export function createShapeReducer(reducerShape: StructureType, { locationString, name, }: ShapeReducerOptions) { + const uniqueId = Math.random().toString(36).substring(5); return { 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}`), }; } diff --git a/src/reducers/primitiveReducer.js b/src/reducers/primitiveReducer.js index c4b49d2..3c06ff5 100644 --- a/src/reducers/primitiveReducer.js +++ b/src/reducers/primitiveReducer.js @@ -69,11 +69,12 @@ export function createPrimitiveReducer(primitiveType: PrimitiveType, { locationString, name, }: PrimitiveReducerOptions) { + const uniqueId = Math.random().toString(36).substring(5); return { 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}`), }; }