Skip to content

Commit 67dc1eb

Browse files
authored
Docs readability enhancements (#189)
- Change docs verbiage on several sections - Recolor the "outdated docs" banner - Add Google Analytics to the docs
1 parent 9973403 commit 67dc1eb

21 files changed

+196
-127
lines changed

LICENSE

-21
This file was deleted.

LICENSE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## The MIT License (MIT)
2+
3+
#### Copyright (c) Reactive Python and affiliates.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

docs/includes/orm.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
Due to Django's ORM design, database queries must be deferred using hooks. Otherwise, you will see a `#!python SynchronousOnlyOperation` exception.
44

5-
These `#!python SynchronousOnlyOperation` exceptions may be resolved in a future version of Django containing an asynchronous ORM. However, it is best practice to always perform ORM calls in the background via hooks.
5+
These `#!python SynchronousOnlyOperation` exceptions may be removed in a future version of Django. However, it is best practice to always perform IO operations (such as ORM queries) via hooks to prevent performance issues.
66

77
<!--orm-excp-end-->
88

99
<!--orm-fetch-start-->
1010

11-
By default, automatic recursive fetching of `#!python ManyToMany` or `#!python ForeignKey` fields is enabled within the default `#!python QueryOptions.postprocessor`. This is needed to prevent `#!python SynchronousOnlyOperation` exceptions when accessing these fields within your ReactPy components.
11+
By default, automatic recursive fetching of `#!python ManyToMany` or `#!python ForeignKey` fields is enabled within the `django_query_postprocessor`. This is needed to prevent `#!python SynchronousOnlyOperation` exceptions when accessing these fields within your ReactPy components.
1212

1313
<!--orm-fetch-end-->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from reactpy import component, html
2+
from reactpy_django.hooks import use_mutation
3+
from reactpy_django.types import MutationOptions
4+
5+
6+
def execute_thread_safe_mutation():
7+
"""This is an example mutation function that does some thread-safe operation."""
8+
pass
9+
10+
11+
@component
12+
def my_component():
13+
item_mutation = use_mutation(
14+
MutationOptions(thread_sensitive=False),
15+
execute_thread_safe_mutation,
16+
)
17+
18+
def submit_event(event):
19+
if event["key"] == "Enter":
20+
item_mutation.execute(text=event["target"]["value"])
21+
22+
if item_mutation.loading or item_mutation.error:
23+
mutation_status = html.h2("Doing something...")
24+
elif item_mutation.error:
25+
mutation_status = html.h2("Error!")
26+
else:
27+
mutation_status = html.h2("Done.")
28+
29+
return html.div(
30+
html.input({"type": "text", "onKeyDown": submit_event}),
31+
mutation_status,
32+
)

docs/python/use-mutation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from reactpy_django.hooks import use_mutation
44

55

6-
def add_item(text: str):
7-
TodoItem(text=text).save()
6+
async def add_item(text: str):
7+
await TodoItem(text=text).asave()
88

99

1010
@component

docs/python/use-query-async.py

-22
This file was deleted.

docs/python/use-query.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from channels.db import database_sync_to_async
12
from example.models import TodoItem
23
from reactpy import component, html
34
from reactpy_django.hooks import use_query
45

56

6-
def get_items():
7-
return TodoItem.objects.all()
7+
async def get_items():
8+
return await database_sync_to_async(TodoItem.objects.all)()
89

910

1011
@component

docs/src/about/license.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
hide:
3+
- toc
4+
---
5+
6+
---
7+
8+
{% include "../../../LICENSE.md" %}

docs/src/assets/css/banner.css

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
body[data-md-color-scheme="slate"] {
2+
--md-banner-bg-color: #4d4121;
3+
--md-banner-font-color: #fff;
4+
}
5+
6+
body[data-md-color-scheme="default"] {
7+
--md-banner-bg-color: #ff9;
8+
--md-banner-font-color: #000;
9+
}
10+
11+
.md-banner--warning {
12+
background-color: var(--md-banner-bg-color);
13+
color: var(--md-banner-font-color);
14+
text-align: center;
15+
}

docs/src/assets/css/footer.css

+4
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@
2727
.legal-footer-right {
2828
float: right;
2929
}
30+
31+
.md-copyright__highlight div {
32+
display: inline;
33+
}

docs/src/dictionary.txt

+1
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ frontends
3737
misconfiguration
3838
misconfigurations
3939
backhaul
40+
sublicense

docs/src/reference/components.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Allows you to defer loading a CSS stylesheet until a component begins rendering.
177177

178178
| Name | Type | Description | Default |
179179
| --- | --- | --- | --- |
180-
| `#!python static_path` | `#!python str` | The path to the static file. This path is identical to what you would use on a `static` template tag. | N/A |
180+
| `#!python static_path` | `#!python str` | The path to the static file. This path is identical to what you would use on Django's `#!jinja {% static %}` template tag. | N/A |
181181
| `#!python key` | `#!python Key | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `#!python None` |
182182

183183
<font size="4">**Returns**</font>
@@ -186,10 +186,6 @@ Allows you to defer loading a CSS stylesheet until a component begins rendering.
186186
| --- | --- |
187187
| `#!python Component` | A ReactPy component. |
188188

189-
??? question "Should I put `#!python django_css` at the top of my HTML?"
190-
191-
Yes, if the stylesheet contains styling for your component.
192-
193189
??? question "Can I load static CSS using `#!python html.link` instead?"
194190

195191
While you can load stylesheets with `#!python html.link`, keep in mind that loading this way **does not** ensure load order. Thus, your stylesheet will be loaded after your component is displayed. This would likely cause unintended visual behavior, so use this at your own discretion.
@@ -204,22 +200,26 @@ Allows you to defer loading a CSS stylesheet until a component begins rendering.
204200

205201
`#!python django_css` can only be used with local static files.
206202

207-
For external CSS, substitute `#!python django_css` with `#!python html.link`.
203+
For external CSS, you should use `#!python html.link`.
208204

209205
```python
210206
{% include "../../python/django-css-external-link.py" %}
211207
```
212208

213209
??? question "Why not load my CSS in `#!html <head>`?"
214210

215-
Traditionally, stylesheets are loaded in your `#!html <head>` using the `#!jinja {% load static %}` template tag.
211+
Traditionally, stylesheets are loaded in your `#!html <head>` using Django's `#!jinja {% static %}` template tag.
216212

217-
To help improve webpage load times, you can use the `#!python django_css` component to defer loading your stylesheet until it is needed.
213+
However, to help improve webpage load times you can use this `#!python django_css` component to defer loading your stylesheet until it is needed.
218214

219215
## Django JS
220216

221217
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/).
222218

