-
-
Notifications
You must be signed in to change notification settings - Fork 22
UserModel related hooks, decorators, and settings
#190
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
UserModel related hooks, decorators, and settings
#190
Conversation
UserModel related hooks and decoratorsUserModel related hooks, decorators, and settings
|
@rmorshea I need your opinion on the
from reactpy import component, html
from reactpy_django.hooks import use_user_data
@component
def my_component():
# user_data properties: current, loading, error
# user_data callable attributes: refetch
# set_user_data properties: loading, error
# set_user_data callable attributes: __call__, reset
user_data, set_user_data = use_user_data()
# Here's an example that uses most of the API
async def on_key_press(event):
if event["key"] == "Enter":
# User data is always a dict
merged_data = user_data.current | {uuid4(): event["target"]["value"]}
set_user_data(merged_data)
return html.div(
html.input({"placeholder": "Type some user data here...", "on_key_press": on_key_press}),
html.div(f"Data: {user_data.current}"),
html.div(f"Data Loading: {user_data.loading}"),
html.div(f"Set Data Loading: {set_user_data.loading}"),
html.div(f"Error(s): {user_data.error} {set_user_data.error}"),
)To get the conversation started, here's a few questions/concerns I have:
|
|
I'll try and take a look in the next couple days. |
|
Would you have time to look at the interface proposed in the above comment this weekend? This PR is fairly bulky and has a lot of Django-only jargon, so a PR review won't be needed. |
|
Sure. I'll make time today or tomorrow. |
|
My take is that the marginal UX improvements made by creating special wrappers for the query and mutation objects may be outweighed by requiring the user to learn something new. It seems easier to explain to the user that To address some of the usability concerns in a slightly simpler way, we could consider adding a user_data = use_user_data()
# access data
user_data.query.data
def some_callback():
new_user_data = user_data.query.data | {...}
user_data.mutation(new_user_data) |
|
Agreed, will implement soon. |
Description
Userrelated features!reactpy_django.hooks.use_usercan be used to access the current user.reactpy_django.hooks.use_user_dataprovides a simplified interface for storing user key-value data.reactpy_django.decorators.user_passes_testis inspired by Django'suser_passes_testdecorator, but works with ReactPy components.settings.py:REACTPY_AUTO_RELOGINwill cause component WebSocket connections to automatically re-login users that are already authenticated. This is useful to continuously updatelast_logintimestamps and refresh the Django login session.Checklist:
Please update this checklist as you complete each item:
By submitting this pull request you agree that all contributions comply with this project's open source license(s).