Last active
January 2, 2023 07:57
-
-
Save rinukkusu/491ab6fed4feee08e4671be0598ce011 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function walkScope(scope) { | |
function processLevel(scope, idCache) { | |
if (scope == null) | |
return null; | |
if (idCache.indexOf(scope.$id) >= 0) | |
return null; | |
idCache.push(scope.$id); | |
let level = {}; | |
let curScopeObj = {id: scope.$id, scope: scope, childs: []}; | |
curScopeObj.childs = processLevel(scope.$$childHead, idCache); | |
level[curScopeObj.id] = curScopeObj; | |
let nextScope = scope.$$nextSibling; | |
while (nextScope != null) { | |
if (idCache.indexOf(nextScope.$id) >= 0) | |
continue; | |
idCache.push(nextScope.$id); | |
let nextScopeObj = {id: nextScope.$id, scope: nextScope, childs: []}; | |
nextScopeObj.childs = processLevel(nextScope, idCache); | |
level[nextScopeObj.id] = nextScopeObj; | |
nextScope = nextScope.$$nextSibling; | |
} | |
return level; | |
} | |
let idCache = []; | |
return processLevel(scope, idCache); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: