Skip to content

Commit 126ea59

Browse files
committed
rename element to component
1 parent 6fd73fd commit 126ea59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+524
-533
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ IDOM can be used to create a simple slideshow which changes whenever a user clic
5050
```python
5151
import idom
5252

53-
@idom.element
53+
@idom.component
5454
def Slideshow():
5555
index, set_index = idom.hooks.use_state(0)
5656
url = f"https://picsum.photos/800/300?image={index}"

docs/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def forward_to_index(request):
2323
return response.redirect("/docs/index.html")
2424

2525

26-
mount, element = multiview()
26+
mount, component = multiview()
2727

2828
examples_dir = here / "source" / "examples"
2929
sys.path.insert(0, str(examples_dir))
@@ -54,7 +54,9 @@ async def forward_to_index(request):
5454
idom.run = original_run
5555

5656

57-
server = PerClientStateServer(element, {"redirect_root_to_index": False}).register(app)
57+
server = PerClientStateServer(component, {"redirect_root_to_index": False}).register(
58+
app
59+
)
5860

5961

6062
def production():

docs/source/core-concepts.rst

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ This section covers core features of IDOM that are used in making
55
interactive interfaces.
66

77

8-
Pure Elements
9-
-------------
8+
Pure Components
9+
---------------
1010

1111
As in most programming paradigms, so many of the problems come down to how we manage
1212
state. The first tool in encouraging its proper curation is the usage of
@@ -17,7 +17,7 @@ way to manage state is to have no state at all."
1717
With IDOM the core of your application will be built on the back of basic functions and
1818
coroutines that return :ref:`VDOM <VDOM Mimetype>` models and which do so without state
1919
and without `side effects`_. We call these kinds of model rendering functions
20-
:ref:`Pure Elements`. For example, one might want a function which
20+
:ref:`Pure Components`. For example, one might want a function which
2121
accepted a list of strings and turned it into a series of paragraph elements:
2222

2323
.. code-block::
@@ -26,12 +26,12 @@ accepted a list of strings and turned it into a series of paragraph elements:
2626
return idom.html.div([idom.html.p(text) for text in list_of_text])
2727
2828
29-
Stateful Elements
30-
-----------------
29+
Stateful Components
30+
-------------------
3131

32-
A Stateful Element is one which uses a :ref:`Life Cycle Hooks`. These life cycle hooks
33-
allow you to add state to otherwise stateless functions. To create a stateful element
34-
you'll need to apply the :func:`~idom.core.element.element` decorator to a coroutine_
32+
A Stateful Component is one which uses a :ref:`Life Cycle Hooks`. These life cycle hooks
33+
allow you to add state to otherwise stateless functions. To create a stateful component
34+
you'll need to apply the :func:`~idom.core.component.component` decorator to a coroutine_
3535
whose body contains a hook usage. We'll demonstrate that with a simple
3636
:ref:`click counter`:
3737

@@ -40,7 +40,7 @@ whose body contains a hook usage. We'll demonstrate that with a simple
4040
import idom
4141

4242

43-
@idom.element
43+
@idom.component
4444
def ClickCount():
4545
count, set_count = idom.hooks.use_state(0)
4646

@@ -50,14 +50,14 @@ whose body contains a hook usage. We'll demonstrate that with a simple
5050
)
5151

5252

53-
Element Layout
54-
--------------
53+
Component Layout
54+
----------------
5555

56-
Displaying an element requires you to turn elements into :ref:`VDOM <VDOM Mimetype>` -
56+
Displaying components requires you to turn them into :ref:`VDOM <VDOM Mimetype>` -
5757
this is done using a :class:`~idom.core.layout.Layout`. Layouts are responsible for
58-
rendering elements (turning them into VDOM) and scheduling their re-renders when they
58+
rendering components (turning them into VDOM) and scheduling their re-renders when they
5959
:meth:`~idom.core.layout.Layout.update`. To create a layout, you'll need an
60-
:class:`~idom.core.element.Element` instance, which will become its root, and won't
60+
:class:`~idom.core.component.Component` instance, which will become its root, and won't
6161
ever be removed from the model. Then you'll just need to call and await a
6262
:meth:`~idom.core.layout.Layout.render` which will return a :ref:`JSON Patch`:
6363

@@ -80,7 +80,7 @@ have to re-render the layout and see what changed:
8080
event_handler_id = "on-click"
8181

8282

83-
@idom.element
83+
@idom.component
8484
def ClickCount():
8585
count, set_count = idom.hooks.use_state(0)
8686

@@ -212,7 +212,7 @@ models:
212212
import idom
213213
from idom.server.sanic import PerClientStateServer
214214
215-
@idom.element
215+
@idom.component
216216
def View(self):
217217
return idom.html.h1(["Hello World"])
218218
@@ -233,7 +233,7 @@ The implementation registers hooks into the application to serve the model once
233233
234234
app = Sanic()
235235
236-
@idom.element
236+
@idom.component
237237
def View(self):
238238
return idom.html.h1(["Hello World"])
239239

docs/source/examples/click_count.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import idom
22

33

4-
@idom.element
4+
@idom.component
55
def ClickCount():
66
count, set_count = idom.hooks.use_state(0)
77

docs/source/examples/material_ui_button_no_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
material_ui = idom.install("@material-ui/core", fallback="loading...")
44

55
idom.run(
6-
idom.element(
6+
idom.component(
77
lambda: material_ui.Button(
88
{"color": "primary", "variant": "contained"}, "Hello World!"
99
)

docs/source/examples/material_ui_button_on_click.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
material_ui = idom.install("@material-ui/core", fallback="loading...")
77

88

9-
@idom.element
9+
@idom.component
1010
def ViewSliderEvents():
1111
event, set_event = idom.hooks.use_state(None)
1212

docs/source/examples/material_ui_slider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
material_ui = idom.install("@material-ui/core", fallback="loading...")
77

88

9-
@idom.element
9+
@idom.component
1010
def ViewSliderEvents():
1111
event, set_event = idom.hooks.use_state(None)
1212

docs/source/examples/matplotlib_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from idom.widgets.html import image
77

88

9-
@idom.element
9+
@idom.component
1010
def PolynomialPlot():
1111
coefficients, set_coefficients = idom.hooks.use_state([0])
1212

@@ -19,7 +19,7 @@ def PolynomialPlot():
1919
)
2020

2121

22-
@idom.element
22+
@idom.component
2323
def ExpandableNumberInputs(values, set_values):
2424
inputs = []
2525
for i in range(len(values)):

docs/source/examples/simple_dashboard.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
victory = idom.install("victory", fallback="loading...")
1010

1111

12-
@idom.element
12+
@idom.component
1313
def RandomWalk():
1414
mu = idom.hooks.use_ref(0)
1515
sigma = idom.hooks.use_ref(1)
@@ -38,7 +38,7 @@ def RandomWalk():
3838
)
3939

4040

41-
@idom.element
41+
@idom.component
4242
def RandomWalkGraph(mu, sigma):
4343
interval = use_interval(0.5)
4444
data, set_data = idom.hooks.use_state([{"x": 0, "y": 0}] * 50)
@@ -56,7 +56,7 @@ async def animate():
5656
return victory.VictoryLine({"data": data, "style": {"parent": {"width": "500px"}}})
5757

5858

59-
@idom.element
59+
@idom.component
6060
def NumberInput(label, value, set_value_callback, domain):
6161
minimum, maximum, step = domain
6262
attrs = {"min": minimum, "max": maximum, "step": step}

docs/source/examples/slideshow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import idom
22

33

4-
@idom.element
4+
@idom.component
55
def Slideshow():
66
index, set_index = idom.hooks.use_state(0)
77

docs/source/examples/snake_game.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GameState(enum.Enum):
1313
play = 3
1414

1515

16-
@idom.element
16+
@idom.component
1717
def GameView():
1818
game_state, set_game_state = idom.hooks.use_state(GameState.init)
1919

@@ -40,7 +40,7 @@ class Direction(enum.Enum):
4040
ArrowRight = (1, 0)
4141

4242

43-
@idom.element
43+
@idom.component
4444
def GameLoop(grid_size, block_scale, set_game_state):
4545
# we `use_ref` here to capture the latest direction press without any delay
4646
direction = idom.hooks.use_ref(Direction.ArrowRight.value)

docs/source/examples/super_simple_chart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
idom.run(
11-
idom.element(
11+
idom.component(
1212
lambda: ssc.SuperSimpleChart(
1313
{
1414
"data": [

docs/source/examples/todo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import idom
22

33

4-
@idom.element
4+
@idom.component
55
def Todo():
66
items, set_items = idom.hooks.use_state([])
77

docs/source/examples/use_reducer_counter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def reducer(count, action):
1212
raise ValueError(f"Unknown action '{action}'")
1313

1414

15-
@idom.element
15+
@idom.component
1616
def Counter():
1717
count, dispatch = idom.hooks.use_reducer(reducer, 0)
1818
return idom.html.div(

docs/source/examples/use_state_counter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def decrement(last_count):
99
return last_count - 1
1010

1111

12-
@idom.element
12+
@idom.component
1313
def Counter():
1414
initial_count = 0
1515
count, set_count = idom.hooks.use_state(initial_count)

docs/source/examples/victory_chart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
victory = idom.install("victory", fallback="loading...")
44

55
idom.run(
6-
idom.element(
6+
idom.component(
77
lambda: victory.VictoryBar({"style": {"parent": {"width": "500px"}}}),
88
)
99
)

docs/source/getting-started.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Since it's likely a lot to take in at once, we'll break it down piece by piece:
1414
:lines: 4-5
1515
:linenos:
1616

17-
The ``idom.element`` decorator creates an :ref:`Element <Stateful Elements>` constructor
17+
The ``idom.component`` decorator creates a :ref:`Component <Stateful Components>` constructor
1818
whose render function is defined by the `asynchronous function`_ below it. To create
19-
an :class:`~idom.core.element.Element` instance we call ``Slideshow()`` with the same
20-
arguments as its render function. The render function of an Element returns a data
21-
structure that depicts a user interface, or in more technical terms a Document Object
22-
Model (DOM). We call this structural representation of the DOM a `Virtual DOM`__ (VDOM)
23-
- a term familiar to those who work with `ReactJS`_. In the case of ``Slideshow`` it
24-
will return a VDOM representing an image which, when clicked, will change.
19+
a Component instance we call ``Slideshow()`` with the same arguments as its render
20+
function. The render function of a Component returns a data structure that depicts a
21+
user interface, or in more technical terms a Document Object Model (DOM). We call this
22+
structural representation of the DOM a `Virtual DOM`__ (VDOM) - a term familiar to those
23+
who work with `ReactJS`_. In the case of ``Slideshow`` it will return a VDOM
24+
representing an image which, when clicked, will change.
2525

2626
__ https://reactjs.org/docs/faq-internals.html#what-is-the-virtual-dom
2727

@@ -31,9 +31,9 @@ __ https://reactjs.org/docs/faq-internals.html#what-is-the-virtual-dom
3131
:linenos:
3232

3333
The :func:`~idom.core.hooks.use_state` function is a :ref:`Hook <Life Cycle Hooks>`.
34-
Calling a Hook inside an Element's render function (one decorated by ``idom.element``)
34+
Calling a Hook inside a Component's render function (one decorated by ``idom.component``)
3535
adds some local state to it. IDOM will preserve the state added by Hooks between calls
36-
to the Element's render function.
36+
to the Component's render function.
3737

3838
The ``use_state`` hook returns two values - the *current* state value and a function
3939
that let's you update that value. In the case of ``Slideshow`` the value of the
@@ -49,7 +49,7 @@ function allow us to change it. The one required argument of ``use_state`` is th
4949
The coroutine above will get added as an event handler to the resulting view. When it
5050
responds to an event it will use the update function returned by the ``use_state`` Hook
5151
to change which image is shown to the user. Calling the update function will schedule
52-
the Element to be re-rendered. That is, the Element's render function will be called
52+
the Component to be re-rendered. That is, the Component's render function will be called
5353
again, and its new result will be displayed.
5454

5555
.. note::

docs/source/javascript-modules.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ in a REPL or Jupyter Notebook):
5454

5555
Any standard javascript dependency specifier is allowed here.
5656

57-
Once the package has been succesfully installed, you can import and display the element:
57+
Once the package has been succesfully installed, you can import and display the component:
5858

5959
.. example:: material_ui_button_no_action
6060

6161

62-
Passing Props To Javascript
63-
---------------------------
62+
Passing Props To Javascript Components
63+
--------------------------------------
6464

6565
So now that we can install and display a Material UI Button we probably want to make it
6666
do something. Thankfully there's nothing new to learn here, you can pass event handlers
6767
to the button just as you did when :ref:`getting started`. Thus, all we need to do is
68-
add an ``onClick`` handler to the element:
68+
add an ``onClick`` handler to the component:
6969

7070
.. example:: material_ui_button_on_click
7171

0 commit comments

Comments
 (0)