11import { options } from 'preact' ;
2- import { vnodesForComponent , mappedVNodes , lastSeen } from './vnodesForComponent' ;
2+ import {
3+ vnodesForComponent ,
4+ mappedVNodes ,
5+ lastSeen ,
6+ } from './vnodesForComponent' ;
37import { VNODE_COMPONENT } from '../constants' ;
48
59const getMappedVnode = type => {
@@ -13,40 +17,40 @@ const getMappedVnode = type => {
1317const BUILT_IN_COMPONENTS = [ 'Fragment' , 'Suspense' , 'SuspenseList' ] ;
1418
1519const isBuiltIn = type => {
16- return BUILT_IN_COMPONENTS . includes ( type . name )
17- }
20+ return BUILT_IN_COMPONENTS . includes ( type . name ) ;
21+ } ;
1822
1923const oldVnode = options . vnode ;
2024options . vnode = vnode => {
2125 if ( vnode && typeof vnode . type === 'function' && ! isBuiltIn ( vnode . type ) ) {
22- const vnodes = vnodesForComponent . get ( vnode . type ) ;
23- if ( ! vnodes ) {
24- vnodesForComponent . set ( vnode . type , [ vnode ] ) ;
25- } else {
26- vnodes . push ( vnode ) ;
27- }
28-
2926 const foundType = getMappedVnode ( vnode . type ) ;
3027 if ( foundType !== vnode . type ) {
31- const vnodes = vnodesForComponent . get ( foundType ) ;
32- if ( ! vnodes ) {
33- vnodesForComponent . set ( foundType , [ vnode ] ) ;
34- } else {
35- vnodes . push ( vnode ) ;
28+ vnode . type = foundType ;
29+ if (
30+ vnode [ VNODE_COMPONENT ] &&
31+ 'prototype' in vnode . type &&
32+ vnode . type . prototype . render
33+ ) {
34+ vnode [ VNODE_COMPONENT ] . constructor = vnode . type ;
3635 }
3736 }
37+ }
3838
39- vnode . type = foundType ;
40- if (
41- vnode [ VNODE_COMPONENT ] &&
42- 'prototype' in vnode . type &&
43- vnode . type . prototype . render
44- ) {
45- vnode [ VNODE_COMPONENT ] . constructor = vnode . type ;
39+ if ( oldVnode ) oldVnode ( vnode ) ;
40+ } ;
41+
42+ const oldDiff = options . __b ;
43+ options . __b = vnode => {
44+ if ( vnode && typeof vnode . type === 'function' && ! isBuiltIn ( vnode . type ) ) {
45+ const vnodes = vnodesForComponent . get ( vnode . type ) ;
46+ if ( ! vnodes ) {
47+ vnodesForComponent . set ( vnode . type , [ vnode ] ) ;
48+ } else {
49+ vnodes . push ( vnode ) ;
4650 }
4751 }
4852
49- if ( oldVnode ) oldVnode ( vnode ) ;
53+ if ( oldDiff ) oldDiff ( vnode ) ;
5054} ;
5155
5256const oldDiffed = options . diffed ;
0 commit comments