@@ -28,7 +28,7 @@ import {
2828} from "./_propsOps" ;
2929import {
3030 _renderFocus , _renderFocusAsSequence , _renderFirstAbleDelegate ,
31- _tryRenderLens , _readSlotValue , _tryRenderLensArray , _validateElement ,
31+ _tryRenderLens , _tryRenderLensArray , _validateElement ,
3232} from "./_renderOps" ;
3333import {
3434 VSSStyleSheetSymbol ,
@@ -354,6 +354,43 @@ class UIComponent extends React.Component {
354354 return this . props . elementKey || this . getUIContextValue ( "key" ) ;
355355 }
356356
357+ readSlotValue ( slotName : string , slotSymbol : Symbol , focus : any , onlyIfAble ? : boolean ,
358+ props = this . props ) :
359+ void | null | string | React . Element < any > | [ ] | Promise < any > {
360+ if ( onlyIfAble ) {
361+ const descriptor = this . context . engine . getHostObjectDescriptor ( slotSymbol ) ;
362+ if ( descriptor
363+ && ( typeof descriptor . isEnabled === "function" )
364+ && ! descriptor . isEnabled ( focus , this ) ) {
365+ return undefined ;
366+ }
367+ }
368+ let assignee ;
369+ try {
370+ assignee = props [ slotName ] ;
371+ if ( assignee === undefined ) {
372+ if ( props . hasOwnProperty ( slotName ) ) {
373+ throw new Error ( `Render role props.${ slotName } is provided but its value is undefined` ) ;
374+ }
375+ assignee = this . getUIContextValue ( slotSymbol ) ;
376+ if ( assignee === undefined ) {
377+ assignee = this . context [ slotName ] ;
378+ if ( assignee === undefined ) return undefined ;
379+ } else if ( Array . isArray ( assignee ) && ! Object . isFrozen ( assignee ) ) {
380+ assignee = [ ...assignee ] ; // the lens chain constantly mutates assignee, return a copy
381+ }
382+ }
383+ return assignee ;
384+ } catch ( error ) {
385+ throw wrapError ( error ,
386+ `During ${ this . debugId ( ) } \n .readSlotValue, with:` ,
387+ "\n\tfocus:" , focus ,
388+ "\n\tslotName:" , slotName ,
389+ "\n\tslotSymbol:" , slotSymbol ,
390+ "\n\tassignee:" , assignee ) ;
391+ }
392+ }
393+
357394 _subscriptions: Object ;
358395 style: Object ;
359396
@@ -524,21 +561,14 @@ class UIComponent extends React.Component {
524561
525562 tryRenderLens ( lens : any , focus : any = this . tryFocus ( ) , lensName : string , onlyIfAble ? : boolean ,
526563 onlyOnce ?: boolean ) : void | null | string | React . Element < any > | [ ] | Promise < any > {
527- const lensAssembly = this . getUIContextValue ( this . getValos ( ) . Lens . lensAssembly ) || [ ] ;
528- const assemblyLength = lensAssembly . length ;
529- let ret ;
530564 try {
531- lensAssembly . push ( lensName ) ;
532- return ( ret = _tryRenderLens ( this , lens , focus , lensName , onlyIfAble , onlyOnce ) ) ;
565+ return _tryRenderLens ( this , lens, focus, lensName, onlyIfAble, onlyOnce) ;
533566 } catch ( error ) {
534567 throw wrapError ( error , `During ${ this . debugId ( ) } \n .renderLens, with:` ,
535568 "\n\tlensName:" , lensName ,
536569 "\n\tlens:" , lens ,
537570 "\n\ttypeof lens:" , typeof lens ,
538571 "\n\tfocus:" , ...dumpObject ( focus ) ) ;
539- } finally {
540- if ( ret === null ) lensAssembly . splice ( assemblyLength ) ;
541- // else lensAssembly[assemblyLength] = { [lensName]: ret };
542572 }
543573 }
544574
@@ -588,10 +618,13 @@ class UIComponent extends React.Component {
588618 const slotName = typeof slot === "string" ? slot : valosLens [ slot ] ;
589619 const slotSymbol = typeof slot !== "string" ? slot : valosLens [ slot ] ;
590620 const rootSlotName = rootSlotName_ || slotName ;
621+ const slotAssembly = this . getUIContextValue ( this . getValos ( ) . Lens . slotAssembly ) || [ ] ;
622+ const assemblyLength = slotAssembly . length ;
623+ slotAssembly . push ( slotName ) ;
591624 try {
592625 if ( ! slotSymbol ) throw new Error ( `No valos.Lens slot symbol for '${ slotName } '` ) ;
593626 if ( ! slotName ) throw new Error ( `No valos.Lens slot name for '${ String ( slotSymbol ) } '` ) ;
594- slotValue = _readSlotValue ( this , slotName , slotSymbol , focus , onlyIfAble ) ;
627+ slotValue = this . readSlotValue ( slotName , slotSymbol , focus , onlyIfAble ) ;
595628 ret = slotValue && this . renderLens (
596629 slotValue , focus , `${ rootSlotName } -${ lensName || "" } ` , undefined , onlyOnce ) ;
597630 return ret ;
@@ -601,6 +634,8 @@ class UIComponent extends React.Component {
601634 "\n\tfocus:" , focus ,
602635 "\n\tslot value:" , slotValue ,
603636 "\n\trootSlotName:" , rootSlotName ) ;
637+ } finally {
638+ if ( assemblyLength < slotAssembly . length ) slotAssembly . splice ( assemblyLength ) ;
604639 }
605640 }
606641
@@ -613,7 +648,7 @@ class UIComponent extends React.Component {
613648 this . _pendingRenderValue = undefined ;
614649 let mainValidationFaults ;
615650 let latestRenderedLensSlot ;
616- if ( this . state . uiContext ) this . setUIContextValue ( this . getValos ( ) . Lens . lensAssembly , [ ] ) ;
651+ if ( this . state . uiContext ) this . setUIContextValue ( this . getValos ( ) . Lens . slotAssembly , [ ] ) ;
617652 try {
618653 const renderNormally = ( ret === undefined ) && ! this . _errorObject
619654 && ! _checkForInfiniteRenderRecursion ( this ) ;
0 commit comments