MCPcopy Create free account
hub / github.com/Snapchat/Valdi / detectInteractiveState

Function detectInteractiveState

npm_modules/cli/src/preview/viewModelParser.ts:88–117  ·  view source on GitHub ↗
(props: ParsedProp[])

Source from the content-addressed store, hash-verified

86}
87
88export function detectInteractiveState(props: ParsedProp[]): InteractiveState[] {
89 const boolProps = props.filter(p => p.isBoolean && !p.optional);
90 const callbackProps = props.filter(p => p.isCallback && p.callbackParamType === 'boolean');
91
92 const pairs: InteractiveState[] = [];
93
94 for (const bp of boolProps) {
95 // Look for a callback that takes boolean — common patterns:
96 // on + onTap, selected + onSelect, checked + onChecked, foo + onFoo
97 const candidate = callbackProps.find(cp => {
98 const cpLower = cp.name.toLowerCase();
99 const bpLower = bp.name.toLowerCase();
100 // onTap / onPress / onChange are generic callbacks often paired with the boolean
101 if (['ontap', 'onpress', 'onchange', 'ontoggle'].includes(cpLower)) return true;
102 // onFoo paired with foo
103 if (cpLower === `on${bpLower}`) return true;
104 return false;
105 });
106
107 if (candidate) {
108 pairs.push({
109 stateName: bp.name,
110 boolPropName: bp.name,
111 callbackPropName: candidate.name,
112 });
113 }
114 }
115
116 return pairs;
117}
118
119/**
120 * Generate a sample value expression for a prop type.

Callers 2

generatePreviewTsxFunction · 0.90

Calls 3

filterMethod · 0.80
findMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected