Commit 6b356ce
authored
Replace project and version KO views (#532)
This solves a few issues and explores a pattern that we need to figure
out in
order to replace Knockout views with web components: authoring and
connection
between nested web components. This is a low stakes place to try this.
The issues around the buttons were addressed through adding a click
wrapper to
the link. If you accidentally trigger the link before the API response,
the
click event is stored and re-emitted after the response finishes.
The pattern being explored here is using the web component context API.
This is
implemented in Lit already. You can read more here:
- https://lit.dev/docs/data/context/
-
https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md
So far, we have been trying out manually using events to pass around
data at
a global level. The context API functions similar under the hood, but
the API is
a much cleaner way to pass data around, and it functions only between
parent and
child elements, not globally.
Where this differs from global events is that we can use this pattern
between
parent and child elements, and we don't need to manually search the DOM
for the
parent element:
```html
<readthedocs-api url="...">
<div>
<div>
<div>
<readthedocs-item-docs>
This element will traverse up the tree and listen to only the first
readthedocs-api provider
</readthedocs-item-docs>
</div>
</div>
</div>
</readthedocs-api url="...">
<readthedocs-api url="...">
<readthedocs-item-docs>
And this element will only listen for data provided by that second
readthedocs-api provider
</readthedocs-item-docs>
</readthedocs-api>
```
## Why?
We want to author as little as we need to in JS, and as much as we can
in
templates. Using the context API allows us to author isolated web
components
that share data _while still using Django templates for as much of our
page
structure as we can_.
The alternative is authoring everything nested in `readthedocs-api` in a
big
web component, which is not a good pattern for a Django backend.
The work here so far this is a very basic example and the
provider/consumer
elements are close in proximity in the DOM. A more complex example would
be a
table listing, where the table row is a data provider and elements
nested
anywhere in that row element can share data.
We want to keep as much of that row in Django templates as possible,
especially
if that row is 95% vanilla HTML elements and 5% dynamic web components.
----
Things I did not do here:
- Deprecate the older elements using the same base
- Remove old project/version KO views
- Split up code
This will come next.
----
- Fixes #444
- Fixes #4971 parent 7560d81 commit 6b356ce
File tree
12 files changed
+550
-174
lines changed- readthedocsext/theme
- static/readthedocsext/theme
- css
- js
- templates
- builds/partials
- profiles/partials
- projects/partials
- src
- js
- modules
- tests/modules
- sui/themes/rtd-application/elements
12 files changed
+550
-174
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 75 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | 37 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
110 | 70 | | |
111 | | - | |
112 | | - | |
113 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
114 | 74 | | |
115 | 75 | | |
116 | 76 | | |
| |||
Lines changed: 1 addition & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | 7 | | |
14 | 8 | | |
15 | 9 | | |
| |||
Lines changed: 13 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | 32 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
67 | 46 | | |
68 | 47 | | |
69 | 48 | | |
| |||
0 commit comments