You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/advanced.md
+39-20Lines changed: 39 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,21 +16,56 @@ class HelloWorldView(UnicornView):
16
16
17
17
## Instance properties
18
18
19
+
### component_args
20
+
21
+
The arguments passed into the component.
22
+
23
+
```html
24
+
<!-- index.html -->
25
+
{% unicorn 'hello-arg' 'World' %}
26
+
```
27
+
28
+
```python
29
+
# hello_arg.py
30
+
from django_unicorn.components import UnicornView
31
+
32
+
classHelloArgView(UnicornView):
33
+
defmount(self):
34
+
assertself.component_args[0] =="World"
35
+
```
36
+
37
+
### component_kwargs
38
+
39
+
The keyword arguments passed into the component.
40
+
41
+
```html
42
+
<!-- index.html -->
43
+
{% unicorn 'hello-kwarg' hello='World' %}
44
+
```
45
+
46
+
```python
47
+
# hello_kwarg.py
48
+
from django_unicorn.components import UnicornView
49
+
50
+
classHelloKwargView(UnicornView):
51
+
defmount(self):
52
+
assertself.component_kwargs["hello"] =="World"
53
+
```
54
+
19
55
### request
20
56
21
-
The current `request` is available on `self` in the component's methods.
57
+
The current `request`.
22
58
23
59
```python
24
60
# hello_world.py
25
61
from django_unicorn.components import UnicornView
26
62
27
63
classHelloWorldView(UnicornView):
28
-
def__init__(self, *args, **kwargs):
29
-
super.__init__(**kwargs)
64
+
defmount(self):
30
65
print("Initial request that rendered the component", self.request)
31
66
32
67
deftest(self):
33
-
print("callMethod request to re-render the component", self.request)
68
+
print("AJAX request that re-renders the component", self.request)
34
69
```
35
70
36
71
## Custom methods
@@ -76,22 +111,6 @@ class StateView(UnicornView):
76
111
77
112
## Instance methods
78
113
79
-
### \_\_init\_\_()
80
-
81
-
Gets called when the component gets constructed for the very first time. Note that constructed components get cached to reduce the amount of time discovering and instantiating them, so `__init__` only gets called the very first time the component gets rendered.
82
-
83
-
```python
84
-
# hello_world.py
85
-
from django_unicorn.components import UnicornView
86
-
87
-
classHelloWorldView(UnicornView):
88
-
name ="original"
89
-
90
-
def__init__(self, *args, **kwargs):
91
-
super().__init__(**kwargs)
92
-
self.name ="initialized"
93
-
```
94
-
95
114
### mount()
96
115
97
116
Gets called when the component gets initialized or [reset](actions.md#reset).
0 commit comments