Last active
April 8, 2023 19:19
-
-
Save naturalwarren/3a7b3d717dd445efe8d4f2a1035e3211 to your computer and use it in GitHub Desktop.
SDUI Base Component Compatibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UIComponent(BaseModel, ABC): | |
# ... | |
def __init__(self, **data) -> None: | |
# SDUIContext is set as a context var when handling any request on the backend | |
current_context = SDUIContext.current() | |
if current_context is not None: | |
# Will raise an error if incompatible | |
current_context.validate_compatibility( | |
self.platform_compatibility() | |
) | |
else: | |
raise MissingContextError(...) | |
# ... | |
@classmethod | |
@abstractmethod | |
def platform_compatibility(cls) -> Dict[Platform, Version]: | |
pass | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment