|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import asyncio |
4 | | -from dataclasses import dataclass |
5 | | -from typing import ( |
6 | | - Any, |
7 | | - Awaitable, |
8 | | - Callable, |
9 | | - DefaultDict, |
10 | | - Generic, |
11 | | - Sequence, |
12 | | - TypeVar, |
13 | | - Union, |
14 | | - cast, |
15 | | -) |
| 4 | +from typing import Any, Awaitable, Callable, DefaultDict, Sequence, Union, cast |
16 | 5 |
|
17 | 6 | from channels.db import database_sync_to_async as _database_sync_to_async |
18 | 7 | from django.db.models.base import Model |
19 | 8 | from django.db.models.query import QuerySet |
20 | 9 | from idom import use_callback, use_ref |
21 | 10 | from idom.backend.types import Location |
22 | 11 | from idom.core.hooks import Context, create_context, use_context, use_effect, use_state |
23 | | -from typing_extensions import ParamSpec |
24 | 12 |
|
25 | | -from django_idom.types import IdomWebsocket |
| 13 | +from django_idom.types import IdomWebsocket, Mutation, Query, _Params, _Result |
26 | 14 |
|
27 | 15 |
|
28 | 16 | database_sync_to_async = cast( |
29 | 17 | Callable[..., Callable[..., Awaitable[Any]]], |
30 | 18 | _database_sync_to_async, |
31 | 19 | ) |
32 | | - |
| 20 | +WebsocketContext: Context[IdomWebsocket | None] = create_context(None) |
33 | 21 | _REFETCH_CALLBACKS: DefaultDict[ |
34 | 22 | Callable[..., Any], set[Callable[[], None]] |
35 | 23 | ] = DefaultDict(set) |
36 | | -WebsocketContext: Context[IdomWebsocket | None] = create_context(None) |
37 | | -_Result = TypeVar("_Result", bound=Union[Model, QuerySet[Any]]) |
38 | | -_Params = ParamSpec("_Params") |
39 | | -_Data = TypeVar("_Data") |
40 | 24 |
|
41 | 25 |
|
42 | 26 | def use_location() -> Location: |
@@ -147,22 +131,6 @@ def reset() -> None: |
147 | 131 | return Mutation(call, loading, error, reset) |
148 | 132 |
|
149 | 133 |
|
150 | | -@dataclass |
151 | | -class Query(Generic[_Data]): |
152 | | - data: _Data |
153 | | - loading: bool |
154 | | - error: Exception | None |
155 | | - refetch: Callable[[], None] |
156 | | - |
157 | | - |
158 | | -@dataclass |
159 | | -class Mutation(Generic[_Params]): |
160 | | - execute: Callable[_Params, None] |
161 | | - loading: bool |
162 | | - error: Exception | None |
163 | | - reset: Callable[[], None] |
164 | | - |
165 | | - |
166 | 134 | def _fetch_deferred(data: Any) -> None: |
167 | 135 | # https://github.com/typeddjango/django-stubs/issues/704 |
168 | 136 | if isinstance(data, QuerySet): # type: ignore[misc] |
|
0 commit comments