Skip to content

Commit 276f962

Browse files
authored
Hook Cleanup (#101)
- Allow `use_mutation` to have `refetch=None`, as the docs suggest is possible. - `use_origin` hook to return the browser's `location.origin` - Fix flaky `test_use_query_and_mutation` test (Key presses require at least 100ms between `keyup`/`keydown` on GH actions) - Logging for `use_mutation`/`use_query` errors (currently silent, which is very hard to debug) - Document `use_mutation`'s `reset()` - Document `use_query` requires a `Model` or `QuerySet` return (due to enforcing no lazy queries) - Document interface on all APIs - Documentation misc cleanup and styling
1 parent 78823ee commit 276f962

File tree

23 files changed

+680
-312
lines changed

23 files changed

+680
-312
lines changed

CHANGELOG.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,18 @@ Using the following categories, list your changes in this order:
2222

2323
## [Unreleased]
2424

25-
- Nothing (Yet)
25+
### Added
26+
27+
- `use_origin` hook to return the browser's `location.origin`.
28+
29+
### Changed
30+
31+
- `use_mutation` and `use_query` will now log any query failures.
32+
33+
### Fixed
34+
35+
- Allow `use_mutation` to have `refetch=None`, as the docs suggest is possible.
36+
- `use_query` will now prefetch all fields to prevent `SynchronousOnlyOperation` exceptions.
2637

2738
## [1.2.0] - 2022-09-19
2839

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You'll need a file to define your [IDOM](https://github.com/idom-team/idom) comp
3030
<!--py-header-end-->
3131
<!--py-code-start-->
3232

33-
```python title="components.py"
33+
```python linenums="1"
3434
from idom import component, html
3535

3636
@component
@@ -51,7 +51,7 @@ Additonally, you can pass in keyword arguments into your component function. For
5151
<!--html-header-end-->
5252
<!--html-code-start-->
5353

54-
```jinja title="my-template.html"
54+
```jinja linenums="1"
5555
{% load idom %}
5656
<!DOCTYPE html>
5757
<html>

docs/includes/examples.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--hello-world-view-start-->
22

3-
```python
3+
```python linenums="1"
44
from django.http import HttpResponse
55

66
def hello_world_view(request, *args, **kwargs):
@@ -11,7 +11,7 @@ def hello_world_view(request, *args, **kwargs):
1111

1212
<!--hello-world-cbv-start-->
1313

14-
```python
14+
```python linenums="1"
1515
from django.http import HttpResponse
1616
from django.views import View
1717

@@ -20,4 +20,15 @@ class HelloWorldView(View):
2020
return HttpResponse("Hello World!")
2121
```
2222

23-
<!--hello-world-cbv-end-->
23+
<!--hello-world-cbv-end-->
24+
25+
<!--todo-model-start-->
26+
27+
```python linenums="1"
28+
from django.db import models
29+
30+
class TodoItem(models.Model):
31+
text = models.CharField(max_length=255)
32+
```
33+
34+
<!--todo-model-end-->
File renamed without changes.

docs/src/features/components.md

+67-31
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
???+ summary
2+
3+
Prefabricated components can be used within your `components.py` to help simplify development.
4+
15
## View To Component
26

37
Convert any Django view into a IDOM component by usng this decorator. Compatible with sync/async [Function Based Views](https://docs.djangoproject.com/en/dev/topics/http/views/) and [Class Based Views](https://docs.djangoproject.com/en/dev/topics/class-based-views/).
48

59
=== "components.py"
610

7-
```python
11+
```python linenums="1"
812
from idom import component, html
913
from django_idom.components import view_to_component
1014
from .views import hello_world_view
@@ -47,7 +51,7 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
4751

4852
=== "components.py"
4953

50-
```python
54+
```python linenums="1"
5155
from idom import component, html
5256
from django_idom.components import view_to_component
5357
from .views import HelloWorldView
@@ -69,7 +73,7 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
6973

7074
=== "components.py"
7175

72-
```python
76+
```python linenums="1"
7377
from idom import component, html
7478
from django_idom.components import view_to_component
7579
from .views import hello_world_view
@@ -99,7 +103,7 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
99103

100104
=== "components.py"
101105

102-
```python
106+
```python linenums="1"
103107
from idom import component, html
104108
from django_idom.components import view_to_component
105109
from .views import hello_world_view
@@ -125,7 +129,7 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
125129

126130
=== "components.py"
127131

128-
```python
132+
```python linenums="1"
129133
from idom import component, html
130134
from django_idom.components import view_to_component
131135
from .views import hello_world_view
@@ -153,7 +157,7 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
153157

154158
=== "components.py"
155159

156-
```python
160+
```python linenums="1"
157161
from idom import component, html
158162
from django_idom.components import view_to_component
159163
from .views import hello_world_view
@@ -174,7 +178,7 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
174178

175179
=== "views.py"
176180

177-
```python
181+
```python linenums="1"
178182
from django.http import HttpResponse
179183

180184
def hello_world_view(request, *args, **kwargs):
@@ -185,17 +189,33 @@ Convert any Django view into a IDOM component by usng this decorator. Compatible
185189

186190
Allows you to defer loading a CSS stylesheet until a component begins rendering. This stylesheet must be stored within [Django's static files](https://docs.djangoproject.com/en/dev/howto/static-files/).
187191

188-
```python title="components.py"
189-
from idom import component, html
190-
from django_idom.components import django_css
192+
=== "components.py"
193+
194+
```python linenums="1"
195+
from idom import component, html
196+
from django_idom.components import django_css
197+
198+
@component
199+
def my_component():
200+
return html.div(
201+
django_css("css/buttons.css"),
202+
html.button("My Button!"),
203+
)
204+
```
191205

192-
@component
193-
def my_component():
194-
return html.div(
195-
django_css("css/buttons.css"),
196-
html.button("My Button!"),
197-
)
198-
```
206+
??? example "See Interface"
207+
208+
<font size="4">**Parameters**</font>
209+
210+
| Name | Type | Description | Default |
211+
| --- | --- | --- | --- |
212+
| static_path | `str` | The path to the static file. This path is identical to what you would use on a `static` template tag. | N/A |
213+
214+
<font size="4">**Returns**</font>
215+
216+
| Type | Description |
217+
| --- | --- |
218+
| `Component` | An IDOM component. |
199219

200220
??? question "Should I put `django_css` at the top of my component?"
201221

@@ -207,7 +227,7 @@ def my_component():
207227

208228
Here's an example on what you should avoid doing for Django static files:
209229

210-
```python
230+
```python linenums="1"
211231
from idom import component, html
212232
from django.templatetags.static import static
213233

@@ -225,7 +245,7 @@ def my_component():
225245

226246
For external CSS, substitute `django_css` with `html.link`.
227247

228-
```python
248+
```python linenums="1"
229249
from idom import component, html
230250

231251
@component
@@ -246,17 +266,33 @@ def my_component():
246266

247267
Allows you to defer loading JavaScript until a component begins rendering. This JavaScript must be stored within [Django's static files](https://docs.djangoproject.com/en/dev/howto/static-files/).
248268

249-
```python title="components.py"
250-
from idom import component, html
251-
from django_idom.components import django_js
269+
=== "components.py"
270+
271+
```python linenums="1"
272+
from idom import component, html
273+
from django_idom.components import django_js
274+
275+
@component
276+
def my_component():
277+
return html.div(
278+
html.button("My Button!"),
279+
django_js("js/scripts.js"),
280+
)
281+
```
252282

253-
@component
254-
def my_component():
255-
return html.div(
256-
html.button("My Button!"),
257-
django_js("js/scripts.js"),
258-
)
259-
```
283+
??? example "See Interface"
284+
285+
<font size="4">**Parameters**</font>
286+
287+
| Name | Type | Description | Default |
288+
| --- | --- | --- | --- |
289+
| static_path | `str` | The path to the static file. This path is identical to what you would use on a `static` template tag. | N/A |
290+
291+
<font size="4">**Returns**</font>
292+
293+
| Type | Description |
294+
| --- | --- |
295+
| `Component` | An IDOM component. |
260296

261297
??? question "Should I put `django_js` at the bottom of my component?"
262298

@@ -268,7 +304,7 @@ def my_component():
268304

269305
Here's an example on what you should avoid doing for Django static files:
270306

271-
```python
307+
```python linenums="1"
272308
from idom import component, html
273309
from django.templatetags.static import static
274310

@@ -286,7 +322,7 @@ def my_component():
286322

287323
For external JavaScript, substitute `django_js` with `html.script`.
288324

289-
```python
325+
```python linenums="1"
290326
from idom import component, html
291327

292328
@component

0 commit comments

Comments
 (0)