Skip to content

Commit

Permalink
add clearHidden scope keyed by path
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Mar 25, 2024
1 parent ea8c8af commit a56be82
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/process/clearHidden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ import {
ProcessorFnSync
} from "types";

type ClearHiddenScope = ProcessorScope & {
clearHidden: {
[path: string]: boolean;
}
}

/**
* This processor function checks components for the `hidden` property and unsets corresponding data
*/
export const clearHiddenProcess: ProcessorFnSync<ProcessorScope> = (context) => {
const { component, data, path, value } = context;
export const clearHiddenProcess: ProcessorFnSync<ClearHiddenScope> = (context) => {
const { component, data, path, value, scope } = context;
if (component.hidden && value !== undefined && (!component.hasOwnProperty('clearOnHide') || component.clearOnHide)) {
unset(data, path);
scope.clearHidden[path] = true;
}
}

export const clearHiddenProcessInfo: ProcessorInfo<ProcessorContext<ProcessorScope>, void> = {
export const clearHiddenProcessInfo: ProcessorInfo<ProcessorContext<ClearHiddenScope>, void> = {
name: 'clearHidden',
shouldProcess: () => true,
processSync: clearHiddenProcess,
Expand Down

0 comments on commit a56be82

Please sign in to comment.