From 95573356941fcf93d46d74e2f015805d271b89bb Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 17 Apr 2025 00:04:18 +0200 Subject: [PATCH] MINOR,FEAT: created convenience functions in builder for dev --- src/builder.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/builder.js b/src/builder.js index e1ce5bd..5953e76 100644 --- a/src/builder.js +++ b/src/builder.js @@ -38,6 +38,64 @@ const builder = { } }, + /** + * Pure convenience, mostly to enable jdocs for builder.extensions + * @param {*} unrecognizedComponent + * @returns {Component} + */ + asComponent(unrecognizedComponent) { + if (unrecognizedComponent instanceof Component) { + console.log("Recognized as Component"); + return unrecognizedComponent; + + } else if (unrecognizedComponent instanceof Modifier) { + return unrecognizedComponent.toComponent() + } + console.log("NOT Recognized"); + + return unrecognizedComponent; + }, + + /** + * Pure convenience, mostly to enable jdocs for builder.extensions + * in this case if there is an actual difference as the element being + * a FlexContainerComponent + * @param {*} unrecognizedComponent + * @returns {FlexContainerComponent} + */ + asFlexContainerComponent(unrecognizedComponent) { + if (unrecognizedComponent instanceof FlexContainerComponent) { + console.log("Recognized as FlexContainerComponent"); + return unrecognizedComponent; + + } else if (unrecognizedComponent instanceof Modifier) { + return unrecognizedComponent.toComponent() + } + console.log("NOT Recognized"); + + return unrecognizedComponent; + }, + + /** + * Pure convenience, mostly to enable jdocs for builder.extensions + * in this case if there is an actual difference as the element being + * an InputComponent + * @param {*} unrecognizedComponent + * @returns {InputComponent} + */ + asInputComponent(unrecognizedComponent) { + if (unrecognizedComponent instanceof InputComponent) { + console.log("Recognized as InputComponent"); + return unrecognizedComponent; + + } else if (unrecognizedComponent instanceof Modifier) { + return unrecognizedComponent.toComponent() + } + console.log("NOT Recognized"); + + return unrecognizedComponent; + }, + /** * * @param {string} htmlText