Skip to content

Commit 2e16b61

Browse files
committed
add sections for working with dicts and lists
still need more content there
1 parent e945d5b commit 2e16b61

File tree

10 files changed

+241
-20
lines changed

10 files changed

+241
-20
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# IDOM · [![Tests](https://github.com/idom-team/idom/workflows/Test/badge.svg?event=push)](https://github.com/idom-team/idom/actions?query=workflow%3ATest) [![PyPI Version](https://img.shields.io/pypi/v/idom.svg)](https://pypi.python.org/pypi/idom) [![License](https://img.shields.io/badge/License-MIT-purple.svg)](https://github.com/idom-team/idom/blob/main/LICENSE)
22

3-
IDOM is a Python package for making user interfaces. These interfaces are built from
4-
small elements of functionality like buttons text and images. IDOM allows you to combine
5-
these elements into reusable "components" that can be composed together to create
6-
complex views.
3+
IDOM is a Python web framework for building **interactive websites without needing a
4+
single line of Javascript**. These sites are built from small elements of functionality
5+
like buttons text and images. IDOM allows you to combine these elements into reusable
6+
"components" that can be composed together to create complex views.
77

88
Ecosystem independence is also a core feature of IDOM. It can be added to existing
99
applications built on a variety of sync and async web servers, as well as integrated

