Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 }}

@mixxorz mixxorz enabled auto-merge (squash) November 19, 2022 07:29
@mixxorz mixxorz disabled auto-merge November 19, 2022 07:29
@mixxorz mixxorz merged commit 34efbed into main Nov 19, 2022
@mixxorz mixxorz deleted the feature/props branch November 19, 2022 09:29
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.

1 participant