File tree Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -71,10 +71,11 @@ def add_hook(
7171 return
7272 hks = self ._ns .get (hook , [])
7373
74- p = 0
74+ p = priority or 0
7575 if not priority and len (hks ):
76- priority_max = max (h .priority for h in hks )
77- p = priority_max - 1
76+ # Take the minimum value and remove 1 to keep the order.
77+ priority_min = min (h .priority for h in hks )
78+ p = priority_min - 1
7879
7980 hks .append (_Hook (func , priority = p , data = data ))
8081 self ._ns [hook ] = sorted (hks , reverse = True , key = lambda h : h .priority )
Original file line number Diff line number Diff line change @@ -114,24 +114,26 @@ def hook2(layout):
114114 layout .children .append (html .Div ("second" ))
115115 return layout
116116
117+ # This appears after the layout
118+ @hooks .layout (priority = 12 )
119+ def hook4 (layout ):
120+ layout .children .append (html .Div ("Prime" ))
121+ return layout
122+
123+ # Should still be last after setting a new max.
117124 @hooks .layout ()
118125 def hook3 (layout ):
119126 layout .children .append (html .Div ("third" ))
120127 return layout
121128
122- @hooks .layout (priority = 6 )
123- def hook4 (layout ):
124- layout .children .insert (0 , html .Div ("Prime" ))
125- return layout
126-
127129 app = Dash ()
128130
129131 app .layout = html .Div ([html .Div ("layout" )], id = "body" )
130132
131133 dash_duo .start_server (app )
132134 dash_duo .wait_for_text_to_equal ("#final-wrapper > div:first-child" , "final" )
133- dash_duo .wait_for_text_to_equal ("#body > div:first-child" , "Prime " )
134- dash_duo .wait_for_text_to_equal ("#body > div:nth-child(2)" , "layout " )
135+ dash_duo .wait_for_text_to_equal ("#body > div:first-child" , "layout " )
136+ dash_duo .wait_for_text_to_equal ("#body > div:nth-child(2)" , "Prime " )
135137 dash_duo .wait_for_text_to_equal ("#body > div:nth-child(3)" , "first" )
136138 dash_duo .wait_for_text_to_equal ("#body > div:nth-child(4)" , "second" )
137139 dash_duo .wait_for_text_to_equal ("#body > div:nth-child(5)" , "third" )
You can’t perform that action at this time.
0 commit comments