@revenuecat/purchases-ui-js
Version:
Web components for Paywalls. Powered by RevenueCat
32 lines (31 loc) • 1.28 kB
JavaScript
export const hasComponentOfTypeInSubtree = (stack, componentType) => {
return (stack.components.some((component) => componentHasTypeInSubtree(component, componentType)) ||
(stack.badge?.stack
? hasComponentOfTypeInSubtree(stack.badge.stack, componentType)
: false));
};
const componentHasTypeInSubtree = (component, componentType) => {
if (component.type === componentType) {
return true;
}
if (component.fallback &&
componentHasTypeInSubtree(component.fallback, componentType)) {
return true;
}
switch (component.type) {
case "carousel":
return component.pages.some((page) => hasComponentOfTypeInSubtree(page, componentType));
case "package":
case "purchase_button":
case "tab":
case "tab_control_button":
return hasComponentOfTypeInSubtree(component.stack, componentType);
case "stack":
return hasComponentOfTypeInSubtree(component, componentType);
case "tabs":
return (hasComponentOfTypeInSubtree(component.control.stack, componentType) ||
component.tabs.some((tab) => hasComponentOfTypeInSubtree(tab.stack, componentType)));
default:
return false;
}
};