reactive-python / reactpy-django

It's React, but in Python. Now with Django integration.
https://reactive-python.github.io/reactpy-django/
MIT License
322 stars 18 forks source link

Deprecate `QueryOptions` and `MutationOptions` #207

Closed Archmonger closed 2 months ago

Archmonger commented 7 months ago

Ref: https://github.com/reactive-python/reactpy-django/issues/113

Current Situation

use_query and use_mutation currently require QueryOptions and MutationOptions objects to configure their behavior. Adding an extra import just for configuration is pretty annoying.

Proposed Actions

Deprecate QueryOptions and MutationOptions in favor of a different interface.

def use_query(
    query: Callable[FuncParams, Awaitable[Inferred]] | Callable[FuncParams, Inferred],
    args: Sequence | None = None,
    kwargs: MutableMapping | None = None,
    /,
    postprocessor: AsyncPostprocessor | SyncPostprocessor | None = None,
    postprocessor_kwargs: MutableMapping | None = None,
    thread_sensitive: bool = True,
):
    ...

This interface does pose a new challenge. Type hints for args and kwargs will no longer receive auto-complete support due to Python type hint limitations. However, this seems to be worth the trade off. Especially since it's likely this type hint limitation will eventually get resolved.

An alternative is to use unpacking (for example use_query(... , *args, **kwargs)), however, this would result in our configuration options, such as thread_sensitive and postprocessor, stepping into the bounds of **kwargs. As a result, that is unfortunately not a good solution since every config option we add has the potential to break a user application.

Archmonger commented 7 months ago

@rmorshea When you have time can you provide your opinion on this suggested API change?

Will be folding it in to the next major release of ReactPy Django.