File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -1015,6 +1015,47 @@ describe('.dom', function () {
10151015 ) ;
10161016 } ) ;
10171017
1018+ it ( 'should change stateful root component without loosing state' , function ( ) {
1019+ const dom = document . createElement ( 'div' ) ;
1020+ const Component = function ( props , { clicks= 0 } , setState ) {
1021+ return dd . H (
1022+ ( ( clicks % 2 ) == 0 )
1023+ ? "div"
1024+ : "span" ,
1025+ dd . H ( "button" , {
1026+ onclick ( ) {
1027+ setState ( {
1028+ clicks : clicks + 1
1029+ } )
1030+ }
1031+ } , `${ clicks } clicks` )
1032+ )
1033+ }
1034+ const vdom = dd . H ( Component ) ;
1035+
1036+ console . log ( '-- pre --' ) ;
1037+
1038+ dd . R ( vdom , dom )
1039+
1040+ expect ( dom . innerHTML ) . toEqual (
1041+ '<div><button>0 clicks</button></div>'
1042+ ) ;
1043+
1044+ const event = new window . MouseEvent ( 'click' ) ;
1045+
1046+ dom . firstChild . dispatchEvent ( event ) ;
1047+ console . log ( '-- post --' ) ;
1048+ expect ( dom . innerHTML ) . toEqual (
1049+ '<span><button>1 clicks</button></span>'
1050+ ) ;
1051+
1052+ dom . firstChild . dispatchEvent ( event ) ;
1053+ console . log ( '-- done --' ) ;
1054+ expect ( dom . innerHTML ) . toEqual (
1055+ '<div><button>2 clicks</button></div>'
1056+ ) ;
1057+ } ) ;
1058+
10181059 it ( 'should not destroy stateful component DOM elements at update' , function ( ) {
10191060 const dom = document . createElement ( 'div' ) ;
10201061 const Component = function ( props , { clicks= 0 } , setState ) {
You can’t perform that action at this time.
0 commit comments