Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prop types, runtime type checking, and component code #25

Merged
merged 22 commits into from Nov 19, 2022
Merged

Conversation

mixxorz
Copy link
Owner

@mixxorz mixxorz commented Nov 1, 2022

This PR:

  • Adds a way to define prop types
  • Adds a way to define default values for props
  • Adds optional runtime type checking
  • Adds a way to add custom Python code to components

Example component:

---
props.types = {
    'required_string': str,
    'optional_number': Optional[int],
    'default_number': int,
}
props.defaults = {
    'default_number': 10,
}

# Arbitrary Python code that adds variables to the template context
props['new_number'] = props['default_number'] * 2

# props['default_number'] will return 10 if `default_number` is not passed to the component.
---

The context contains:

Required string: {{ required_string }}
Optional number: {{ optional_number }}
Default number: {{ default_number }}
New number: {{ new_number }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant