@@ -109,6 +109,7 @@ def construct_component(
109109 ** kwargs ,
110110 )
111111
112+ component .calls = []
112113 component .children = []
113114 component ._children_set = False
114115
@@ -135,6 +136,9 @@ class UnicornView(TemplateView):
135136 # Dictionary with key: attribute name; value: pickled attribute value
136137 _resettable_attributes_cache : Dict [str , Any ] = {}
137138
139+ # JavaScript method calls
140+ calls = []
141+
138142 def __init__ (self , ** kwargs ):
139143 super ().__init__ (** kwargs )
140144
@@ -211,15 +215,39 @@ def reset(self):
211215 )
212216 pass
213217
218+ def call (self , function_name ):
219+ """
220+ Add a JavaScript method name and arguments to be called after the component is rendered.
221+ """
222+ self .calls .append ({"fn" : function_name })
223+
214224 def mount (self ):
215225 """
216- Hook that gets called when a component is first created.
226+ Hook that gets called when the component is first created.
217227 """
218228 pass
219229
220230 def hydrate (self ):
221231 """
222- Hook that gets called when a component's data is hydrated.
232+ Hook that gets called when the component's data is hydrated.
233+ """
234+ pass
235+
236+ def complete (self ):
237+ """
238+ Hook that gets called when the component's methods are all called.
239+ """
240+ pass
241+
242+ def rendered (self , html ):
243+ """
244+ Hook that gets called after the component has been rendered.
245+ """
246+ pass
247+
248+ def parent_rendered (self , html ):
249+ """
250+ Hook that gets called after the component's parent has been rendered.
223251 """
224252 pass
225253
@@ -561,13 +589,18 @@ def _is_public(self, name: str) -> bool:
561589 "update" ,
562590 "calling" ,
563591 "called" ,
592+ "complete" ,
593+ "rendered" ,
594+ "parent_rendered" ,
564595 "validate" ,
565596 "is_valid" ,
566597 "get_frontend_context_variables" ,
567598 "errors" ,
568599 "updated" ,
569600 "parent" ,
570601 "children" ,
602+ "call" ,
603+ "calls" ,
571604 )
572605 excludes = []
573606
@@ -628,6 +661,7 @@ def _get_component_class(
628661 component = constructed_views_cache [component_id ]
629662 component .setup (request )
630663 component ._validate_called = False
664+ component .calls = []
631665 logger .debug (f"Retrieve { component_id } from constructed views cache" )
632666
633667 return component
0 commit comments