@@ -748,10 +748,7 @@ class VirtualElement {
748
748
}
749
749
750
750
export
751
- class VirtualElementPass {
752
- readonly realize : VirtualElementPass . IRealize ;
753
-
754
- readonly render : VirtualElementPass . IRender ;
751
+ class VirtualElementPass {
755
752
756
753
/**
757
754
* The type of the node.
@@ -764,26 +761,13 @@ class VirtualElementPass {
764
761
/**
765
762
* Construct a new virtual element pass thru node.
766
763
*
767
- * @param realize - a function that takes no arguments and returns an HTMLElement
768
- *
769
764
* @param render - a function that takes a host HTMLElement and returns void
770
765
*/
771
- constructor ( { realize, render} : VirtualElementPass . IProps ) {
772
- this . render = render ;
773
- this . realize = realize || ( ( ) => { const host = document . createElement ( 'div' ) ; this . render ( host ) ; return host } ) ;
774
- }
766
+ constructor ( readonly render : VirtualElementPass . IRender , readonly tag : string , readonly attrs : ElementAttrs ) { }
775
767
}
776
768
777
769
export namespace VirtualElementPass {
778
- export type IRealize = ( ) => HTMLElement ;
779
-
780
770
export type IRender = ( host : HTMLElement ) => void ;
781
-
782
- export interface IProps {
783
- realize ?: IRealize ;
784
-
785
- render : IRender ;
786
- }
787
771
}
788
772
789
773
/**
@@ -973,8 +957,8 @@ namespace h {
973
957
export const wbr : IFactory = h . bind ( undefined , 'wbr' ) ;
974
958
}
975
959
976
- export function hpass ( props : VirtualElementPass . IProps ) : VirtualElementPass {
977
- return new VirtualElementPass ( props ) ;
960
+ export function hpass ( render : VirtualElementPass . IRender , tag : string , attrs : ElementAttrs = { } ) : VirtualElementPass {
961
+ return new VirtualElementPass ( render , tag , attrs ) ;
978
962
}
979
963
980
964
/**
@@ -1070,32 +1054,28 @@ namespace Private {
1070
1054
let host = arguments [ 1 ] || null ;
1071
1055
const before = arguments [ 2 ] || null ;
1072
1056
1073
- if ( node . type === 'passthru' ) {
1074
- if ( host ) {
1075
- // TODO: figure out how to do an "insert before" with a passthru node
1076
- node . render ( host ) ;
1077
- } else {
1078
- throw new Error ( "createDOMNode should not be called with only one argument on vdom nodes of type === 'passthru'" ) ;
1079
- }
1057
+ if ( host ) {
1058
+ host . insertBefore ( createDOMNode ( node ) , before ) ;
1080
1059
} else {
1081
- if ( host ) {
1082
- host . insertBefore ( createDOMNode ( node ) , before ) ;
1083
- } else {
1084
- // Create a text node for a virtual text node.
1085
- if ( node . type === 'text' ) {
1086
- return document . createTextNode ( node . content ) ;
1087
- }
1060
+ // Create a text node for a virtual text node.
1061
+ if ( node . type === 'text' ) {
1062
+ return document . createTextNode ( node . content ) ;
1063
+ }
1088
1064
1089
- // Create the HTML element with the specified tag.
1090
- host = document . createElement ( node . tag ) ;
1065
+ // Create the HTML element with the specified tag.
1066
+ host = document . createElement ( node . tag ) ;
1091
1067
1092
- // Add the attributes for the new element.
1093
- addAttrs ( host , node . attrs ) ;
1068
+ // Add the attributes for the new element.
1069
+ addAttrs ( host , node . attrs ) ;
1094
1070
1095
- // Recursively populate the element with child content.
1096
- for ( let i = 0 , n = node . children . length ; i < n ; ++ i ) {
1097
- createDOMNode ( node . children [ i ] , host ) ;
1098
- }
1071
+ if ( node . type === 'passthru' ) {
1072
+ node . render ( host ) ;
1073
+ return host ;
1074
+ }
1075
+
1076
+ // Recursively populate the element with child content.
1077
+ for ( let i = 0 , n = node . children . length ; i < n ; ++ i ) {
1078
+ createDOMNode ( node . children [ i ] , host ) ;
1099
1079
}
1100
1080
}
1101
1081
@@ -1155,7 +1135,7 @@ namespace Private {
1155
1135
1156
1136
// Handle the case of passthru update.
1157
1137
if ( oldVNode . type === 'passthru' && newVNode . type === 'passthru' ) {
1158
- newVNode . render ( host ) ;
1138
+ newVNode . render ( currElem as HTMLElement ) ;
1159
1139
currElem = currElem ! . nextSibling ;
1160
1140
continue ;
1161
1141
}
0 commit comments