generated from wrappid/wrappid-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(global): ♻️ made reducer for store builder data
the one builder instance is created is once Ref #54
- Loading branch information
Showing
4 changed files
with
123 additions
and
138 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { AppBuilderData } from "../components/data/app-builder/AppBuilder.data"; | ||
import { DynamicEntity } from "../components/data/app-builder/DynamicEntity.interface"; | ||
import { BuilderState } from "../reducers/builder.reducer"; | ||
import { SET_BUILDER_DATA } from "../types/builder.types"; | ||
|
||
// export const setBuilderData_Case1 = (data: {[key: string]: string}) => (dispatch) => { | ||
// dispatch({ | ||
// payload: data, | ||
// type : BUILDER_DATA_CASE_1 | ||
// }); | ||
// }; | ||
|
||
// export const setBuilderData = (builderData: AppBuilderData, entityData: DynamicEntity) => { | ||
// return { | ||
// payload: { builderData, entityData }, | ||
// type : SET_BUILDER_DATA | ||
// }; | ||
// }; | ||
|
||
// export const setBuilderData = (builderData: AppBuilderData, entityData: DynamicEntity, currentState: BuilderState) => { | ||
// const existingBuilderIndex = currentState.appBuilderData.findIndex( | ||
// (data) => data.builderId === builderData.builderId | ||
// ); | ||
|
||
// let updatedAppBuilderData; | ||
|
||
// if (existingBuilderIndex > -1) { | ||
// // Update existing builderData's entityData | ||
// updatedAppBuilderData = currentState.appBuilderData.map((data, index) => | ||
// index === existingBuilderIndex ? { ...data, entityData } : data | ||
// ); | ||
// } else { | ||
// // Add new builderData to the state | ||
// updatedAppBuilderData = [...currentState.appBuilderData, { ...builderData, entityData }]; | ||
// } | ||
|
||
// return { | ||
// payload: { appBuilderData: updatedAppBuilderData }, | ||
// type : SET_BUILDER_DATA | ||
// }; | ||
// }; | ||
|
||
export const setBuilderData = (builderData: AppBuilderData, entityData: DynamicEntity, currentState: BuilderState) => { | ||
const existingBuilderIndex = currentState.appBuilderData.findIndex( | ||
(data) => data.builderId === builderData.builderId | ||
); | ||
|
||
let updatedAppBuilderData; | ||
|
||
if (existingBuilderIndex > -1) { | ||
// Update existing builderData's entityData using the setter method | ||
updatedAppBuilderData = currentState.appBuilderData.map((data, index) => { | ||
if (index === existingBuilderIndex) { | ||
// Directly update the entityData using the setter | ||
data.setEntityData(entityData); // Use setter to update entityData | ||
} | ||
return data; | ||
}); | ||
} else { | ||
// Add new builderData to the state and set entityData | ||
builderData.setEntityData(entityData); | ||
updatedAppBuilderData = [...currentState.appBuilderData, builderData]; | ||
} | ||
|
||
return { | ||
payload: { appBuilderData: updatedAppBuilderData }, | ||
type : SET_BUILDER_DATA | ||
}; | ||
}; |
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
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
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