-
Notifications
You must be signed in to change notification settings - Fork 282
Description
If you'd like to discuss your feature idea first with the community (highly recommended!) please visit our Discord channel.
Is your feature request related to a problem? Please describe.
When passing in a custom Mapping it doesn't get detected as attributes. e.g. Div(MyMapping(), "content")
Describe the solution you'd like
Currently the code is using an isinstance(x, dict) check, I'd like to change it to isinstance(x, Mapping) to allow any mapping types.
fasthtml/fasthtml/components.py
Line 87 in ad42bb8
| ds,c = partition(c, risinstance(dict)) |
Example code
# Your example code here
Div(MyMapping(), {'regular': 'dict'}, Span("content"))Similar implementations
If available, provide links to similar features in other libraries:
- htpy allows any Mapping, not just dicts.
Problem solved
Explain what problem this feature would solve and how it would benefit users of the library:
I'm creating a helper for datastar which allows constructing datastar attributes. Ideally this helper is easily usable with multiple html building frameworks. Rather than subclassing a dict, it subclasses Mapping to make things simpler. Currently it has to be used with Fasthtml via unpacking Div(**data.on("click", "console.log('clicked');")) but ideally it would work the same as a dictionary as well. Div(data.on("click", "console.log('clicked');") starfederation/datastar#902
Additional context
Add any other context or screenshots about the feature request here.
Confirmation
Please confirm the following:
- I have checked the existing issues and pull requests to ensure this feature hasn't been requested before.
- I have read the project's documentation to ensure this feature doesn't already exist.