Skip to content

Commit

Permalink
move reset to processOne
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Oct 3, 2024
1 parent 209676d commit 9838792
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/process/processOne.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { get, set } from "lodash";
import { Component, ProcessorsContext, ProcessorType } from "types";
import { getComponentKey } from "utils/formUtil";
import { resetEphermalState } from "utils";

export function dataValue(component: Component, row: any) {
const key = getComponentKey(component);
return key ? get(row, key) : undefined;
}

export async function processOne<ProcessorScope>(context: ProcessorsContext<ProcessorScope>) {
const { processors } = context;
const { processors, component } = context;
// Create a getter for `value` that is always derived from the current data object
if (typeof context.value === 'undefined') {
Object.defineProperty(context, 'value', {
Expand All @@ -21,6 +22,8 @@ export async function processOne<ProcessorScope>(context: ProcessorsContext<Proc
}
});
}
// If the component has ephermal state, then we need to reset the ephermal state in case this is e.g. a data grid, in which each row needs to be validated independently
resetEphermalState(component);
if (!context.row) {
return;
}
Expand All @@ -33,7 +36,7 @@ export async function processOne<ProcessorScope>(context: ProcessorsContext<Proc
}

export function processOneSync<ProcessorScope>(context: ProcessorsContext<ProcessorScope>) {
const { processors } = context;
const { processors, component } = context;
// Create a getter for `value` that is always derived from the current data object
if (typeof context.value === 'undefined') {
Object.defineProperty(context, 'value', {
Expand All @@ -46,6 +49,8 @@ export function processOneSync<ProcessorScope>(context: ProcessorsContext<Proces
}
});
}
// If the component has ephermal state, then we need to reset the ephermal state in case this is e.g. a data grid, in which each row needs to be validated independently
resetEphermalState(component);
if (!context.row) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/utils/formUtil/eachComponentData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const eachComponentData = (
components,
(component, compPath, componentComponents, compParent) => {
const row = getContextualRowData(component, compPath, data);
resetEphermalState(component);
if (fn(component, data, row, compPath, componentComponents, index, compParent) === true) {
return true;
}
Expand Down
2 changes: 0 additions & 2 deletions src/utils/formUtil/eachComponentDataAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export const eachComponentDataAsync = async (
components,
async (component: any, compPath: string, componentComponents: any, compParent: any) => {
const row = getContextualRowData(component, compPath, data);
// If the component has ephermal state, then we need to reset the ephermal state in case this is e.g. a data grid, in which each row needs to be validated independently
resetEphermalState(component);
if (await fn(component, data, row, compPath, componentComponents, index, compParent) === true) {
return true;
}
Expand Down

0 comments on commit 9838792

Please sign in to comment.