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
The my_isolated component will be rerendered 300ms after the `update_time` event is emitted
112
124
113
125
### Example 5 - Initialize isolated component on a event
114
126
115
-
TODO
127
+
```ruby
128
+
classHome < Matestack::Ui::Page
129
+
defresponse
130
+
heading size:1, text:'Welcome'
131
+
my_isolated init_on:'init_time'
132
+
onclick emit:'init_time'do
133
+
button 'Init Time!'
134
+
end
135
+
end
136
+
end
137
+
```
138
+
139
+
With `init_on: 'init_time'` you can specify an event on which the isolated component should be initialized. When you click the button the event `init_time` is emitted and the isolated component asynchronously requests its content.
116
140
117
141
### Example 6 - Use custom data in isolated components
118
142
119
-
TODO
143
+
Like described above it is possible to use custom data in your isolated components. Just pass them as a hash to `public_options` and use them in your isolated component. Be careful, because `public_options` are visible in the raw html response from the server as they get passed to a vue component.
144
+
145
+
Lets render a collection of models and each of them should rerender when a user clicks a corresponding refresh button. Our model is called `Match`, representing a soccer match. It has an attribute called score with the current match score.
This page will render a match_isolated_score component for each match.
192
+
If one of the isolated components gets rerendered we need the id in order to fetch the correct match. Because the server only resolves the isolated component instead of the whole UI it does not know which match exactly is requested unless the client requests a rerender with the match id. This is why `public_options` options are passed to the client side vue component.
193
+
So if match two should be rerendered the client requests the match_isolated_score component with `public_options: { id: 2 }`. With this information our isolated component can fetch the match and rerender itself.
0 commit comments