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

Lines changed: 0 additions & 21 deletions
This file was deleted.

LICENSE.md

Lines changed: 9 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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-->
Lines changed: 32 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/python/use-query.py

Lines changed: 3 additions & 2 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 15 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)