| 132 | * Returns an instance of a view (if found), otherwise undefined. |
| 133 | */ |
| 134 | export function getViewById(view: ViewBase, id: string): ViewBase { |
| 135 | if (!view) { |
| 136 | return undefined; |
| 137 | } |
| 138 | |
| 139 | if (view.id === id) { |
| 140 | return view; |
| 141 | } |
| 142 | |
| 143 | let retVal: ViewBase; |
| 144 | const descendantsCallback = function (child: ViewBase): boolean { |
| 145 | if (child.id === id) { |
| 146 | retVal = child; |
| 147 | |
| 148 | // break the iteration by returning false |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | return true; |
| 153 | }; |
| 154 | |
| 155 | eachDescendant(view, descendantsCallback); |
| 156 | |
| 157 | return retVal; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Gets a child view by domId. |