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
</code></pre></div></td></tr></table></div></div></div></div></details><detailsclass=question><summary>How do I signal a re-render from something that isn't a component?</summary><p>There are occasions where you may want to signal a re-render from something that isn't a component, such as a Django model signal.</p><p>In these cases, you can use the <codeclass=highlight><spanclass=n>use_channel_layer</span></code> hook to receive a signal within your component, and then use the <codeclass=highlight><spanclass=n>get_channel_layer</span><spanclass=p>()</span><spanclass=o>.</span><spanclass=n>send</span><spanclass=p>(</span><spanclass=o>...</span><spanclass=p>)</span></code> to send the signal.</p><p>In the example below, the sender will send a signal every time <codeclass=highlight><spanclass=n>ExampleModel</span></code> is saved. Then, when the receiver component gets this signal, it explicitly calls <codeclass=highlight><spanclass=n>set_message</span><spanclass=p>(</span><spanclass=o>...</span><spanclass=p>)</span></code> to trigger a re-render.</p><divclass="tabbed-set tabbed-alternate" data-tabs=17:2><inputchecked=checkedid=__tabbed_17_1name=__tabbed_17type=radio><inputid=__tabbed_17_2name=__tabbed_17type=radio><divclass=tabbed-labels><labelfor=__tabbed_17_1>signals.py</label><labelfor=__tabbed_17_2>components.py</label></div><divclass=tabbed-content><divclass=tabbed-block><divclass=highlight><tableclass=highlighttable><tr><tdclass=linenos><divclass=linenodiv><pre><span></span><spanclass=normal> 1</span>
879
+
</code></pre></div></td></tr></table></div></div></div></div></details><detailsclass=question><summary>How do I signal a re-render from something that isn't a component?</summary><p>There are occasions where you may want to signal a re-render from something that isn't a component, such as a Django model signal.</p><p>In these cases, you can use the <codeclass=highlight><spanclass=n>use_channel_layer</span></code> hook to receive a signal within your component, and then use the <codeclass=highlight><spanclass=n>get_channel_layer</span><spanclass=p>()</span><spanclass=o>.</span><spanclass=n>send</span><spanclass=p>(</span><spanclass=o>...</span><spanclass=p>)</span></code> to send the signal.</p><p>In the example below, the sender will signal every time <codeclass=highlight><spanclass=n>ExampleModel</span></code> is saved. Then, when the receiver gets this signal, it explicitly calls <codeclass=highlight><spanclass=n>set_message</span><spanclass=p>(</span><spanclass=o>...</span><spanclass=p>)</span></code> to trigger a re-render.</p><divclass="tabbed-set tabbed-alternate" data-tabs=17:2><inputchecked=checkedid=__tabbed_17_1name=__tabbed_17type=radio><inputid=__tabbed_17_2name=__tabbed_17type=radio><divclass=tabbed-labels><labelfor=__tabbed_17_1>signals.py</label><labelfor=__tabbed_17_2>components.py</label></div><divclass=tabbed-content><divclass=tabbed-block><divclass=highlight><tableclass=highlighttable><tr><tdclass=linenos><divclass=linenodiv><pre><span></span><spanclass=normal> 1</span>
</code></pre></div></td></tr></table></div></div></div></div><detailsclass=example><summary>See Interface</summary><p><fontsize=4><strong>Parameters</strong></font></p><p><codeclass=highlight><spanclass=kc>None</span></code></p><p><fontsize=4><strong>Returns</strong></font></p><table><thead><tr><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><codeclass=highlight><spanclass=nb>str</span><spanclass=o>|</span><spanclass=kc>None</span></code></td><td>A string containing the browser's current origin, obtained from WebSocket or HTTP headers (if available).</td></tr></tbody></table></details><hr><h3id=use-root-id>Use Root ID<aclass=headerlinkhref=#use-root-idtitle="Permanent link">¶</a></h3><p>Shortcut that returns the root component's <codeclass=highlight><spanclass=nb>id</span></code> from the WebSocket or HTTP connection.</p><p>The root ID is currently a randomly generated <codeclass=highlight><spanclass=n>uuid4</span></code> (unique across all root component).</p><p>This is useful when used in combination with <ahref=#use-channel-layer><codeclass=highlight><spanclass=n>use_channel_layer</span></code></a> to send messages to a specific component instance, and/or retain a backlog of messages in case that component is disconnected via <codeclass=highlight><spanclass=n>use_channel_layer</span><spanclass=p>(</span><spanclass=o>...</span><spanclass=p>,</span><spanclass=n>group_discard</span><spanclass=o>=</span><spanclass=kc>False</span><spanclass=p>)</span></code>.</p><divclass="tabbed-set tabbed-alternate" data-tabs=22:1><inputchecked=checkedid=__tabbed_22_1name=__tabbed_22type=radio><divclass=tabbed-labels><labelfor=__tabbed_22_1>components.py</label></div><divclass=tabbed-content><divclass=tabbed-block><divclass=highlight><tableclass=highlighttable><tr><tdclass=linenos><divclass=linenodiv><pre><span></span><spanclass=normal>1</span>
1011
+
</code></pre></div></td></tr></table></div></div></div></div><detailsclass=example><summary>See Interface</summary><p><fontsize=4><strong>Parameters</strong></font></p><p><codeclass=highlight><spanclass=kc>None</span></code></p><p><fontsize=4><strong>Returns</strong></font></p><table><thead><tr><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><codeclass=highlight><spanclass=nb>str</span><spanclass=o>|</span><spanclass=kc>None</span></code></td><td>A string containing the browser's current origin, obtained from WebSocket or HTTP headers (if available).</td></tr></tbody></table></details><hr><h3id=use-root-id>Use Root ID<aclass=headerlinkhref=#use-root-idtitle="Permanent link">¶</a></h3><p>Shortcut that returns the root component's <codeclass=highlight><spanclass=nb>id</span></code> from the WebSocket or HTTP connection.</p><p>The root ID is a randomly generated <codeclass=highlight><spanclass=n>uuid4</span></code>. It is notable to mention that it is persistent across the current connection. The <code>uuid</code> is reset when the page is refreshed.</p><p>This is useful when used in combination with <ahref=#use-channel-layer><codeclass=highlight><spanclass=n>use_channel_layer</span></code></a> to send messages to a specific component instance, and/or retain a backlog of messages in case that component is disconnected via <codeclass=highlight><spanclass=n>use_channel_layer</span><spanclass=p>(</span><spanclass=o>...</span><spanclass=p>,</span><spanclass=n>group_discard</span><spanclass=o>=</span><spanclass=kc>False</span><spanclass=p>)</span></code>.</p><divclass="tabbed-set tabbed-alternate" data-tabs=22:1><inputchecked=checkedid=__tabbed_22_1name=__tabbed_22type=radio><divclass=tabbed-labels><labelfor=__tabbed_22_1>components.py</label></div><divclass=tabbed-content><divclass=tabbed-block><divclass=highlight><tableclass=highlighttable><tr><tdclass=linenos><divclass=linenodiv><pre><span></span><spanclass=normal>1</span>
0 commit comments