@@ -35,9 +35,11 @@ let $exceptionHandler;
3535
3636export const $postUpdateQueue = [ ] ;
3737
38+ export let rootScope ;
39+
3840export class RootScopeProvider {
3941 constructor ( ) {
40- this . rootScope = createScope ( ) ;
42+ rootScope = this . rootScope = createScope ( ) ;
4143 }
4244
4345 $get = [
@@ -239,6 +241,8 @@ export class Scope {
239241
240242 this . scheduled = [ ] ;
241243
244+ this . $scopename = undefined ;
245+
242246 /** @private */
243247 this . propertyMap = {
244248 $watch : this . $watch . bind ( this ) ,
@@ -250,18 +254,20 @@ export class Scope {
250254 $apply : this . $apply . bind ( this ) ,
251255 $postUpdate : this . $postUpdate . bind ( this ) ,
252256 $isRoot : this . #isRoot. bind ( this ) ,
253- $proxy : this . $proxy ,
254257 $on : this . $on . bind ( this ) ,
255258 $emit : this . $emit . bind ( this ) ,
256259 $broadcast : this . $broadcast . bind ( this ) ,
257260 $transcluded : this . $transcluded . bind ( this ) ,
258261 $handler : /** @type {Scope } */ ( this ) ,
262+ $merge : this . $merge . bind ( this ) ,
263+ $getById : this . $getById . bind ( this ) ,
264+ $searchByName : this . $searchByName . bind ( this ) ,
265+ $proxy : this . $proxy ,
259266 $parent : this . $parent ,
260267 $root : this . $root ,
261268 $children : this . $children ,
262269 $id : this . $id ,
263- $merge : this . $merge . bind ( this ) ,
264- $getById : this . $getById . bind ( this ) ,
270+ $scopename : this . $scopename ,
265271 } ;
266272 }
267273
@@ -277,8 +283,14 @@ export class Scope {
277283 */
278284 set ( target , property , value , proxy ) {
279285 if ( property === "undefined" ) {
280- throw new Error ( "Attempting to set undefined property" ) ;
286+ return false ;
287+ }
288+
289+ if ( property === "$scopename" ) {
290+ this . $scopename = value ;
291+ return true ;
281292 }
293+
282294 if (
283295 ( target . constructor ?. $nonscope &&
284296 Array . isArray ( target . constructor . $nonscope ) &&
@@ -496,9 +508,9 @@ export class Scope {
496508 * @returns {* } - The value of the property or a method if accessing `watch` or `sync`.
497509 */
498510 get ( target , property , proxy ) {
511+ if ( property === "$scopename" && this . $scopename ) return this . $scopename ;
499512 if ( property === "$$watchersCount" ) return calculateWatcherCount ( this ) ;
500513 if ( property === isProxySymbol ) return true ;
501-
502514 if ( target [ property ] && isProxy ( target [ property ] ) ) {
503515 this . $proxy = target [ property ] ;
504516 } else {
@@ -527,7 +539,6 @@ export class Scope {
527539 this . #scheduleListener( this . scheduled ) ;
528540 }
529541 }
530-
531542 if ( hasOwn ( this . propertyMap , property ) ) {
532543 this . $target = target ;
533544 return this . propertyMap [ property ] ;
@@ -1272,6 +1283,26 @@ export class Scope {
12721283 return res ;
12731284 }
12741285 }
1286+
1287+ $searchByName ( name ) {
1288+ const getByName = ( scope , name ) => {
1289+ if ( scope . $scopename === name ) {
1290+ return scope ;
1291+ } else {
1292+ let res = undefined ;
1293+ for ( const child of scope . $children ) {
1294+ let found = getByName ( child , name ) ;
1295+ if ( found ) {
1296+ res = found ;
1297+ break ;
1298+ }
1299+ }
1300+ return res ;
1301+ }
1302+ } ;
1303+
1304+ return getByName ( this . $root , name ) ;
1305+ }
12751306}
12761307
12771308/*------------- Private helpers -------------*/
0 commit comments