Example #1
0
 const onReadyStateChange = ErrorUtils.guard(readyState => {
   const {aborted, done, error, ready} = readyState;
   const isComplete = aborted || done || error;
   if (isComplete && this.pending === current) {
     this.pending = null;
   }
   let partialState;
   if (ready) {
     // Only update query data if variables changed. Otherwise, `querySet`
     // and `fragmentPointers` will be empty, and `nextVariables` will be
     // equal to `lastVariables`.
     this._fragmentPointers = fragmentPointers;
     this._updateFragmentResolvers(this.context.relay.environment);
     const queryData = this._getQueryData(this.props);
     partialState = {
       queryData,
       rawVariables,
       relayProp: {
         ...this.state.relayProp,
         pendingVariables: null,
         variables: nextVariables,
       },
     };
   } else {
     partialState = {
       relayProp: {
         ...this.state.relayProp,
         pendingVariables: isComplete ? null : nextVariables,
       },
     };
   }
   const mounted = this.mounted;
   if (mounted) {
     const updateProfiler = RelayProfiler.profile('RelayContainer.update');
     relayUnstableBatchedUpdates(() => {
       this.setState(partialState, () => {
         updateProfiler.stop();
         if (isComplete) {
           completeProfiler.stop();
         }
       });
       if (callback) {
         callback.call(
           // eslint-disable-next-line react/no-string-refs
           this.refs.component || null,
           {...readyState, mounted},
         );
       }
     });
   } else {
     if (callback) {
       callback({...readyState, mounted});
     }
     if (isComplete) {
       completeProfiler.stop();
     }
   }
 }, 'RelayContainer.onReadyStateChange');
Example #2
0
 var onReadyStateChange = ErrorUtils.guard(readyState => {
   var {aborted, done, error, ready} = readyState;
   var isComplete = aborted || done || error;
   if (isComplete && this.pending === current) {
     this.pending = null;
   }
   var partialState;
   if (ready && fragmentPointers) {
     // Only update query data if variables changed. Otherwise, `querySet`
     // and `fragmentPointers` will be empty, and `nextVariables` will be
     // equal to `lastVariables`.
     this._fragmentPointers = fragmentPointers;
     this._updateFragmentResolvers(this.context.relay);
     var queryData = this._getQueryData(this.props);
     partialState = {variables: nextVariables, queryData};
   } else {
     partialState = {};
   }
   var mounted = this.mounted;
   if (mounted) {
     var updateProfiler = RelayProfiler.profile('RelayContainer.update');
     relayUnstableBatchedUpdates(() => {
       this.setState(partialState, () => {
         updateProfiler.stop();
         if (isComplete) {
           completeProfiler.stop();
         }
       });
       if (callback) {
         callback.call(
           this.refs.component || null,
           {...readyState, mounted}
         );
       }
     });
   } else {
     if (callback) {
       callback({...readyState, mounted});
     }
     if (isComplete) {
       completeProfiler.stop();
     }
   }
 }, 'RelayContainer.onReadyStateChange');