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/api/100-components/cable.md
+28-25Lines changed: 28 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,24 +12,24 @@ When rendering a list of items, make sure to use a custom component for each ite
12
12
Imagine something like this:
13
13
14
14
```ruby
15
-
classMyPage < Matestack::Ui::Page
15
+
classPage < Matestack::Ui::Page
16
16
17
17
defresponse
18
18
cable id:'foo' [...] do
19
19
#this block will be rendered as initial content
20
20
#and may be modified on the client later on when receiving defined events
21
21
DummyModel.all.each do |instance|
22
-
my_list_componentitem: instance
22
+
list_componentitem: instance
23
23
end
24
24
end
25
25
end
26
26
end
27
27
```
28
28
29
-
with a (registered!) custom component:
29
+
with an as `list_component` registered component:
30
30
31
31
```ruby
32
-
classMyListComponent < Matestack::Ui::Component
32
+
classListComponent < Matestack::Ui::Component
33
33
34
34
requires :item
35
35
@@ -44,30 +44,33 @@ class MyListComponent < Matestack::Ui::Component
44
44
end
45
45
```
46
46
47
+
48
+
49
+
47
50
**Required options**
48
51
49
52
*`id` - Expects a unique string identifying the component
50
53
51
54
**Optional options**
52
55
53
-
*`append_on` - Expects a string which matches the event which will be emitted via ActionCable on the serverside. Event payload data in form of HTML will be **appended** to the current cable component DOM
56
+
*`append_on` - Expects a string matching the event which will be emitted via ActionCable on the serverside. Event payload data in form of HTML will be **appended** to the current cable component DOM
*`prepend_on` - Expects a string which matches the event which will be emitted via ActionCable on the serverside. Event payload data in form of HTML will be **prepended** to the current cable component DOM
*`replace_on` - Expects a string which matches the event which will be emitted via ActionCable on the serverside. Event payload data in form of HTML will **replace** the whole current cable component DOM
*`update_on` - Expects a string which matches the event which will be emitted via ActionCable on the serverside. Event payload data in form of HTML will **update** a specific element iditified by its root ID within the current cable component DOM
*`delete_on` - Expects a string which matches the event which will be emitted via ActionCable on the serverside. Event payload data in form of a string containing the ID will **remove** a specific element identified by its root ID within the current cable component DOM
Copy file name to clipboardExpand all lines: docs/guides/750-cable/README.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,14 +2,14 @@
2
2
3
3
The `cable` component is designed to asynchronously manipulate its DOM based on ActionCable events triggered on the serverside. Imagine a list of Todos and a `form` below that list. After creating a new Todo, the new list item can be rendered on the serverside and pushed to the `cable` component, which can be configured to pre or append the current list with the new item. Unlike the `async` component, the `cable` component does not request and rerender the whole list after receiving a specific event.
4
4
5
-
Furthermore you can update or remove items in that list using ActionCable events as well. The `cable` component again will only manipulate the specific DOM elements and not the whole list. This requires more implementation effort but gives your more flexibility and performance while creating reactive UIs compared to the `async` component. As usual, no JavaScript is required at your end in order to implement this sophisticated reactivity.
5
+
Furthermore you can update or remove items in that list using ActionCable events as well. The `cable` component again will only manipulate the specific DOM elements and not the whole list. This requires more implementation effort but gives you more flexibility and performance while creating reactive UIs compared to the `async` component. As usual, no JavaScript is required at your end in order to implement this sophisticated reactivity.
6
6
7
7
Please read the [ActionCable Guide](/docs/guides/1000-action_cable/README.md) if you need help setting up ActionCable for your project.
8
8
9
9
10
10
## `cable` vs `async` component
11
11
12
-
`cable` and `async` might seem similar. They indeed can be used for similar use cases - imagine implementing a reactive list of Todo items (ActiveRecord Instances) created via a `form` below the list. You can either use `async` or `cable` in order to create that reactive list!
12
+
`cable` and `async` might seem similar. They indeed can be used for similar use cases - imagine implementing a reactive list of todo items (using ActiveRecord) created via a `form` below the list. You can either use `async` or `cable` in order to create that reactive list!
13
13
14
14
But they work completely differently:
15
15
@@ -56,7 +56,7 @@ class MyPage < Matestack::Ui::Page
56
56
end
57
57
```
58
58
59
-
with a (registered!) custom component:
59
+
with an as `todo_component` registered component:
60
60
61
61
```ruby
62
62
classTodoComponent < Matestack::Ui::Component
@@ -74,9 +74,9 @@ class TodoComponent < Matestack::Ui::Component
74
74
end
75
75
```
76
76
77
-
After form submission, the form resets itself dynamically, but the list will not get updated with the new todo instance. You can now decide, if you want to use `async` or `cable` in order to implement that reactivity. `async` could react to an event emitted by the `form` and simply rerender the whole list without any further implementation. Wrapping the list in an correctly configured `async` component would be enough!
77
+
After form submission, the form resets itself dynamically, but the list will not get updated with the new todo instance. You can now decide, if you want to use `async` or `cable` in order to implement that reactivity. `async` could react to an event emitted by the `form` and simply rerender the whole list without any further implementation. Wrapping the list in a correctly configured `async` component would be enough!
78
78
79
-
But in this case, we do not want to rerender the whole list every time we submitted the form, because - let's say - the list will be quite long and rerendering the whole list would be too slow. We only want to add new items to the current DOM without touching the rest of the list. The `cable` component enables you to do exactly this. The principle behind: After form submission the new component is rendered on the serverside and than pushed to the clientside via ActionCable. The `cable` component receives this event and will than - depending on your configuration - append or prepend the current list on the UI. Implementation would look like this:
79
+
But in this case, we do not want to rerender the whole list every time we submitted the form, because - let's say - the list will be quite long and rerendering the whole list would be getting slow. We only want to add new items to the current DOM without touching the rest of the list. The `cable` component enables you to do exactly this. The principle behind it: After form submission the new component is rendered on the serverside and than pushed to the clientside via ActionCable. The `cable` component receives this event and will than - depending on your configuration - append or prepend the current list on the UI. Implementation would look like this:
80
80
81
81
### Appending elements
82
82
@@ -121,7 +121,7 @@ end
121
121
122
122
```
123
123
124
-
Please notice that it is mandatory to use a component for each list item. Otherwise it wouldn't be possible to render only a new list item within the `create` action and push only that new component to the client.
124
+
Please notice that we recommend to use a component for each list item. With a component for each item it is possible to easily render a new list item within the `create` action and push it to the client. But it is possible to also use another component or a html string. Any given html will be appended to the list.
0 commit comments