@@ -7,21 +7,27 @@ import { HYDRATED_CLASS, PLATFORM_FLAGS } from './runtime-constants';
77import { renderVdom } from './vdom/vdom-render' ;
88
99
10- export const safeCall = async ( instance : any , method : string , arg ?: any ) => {
10+ export const safeCall = ( instance : any , method : string , arg ?: any ) => {
1111 if ( instance && instance [ method ] ) {
1212 try {
13- await instance [ method ] ( arg ) ;
13+ return instance [ method ] ( arg ) ;
1414 } catch ( e ) {
1515 consoleError ( e ) ;
1616 }
1717 }
18+ return undefined ;
1819} ;
1920
20- export const scheduleUpdate = async ( elm : d . HostElement , hostRef : d . HostRef , cmpMeta : d . ComponentRuntimeMeta , isInitialLoad : boolean ) => {
21+ const then = ( promise : Promise < any > , thenFn : ( ) => any ) => {
22+ return promise && promise . then ? promise . then ( thenFn ) : thenFn ( ) ;
23+ } ;
24+
25+ export const scheduleUpdate = ( elm : d . HostElement , hostRef : d . HostRef , cmpMeta : d . ComponentRuntimeMeta , isInitialLoad : boolean ) => {
2126 if ( BUILD . taskQueue && BUILD . updatable ) {
2227 hostRef . $flags$ |= HOST_FLAGS . isQueuedForUpdate ;
2328 }
2429 const instance = BUILD . lazyLoad ? hostRef . $lazyInstance$ : elm as any ;
30+ let promise : Promise < void > ;
2531 if ( isInitialLoad ) {
2632 if ( BUILD . hostListener ) {
2733 hostRef . $flags$ |= HOST_FLAGS . isListenReady ;
@@ -32,31 +38,33 @@ export const scheduleUpdate = async (elm: d.HostElement, hostRef: d.HostRef, cmp
3238 }
3339 emitLifecycleEvent ( elm , 'componentWillLoad' ) ;
3440 if ( BUILD . cmpWillLoad ) {
35- await safeCall ( instance , 'componentWillLoad' ) ;
41+ promise = safeCall ( instance , 'componentWillLoad' ) ;
3642 }
3743
3844 } else {
3945 emitLifecycleEvent ( elm , 'componentWillUpdate' ) ;
4046
4147 if ( BUILD . cmpWillUpdate ) {
42- await safeCall ( instance , 'componentWillUpdate' ) ;
48+ promise = safeCall ( instance , 'componentWillUpdate' ) ;
4349 }
4450 }
4551
4652 emitLifecycleEvent ( elm , 'componentWillRender' ) ;
4753 if ( BUILD . cmpWillRender ) {
48- await safeCall ( instance , 'componentWillRender' ) ;
54+ promise = then ( promise , ( ) => safeCall ( instance , 'componentWillRender' ) ) ;
4955 }
5056
5157 // there is no ancestorc omponent or the ancestor component
5258 // has already fired off its lifecycle update then
5359 // fire off the initial update
54- if ( BUILD . taskQueue ) {
55- writeTask ( ( ) => updateComponent ( elm , hostRef , cmpMeta , instance , isInitialLoad ) ) ;
56- } else {
57- // syncronuously write DOM
58- updateComponent ( elm , hostRef , cmpMeta , instance , isInitialLoad ) ;
60+ const update = ( ) => updateComponent ( elm , hostRef , cmpMeta , instance , isInitialLoad ) ;
61+ if ( promise ) {
62+ return promise . then ( BUILD . taskQueue
63+ ? ( ) => writeTask ( update )
64+ : update
65+ ) ;
5966 }
67+ return update ( ) ;
6068} ;
6169
6270const updateComponent = ( elm : d . RenderNode , hostRef : d . HostRef , cmpMeta : d . ComponentRuntimeMeta , instance : any , isInitialLoad : boolean ) => {
0 commit comments