docs/source/_static/css/sphinx-design-overrides.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ body {
1717
max-height: 700px;
1818
overflow: auto;
1919
}
20+
21+
.sd-card-title .sd-badge {
22+
font-size: 1em;
23+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from idom import component, html, run, use_state
2+
3+
4+
@component
5+
def Form():
6+
person, set_person = use_state(
7+
{
8+
"first_name": "Barbara",
9+
"last_name": "Hepworth",
10+
"email": "[email protected]",
11+
}
12+
)
13+
14+
def handle_first_name_change(event):
15+
set_person({**person, "first_name": event["target"]["value"]})
16+
17+
def handle_last_name_change(event):
18+
set_person({**person, "last_name": event["target"]["value"]})
19+
20+
def handle_email_change(event):
21+
set_person({**person, "email": event["target"]["value"]})
22+
23+
return html.div(
24+
html.label(
25+
"First name: ",
26+
html.input(
27+
{"value": person["first_name"], "onChange": handle_first_name_change},
28+
),
29+
),
30+
html.label(
31+
"First name: ",
32+
html.input(
33+
{"value": person["last_name"], "onChange": handle_last_name_change},
34+
),
35+
),
36+
html.label(
37+
"First name: ",
38+
html.input(
39+
{"value": person["email"], "onChange": handle_email_change},
40+
),
41+
),
42+
html.p(f"{person['first_name']} {person['last_name']} {person['email']}"),
43+
)
44+
45+
46+
run(Form)

docs/source/adding-interactivity/dangers-of-mutability/index.rst

Lines changed: 181 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,199 @@ you touch or hover over the preview:
119119
depends on it. This is called a “local mutation.” You can even do local mutation
120120
while rendering. Very convenient and completely okay!
121121

122-
Python provides a number of mutable built in data types:
123122

124-
- :ref:`Dictionaries <working with dictionaries>`
125-
- :ref:`Lists <working with lists>`
126-
- :ref:`Sets <working with sets>`
123+
Working with Dictionaries
124+
-------------------------
127125

128-
Below we suggest a number of strategies for safely working with these types...
126+
Below are some operations to :bdg-danger:`avoid` and stragies to :bdg-info:`prefer` when
127+
working with dictionaries...
129128

130129

131-
Working with Dictionaries
132-
-------------------------
130+
Updating Dictionary Items
131+
.........................
132+
133+
.. grid:: 1 1 2 2
134+
:gutter: 1
135+
136+
.. grid-item-card:: :bdg-danger:`Avoid`
137+
138+
.. code-block::
139+
140+
d["key"] = value
141+
142+
d.update(key=value)
143+
144+
d.setdefault("key", value)
145+
146+
.. grid-item-card:: :bdg-info:`Prefer`
147+
148+
.. code-block::
149+
150+
{**d, "key": value}
151+
152+
# Python >= 3.9
153+
d | {"key": value}
154+
155+
# Equivalent to setdefault()
156+
{"key": value, **d}
157+
158+
159+
Removing Dictionary Items
160+
.........................
161+
162+
.. grid:: 1 1 2 2
163+
:gutter: 1
164+
165+
.. grid-item-card:: :bdg-danger:`Avoid`
166+
167+
.. code-block::
168+
169+
d["key"] = value
170+
171+
d.update(key=value)
133172
134-
There are a number of different ways to idiomatically construct dictionaries
173+
d.setdefault("key", value)
174+
175+
.. grid-item-card:: :bdg-info:`Prefer`
176+
177+
.. code-block::
178+
179+
{
180+
k: v
181+
for k, v in d.items()
182+
if k != "key"
183+
}
135184
136185
137186
Working with Lists
138187
------------------
139188

189+
Below are some operations to :bdg-danger:`avoid` and stragies to :bdg-info:`prefer` when
190+
working with lists...
191+
192+
193+
Replacing List Items
194+
....................
195+
196+
.. grid:: 1 1 2 2
197+
198+
.. grid-item-card:: :bdg-danger:`Avoid`
199+
200+
.. code-block::
201+
202+
l[index] = value
203+
204+
l[start:end] = values
205+
206+
.. grid-item-card:: :bdg-info:`Prefer`
207+
208+
.. code-block::
209+
210+
l[:index] + [value] + l[index + 1:]
211+
212+
l[:start] + values + l[end + 1:]
213+
214+
215+
Inserting List Items
216+
....................
217+
218+
.. grid:: 1 1 2 2
219+
220+
.. grid-item-card:: :bdg-danger:`Avoid`
221+
222+
.. code-block::
223+
224+
l.append(value)
225+
226+
l.extend(values)
227+
228+
l.insert(index, value)
229+
230+
.. grid-item-card:: :bdg-info:`Prefer`
231+
232+
.. code-block::
233+
234+
l + [value]
235+
236+
l + values
237+
238+
l[:index] + [value] + l[index:]
239+
240+
241+
Removing List Items
242+
...................
243+
244+
.. grid:: 1 1 2 2
245+
246+
.. grid-item-card:: :bdg-danger:`Avoid`
247+
248+
.. code-block::
249+
250+
del l[index]
251+
252+
l.pop(index)
253+
254+
l.clear()
255+
256+
.. grid-item-card:: :bdg-info:`Prefer`
257+
258+
.. code-block::
259+
260+
l[:index - 1] + l[index:]
261+
262+
[]
263+
264+
265+
Re-ordering List Items
266+
......................
267+
268+
.. grid:: 1 1 2 2
269+
270+
.. grid-item-card:: :bdg-danger:`Avoid`
271+
272+
.. code-block::
273+
274+
l.sort()
275+
276+
l.reverse()
277+
278+
.. grid-item-card:: :bdg-info:`Prefer`
279+
280+
.. code-block::
281+
282+
list(sorted(l))
283+
284+
list(reversed(l))
285+
140286
141287
Working with Sets
142288
-----------------
143289

290+
Below are some operations to :bdg-danger:`avoid` and stragies to :bdg-info:`prefer` when
291+
working with sets...
292+
293+
Ading Set Items
294+
...............
295+
296+
.. grid:: 1 1 2 2
297+
298+
.. grid-item-card:: :bdg-danger:`Avoid`
299+
300+
.. code-block::
301+
302+
l[index] = value
303+
304+
l[start:end] = values
305+
306+
.. grid-item-card:: :bdg-info:`Prefer`
307+
308+
.. code-block::
309+
310+
l[:index] + [value] + l[index + 1:]
311+
312+
l[:start] + values + l[end + 1:]
313+
314+
315+
Useful Packages
316+
---------------
144317

145-
Working with Nested Data
146-
------------------------

docs/source/adding-interactivity/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Adding Interactivity
1616
:animate: fade-in
1717
:open:
1818

19-
.. grid:: 2
19+
.. grid:: 1 1 2 2
2020

2121
.. grid-item-card:: :octicon:`bell` Responding to Events
2222
:link: responding-to-events/index

docs/source/creating-interfaces/html-with-idom.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ code examples below. The one on the left shows how to make a basic title and tod
99
using standard HTML, the one of the right uses IDOM in Python, and below is a view of
1010
what the HTML would look like if displayed:
1111

12-
.. grid:: 2
12+
.. grid:: 1 1 2 2
1313
:margin: 0
1414
:padding: 0
1515

docs/source/creating-interfaces/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Creating Interfaces
1313
:animate: fade-in
1414
:open:
1515

16-
.. grid:: 2
16+
.. grid:: 1 1 2 2
1717

1818
.. grid-item-card:: :octicon:`code-square` HTML with IDOM
1919
:link: html-with-idom

docs/source/developing-idom/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ or simply sharing your work with your colleagues and friends. We're excited to s
2121
you can help move this project and community forward!
2222

2323

24-
.. grid:: 2
24+
.. grid:: 1 1 2 2
2525
:gutter: 1
2626

2727
.. grid-item-card:: :octicon:`people` Discussion Forum

docs/source/getting-started/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Getting Started
1212
:animate: fade-in
1313
:open:
1414

15-
.. grid:: 2
15+
.. grid:: 1 1 2 2
1616

1717
.. grid-item-card:: :octicon:`tools` Installing IDOM
1818
:link: installing-idom

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ more detailed information about how to :ref:`run IDOM <Running IDOM>` in differe
9393
contexts. For example, if you want to embed IDOM into an existing application, or run
9494
IDOM within a Jupyter Notebook, this is where you can learn how to do those things.
9595

96-
.. grid:: 2
96+
.. grid:: 1 1 2 2
9797

9898
.. grid-item::
9999

0 commit comments

Comments
 (0)