@@ -16,14 +16,14 @@ import {
1616 REACT_FORWARD_REF_TYPE ,
1717} from 'shared/ReactSymbols' ;
1818
19- type BlockQueryFunction < Args : Iterable < any > , Data > = ( ...args : Args ) => Data ;
19+ type BlockLoadFunction < Args : Iterable < any > , Data > = ( ...args : Args ) => Data ;
2020export type BlockRenderFunction < Props , Data > = (
2121 props : Props ,
2222 data : Data ,
2323) => React$Node ;
2424
2525type Payload < Props , Args : Iterable < any > , Data > = {
26- query : BlockQueryFunction < Args , Data> ,
26+ load : BlockLoadFunction < Args , Data> ,
2727 args : Args ,
2828 render : BlockRenderFunction < Props , Data> ,
2929} ;
@@ -44,20 +44,20 @@ function lazyInitializer<Props, Args: Iterable<any>, Data>(
4444) : BlockComponent < Props , Data > {
4545 return {
4646 $$typeof : REACT_BLOCK_TYPE ,
47- _data : payload . query . apply ( null , payload . args ) ,
47+ _data : payload . load . apply ( null , payload . args ) ,
4848 _render : payload . render ,
4949 } ;
5050}
5151
5252export function block < Args : Iterable < any > , Props , Data > (
53- query : BlockQueryFunction < Args , Data > ,
5453 render : BlockRenderFunction < Props , Data > ,
54+ load ? : BlockLoadFunction < Args , Data > ,
5555) : ( ...args : Args ) = > Block < Props > {
5656 if ( __DEV__ ) {
57- if ( typeof query !== 'function' ) {
57+ if ( load !== undefined && typeof load !== 'function' ) {
5858 console . error (
59- 'Blocks require a query function but was given %s.' ,
60- query === null ? 'null' : typeof query ,
59+ 'Blocks require a load function, if provided, but was given %s.' ,
60+ load === null ? 'null' : typeof load ,
6161 ) ;
6262 }
6363 if ( render != null && render . $$typeof === REACT_MEMO_TYPE ) {
@@ -97,11 +97,28 @@ export function block<Args: Iterable<any>, Props, Data>(
9797 }
9898 }
9999
100+ if ( load === undefined ) {
101+ return function ( ) : Block < Props > {
102+ let blockComponent : BlockComponent < Props , void > = {
103+ $$typeof : REACT_BLOCK_TYPE ,
104+ _data : undefined ,
105+ // $FlowFixMe: Data must be void in this scenario.
106+ _render : render ,
107+ } ;
108+
109+ // $FlowFixMe
110+ return blockComponent ;
111+ } ;
112+ }
113+
114+ // Trick to let Flow refine this.
115+ let loadFn = load ;
116+
100117 return function ( ) : Block < Props > {
101118 let args : Args = arguments ;
102119
103120 let payload : Payload < Props , Args , Data > = {
104- query : query ,
121+ load : loadFn ,
105122 args : args ,
106123 render : render ,
107124 } ;
0 commit comments