Skip to content

Commit 46dea2b

Browse files
fix(view): Update views in order of ui-view depth and also by state depth
Closes angular-ui/ui-router#3168
1 parent 1a6cdfc commit 46dea2b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/view/view.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,13 @@ export class ViewService {
167167
let uiViewsByFqn: TypedMap<ActiveUIView> =
168168
this._uiViews.map(uiv => [uiv.fqn, uiv]).reduce(applyPairs, <any> {});
169169

170-
// Return the number of dots in the fully qualified name
170+
// Return a weighted depth value for a uiView.
171+
// The depth is the nesting depth of ui-views (based on FQN; times 10,000)
172+
// plus the depth of the state that is populating the uiView
171173
function uiViewDepth(uiView: ActiveUIView) {
172-
return uiView.fqn.split(".").length;
174+
const stateDepth = (context: ViewContext) =>
175+
context.parent ? stateDepth(context.parent) + 1 : 1;
176+
return (uiView.fqn.split(".").length * 10000) + stateDepth(uiView.creationContext);
173177
}
174178

175179
// Return the ViewConfig's context's depth in the context tree.
@@ -200,6 +204,7 @@ export class ViewService {
200204
uiView.configUpdated(viewConfig);
201205
};
202206

207+
// Sort views by FQN and state depth. Process uiviews nearest the root first.
203208
this._uiViews.sort(depthCompare(uiViewDepth, 1)).map(matchingConfigPair).forEach(configureUIView);
204209
};
205210

0 commit comments

Comments
 (0)