219+
!!! warning "Pitfall"
220+
221+
Be mindful of load order! If your JavaScript relies on the component existing on the page, you must place `django_js` at the **bottom** of your component.
222+
223223
=== "components.py"
224224

225225
```python
@@ -232,7 +232,7 @@ Allows you to defer loading JavaScript until a component begins rendering. This
232232

233233
| Name | Type | Description | Default |
234234
| --- | --- | --- | --- |
235-
| `#!python static_path` | `#!python str` | The path to the static file. This path is identical to what you would use on a `static` template tag. | N/A |
235+
| `#!python static_path` | `#!python str` | The path to the static file. This path is identical to what you would use on Django's `#!jinja {% static %}` template tag. | N/A |
236236
| `#!python key` | `#!python Key | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings | `#!python None` |
237237

238238
<font size="4">**Returns**</font>
@@ -241,10 +241,6 @@ Allows you to defer loading JavaScript until a component begins rendering. This
241241
| --- | --- |
242242
| `#!python Component` | A ReactPy component. |
243243

244-
??? question "Should I put `#!python django_js` at the bottom of my HTML?"
245-
246-
Yes, if your scripts are reliant on the contents of the component.
247-
248244
??? question "Can I load static JavaScript using `#!python html.script` instead?"
249245

250246
While you can load JavaScript with `#!python html.script`, keep in mind that loading this way **does not** ensure load order. Thus, your JavaScript will likely be loaded at an arbitrary time after your component is displayed.
@@ -259,14 +255,14 @@ Allows you to defer loading JavaScript until a component begins rendering. This
259255

260256
`#!python django_js` can only be used with local static files.
261257

262-
For external JavaScript, substitute `#!python django_js` with `#!python html.script`.
258+
For external JavaScript, you should use `#!python html.script`.
263259

264260
```python
265261
{% include "../../python/django-js-remote-script.py" %}
266262
```
267263

268264
??? question "Why not load my JS in `#!html <head>`?"
269265

270-
Traditionally, JavaScript is loaded in your `#!html <head>` using the `#!jinja {% load static %}` template tag.
266+
Traditionally, JavaScript is loaded in your `#!html <head>` using Django's `#!jinja {% static %}` template tag.
271267

272-
To help improve webpage load times, you can use the `#!python django_js` component to defer loading your JavaScript until it is needed.
268+
However, to help improve webpage load times you can use this `#!python django_js` component to defer loading your JavaScript until it is needed.

docs/src/reference/decorators.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Decorator functions can be used within your `components.py` to help simplify dev
1010

1111
## Auth Required
1212

13-
You can limit access to a component to users with a specific `#!python auth_attribute` by using this decorator (with or without parentheses).
13+
You can limit component access to users with a specific `#!python auth_attribute` by using this decorator (with or without parentheses).
1414

1515
By default, this decorator checks if the user is logged in and not deactivated (`#!python is_active`).
1616

0 commit comments

Comments
 (0)