function checkShouldComponentUpdate(workInProgress, oldProps, newProps, oldState, newState, newContext) {
    if (oldProps === null || workInProgress.updateQueue !== null && workInProgress.updateQueue.hasForceUpdate) {
      // If the workInProgress already has an Update effect, return true
      return true;
    }

    var instance = workInProgress.stateNode;
    if (typeof instance.shouldComponentUpdate === 'function') {
      if (process.env.NODE_ENV !== 'production') {
        startPhaseTimer(workInProgress, 'shouldComponentUpdate');
      }
      var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, newContext);
      if (process.env.NODE_ENV !== 'production') {
        stopPhaseTimer();
      }

      if (process.env.NODE_ENV !== 'production') {
        process.env.NODE_ENV !== 'production' ? warning(shouldUpdate !== undefined, '%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', getComponentName(workInProgress) || 'Unknown') : void 0;
      }

      return shouldUpdate;
    }

    var type = workInProgress.type;
    if (type.prototype && type.prototype.isPureReactComponent) {
      return !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState);
    }

    return true;
  }
 shouldComponentUpdate(nextProps, nextState) {
   // draggable does not affect inner components
   return !shallowEqual(
     omit(this.props, ['draggable']),
     omit(nextProps, ['draggable'])
   ) || !shallowEqual(this.state, nextState);
 }
  function checkShouldComponentUpdate(workInProgress, oldProps, newProps, oldState, newState, newContext) {
    if (oldProps === null || (workInProgress.updateQueue !== null && workInProgress.updateQueue.hasForceUpdate)) {
      // If the workInProgress already has an Update effect, return true
      return true;
    }

    const instance = workInProgress.stateNode;
    if (typeof instance.shouldComponentUpdate === 'function') {
      const shouldUpdate = instance.shouldComponentUpdate(newProps, newState, newContext);

      if (__DEV__) {
        warning(
          shouldUpdate !== undefined,
          '%s.shouldComponentUpdate(): Returned undefined instead of a ' +
          'boolean value. Make sure to return true or false.',
          getComponentName(workInProgress)
        );
      }

      return shouldUpdate;
    }

    const type = workInProgress.type;
    if (type.prototype && type.prototype.isPureReactComponent) {
      return (
        !shallowEqual(oldProps, newProps) ||
        !shallowEqual(oldState, newState)
      );
    }

    return true;
  }
  ReactShallowRenderer.prototype._updateClassComponent = function _updateClassComponent(element, context) {
    var props = element.props,
        type = element.type;


    var oldState = this._instance.state || emptyObject;
    var oldProps = this._instance.props;

    if (oldProps !== props) {
      // In order to support react-lifecycles-compat polyfilled components,
      // Unsafe lifecycles should not be invoked for components using the new APIs.
      if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
        if (typeof this._instance.componentWillReceiveProps === 'function') {
          this._instance.componentWillReceiveProps(props, context);
        }
        if (typeof this._instance.UNSAFE_componentWillReceiveProps === 'function') {
          this._instance.UNSAFE_componentWillReceiveProps(props, context);
        }
      }

      this._updateStateFromStaticLifecycle(props);
    }

    // Read state after cWRP in case it calls setState
    var state = this._newState || oldState;

    var shouldUpdate = true;
    if (this._forcedUpdate) {
      shouldUpdate = true;
      this._forcedUpdate = false;
    } else if (typeof this._instance.shouldComponentUpdate === 'function') {
      shouldUpdate = !!this._instance.shouldComponentUpdate(props, state, context);
    } else if (type.prototype && type.prototype.isPureReactComponent) {
      shouldUpdate = !shallowEqual(oldProps, props) || !shallowEqual(oldState, state);
    }

    if (shouldUpdate) {
      // In order to support react-lifecycles-compat polyfilled components,
      // Unsafe lifecycles should not be invoked for components using the new APIs.
      if (typeof element.type.getDerivedStateFromProps !== 'function' && typeof this._instance.getSnapshotBeforeUpdate !== 'function') {
        if (typeof this._instance.componentWillUpdate === 'function') {
          this._instance.componentWillUpdate(props, state, context);
        }
        if (typeof this._instance.UNSAFE_componentWillUpdate === 'function') {
          this._instance.UNSAFE_componentWillUpdate(props, state, context);
        }
      }
    }

    this._instance.context = context;
    this._instance.props = props;
    this._instance.state = state;

    if (shouldUpdate) {
      this._rendered = this._instance.render();
    }
    // Intentionally do not call componentDidUpdate()
    // because DOM refs are not available.
  };
  function checkShouldComponentUpdate(
    workInProgress,
    oldProps,
    newProps,
    oldState,
    newState,
    newContext,
  ) {
    if (
      oldProps === null ||
      (workInProgress.updateQueue !== null &&
        workInProgress.updateQueue.hasForceUpdate)
    ) {
      // If the workInProgress already has an Update effect, return true
      return true;
    }

    const instance = workInProgress.stateNode;
    const type = workInProgress.type;
    if (typeof instance.shouldComponentUpdate === 'function') {
      startPhaseTimer(workInProgress, 'shouldComponentUpdate');
      const shouldUpdate = instance.shouldComponentUpdate(
        newProps,
        newState,
        newContext,
      );
      stopPhaseTimer();

      // Simulate an async bailout/interruption by invoking lifecycle twice.
      if (debugRenderPhaseSideEffects) {
        instance.shouldComponentUpdate(newProps, newState, newContext);
      }

      if (__DEV__) {
        warning(
          shouldUpdate !== undefined,
          '%s.shouldComponentUpdate(): Returned undefined instead of a ' +
            'boolean value. Make sure to return true or false.',
          getComponentName(workInProgress) || 'Unknown',
        );
      }

      return shouldUpdate;
    }

    if (type.prototype && type.prototype.isPureReactComponent) {
      return (
        !shallowEqual(oldProps, newProps) || !shallowEqual(oldState, newState)
      );
    }

    return true;
  }
Example #6
0
 Subscription.prototype.componentWillReceiveProps = function (nextProps, nextContext) {
     var nextClient = getClient(nextProps, nextContext);
     if (shallowEqual$2(this.props.variables, nextProps.variables) &&
         this.client === nextClient &&
         this.props.subscription === nextProps.subscription) {
         return;
     }
     var shouldResubscribe = nextProps.shouldResubscribe;
     if (typeof shouldResubscribe === 'function') {
         shouldResubscribe = !!shouldResubscribe(this.props, nextProps);
     }
     var shouldNotResubscribe = shouldResubscribe === false;
     if (this.client !== nextClient) {
         this.client = nextClient;
     }
     if (!shouldNotResubscribe) {
         this.endSubscription();
         delete this.queryObservable;
         this.initialize(nextProps);
         this.startSubscription();
         this.setState(this.getInitialState());
         return;
     }
     this.initialize(nextProps);
     this.startSubscription();
 };
Example #7
0
/**
 * Poll selection to see whether it's changed.
 *
 * @param {object} nativeEvent
 * @return {?SyntheticEvent}
 */
function constructSelectEvent(nativeEvent, nativeEventTarget) {
  // Ensure we have the right element, and that the user is not dragging a
  // selection (this matches native `select` event behavior). In HTML5, select
  // fires only on input and textarea thus if there's no focused element we
  // won't dispatch.
  if (
    mouseDown || activeElement == null || activeElement !== getActiveElement()
  ) {
    return null;
  }

  // Only fire when selection has actually changed.
  var currentSelection = getSelection(activeElement);
  if (!lastSelection || !shallowEqual(lastSelection, currentSelection)) {
    lastSelection = currentSelection;

    var syntheticEvent = SyntheticEvent.getPooled(
      eventTypes.select,
      activeElementInst,
      nativeEvent,
      nativeEventTarget,
    );

    syntheticEvent.type = 'select';
    syntheticEvent.target = activeElement;

    EventPropagators.accumulateTwoPhaseDispatches(syntheticEvent);

    return syntheticEvent;
  }

  return null;
}
Example #8
0
function checkAndWarnForMutatedStyle(style1, style2, component) {
  if (style1 == null || style2 == null) {
    return;
  }
  if (shallowEqual(style1, style2)) {
    return;
  }

  var componentName = component._tag;
  var owner = component._currentElement._owner;
  var ownerName;
  if (owner) {
    ownerName = owner.getName();
  }

  var hash = ownerName + '|' + componentName;

  if (styleMutationWarning.hasOwnProperty(hash)) {
    return;
  }

  styleMutationWarning[hash] = true;

  process.env.NODE_ENV !== 'production' ? warning(false, '`%s` was passed a style object that has previously been mutated. ' + 'Mutating `style` is deprecated. Consider cloning it beforehand. Check ' + 'the `render` %s. Previous style: %s. Mutated style: %s.', componentName, owner ? 'of `' + ownerName + '`' : 'using <' + componentName + '>', friendlyStringify(style1), friendlyStringify(style2)) : void 0;
}
Example #9
0
 WithStateHandlers.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
   var propsChanged = nextProps !== this.props;
   // the idea is to skip render if stateUpdater handler return undefined
   // this allows to create no state update handlers with access to state and props
   var stateChanged = !shallowEqual(nextState, this.state);
   return propsChanged || stateChanged;
 };
Example #10
0
 shouldComponentUpdate(nextProps, nextState) {
   if (!shallowEqual(this.state, nextState)) {
     return true;
   }
   return ["config", "instances", "applications"].includes(
     nextProps.modelEvent
   );
 }
Example #11
0
 next: function (_a) {
     var data = _a.data;
     if (initial && initial.networkStatus === 7 && shallowEqual(initial.data, data)) {
         initial = undefined;
         return;
     }
     initial = undefined;
     _this.updateCurrentData();
 },
Example #12
0
export const isActive = (state, {pathname, query}) => {
  const {
    pathname: newPathname, cleanQuery
  } = changeParams(state, {pathname, query});


  return shallowEqual(cleanQuery, state.cleanQuery) &&
    newPathname === state.pathname;
};
Example #13
0
  _updateClassComponent(type, props, context) {
    const oldState = this._instance.state || emptyObject;
    const oldProps = this._instance.props;

    if (
      oldProps !== props &&
      typeof this._instance.componentWillReceiveProps === 'function'
    ) {
      this._instance.componentWillReceiveProps(props, context);
    }
    // Read state after cWRP in case it calls setState
    const state = this._newState || oldState;

    let shouldUpdate = true;
    if (this._forcedUpdate) {
      shouldUpdate = true;
      this._forcedUpdate = false;
    } else if (typeof this._instance.shouldComponentUpdate === 'function') {
      shouldUpdate = !!this._instance.shouldComponentUpdate(
        props,
        state,
        context,
      );
    } else if (type.prototype && type.prototype.isPureReactComponent) {
      shouldUpdate =
        !shallowEqual(oldProps, props) || !shallowEqual(oldState, state);
    }

    if (shouldUpdate) {
      if (typeof this._instance.componentWillUpdate === 'function') {
        this._instance.componentWillUpdate(props, state, context);
      }
    }

    this._instance.context = context;
    this._instance.props = props;
    this._instance.state = state;

    if (shouldUpdate) {
      this._rendered = this._instance.render();
    }
    // Intentionally do not call componentDidUpdate()
    // because DOM refs are not available.
  }
Example #14
0
 componentWillUpdate(nextProps, nextState) {
   if (this.state.selectedTopics !== nextState.selectedTopics) {
     const changedTopics = !shallowEqual(
       nextProps.selectedTopics,
       nextState.selectedTopics,
     );
     const toValue = changedTopics ? 1 : 0;
     Animated.spring(this.state.anim, {toValue}).start();
   }
 }
Example #15
0
 RelayContainer.prototype._initialize = function _initialize(props, environment, route, prevVariables) {
   var nextVariables = getVariablesWithPropOverrides(spec, props, prevVariables);
   this._updateFragmentPointers(props, route, nextVariables);
   this._updateFragmentResolvers(environment);
   return {
     queryData: this._getQueryData(props),
     relayProp: this.state.relayProp.route === route && shallowEqual(this.state.relayProp.variables, nextVariables) ? this.state.relayProp : _extends({}, this.state.relayProp, {
       route: route,
       variables: nextVariables
     })
   };
 };
Example #16
0
 Mutation.prototype.componentWillReceiveProps = function (nextProps, nextContext) {
     var nextClient = getClient(nextProps, nextContext);
     if (shallowEqual$1(this.props, nextProps) && this.client === nextClient) {
         return;
     }
     if (this.props.mutation !== nextProps.mutation) {
         this.verifyDocumentIsMutation(nextProps.mutation);
     }
     if (this.client !== nextClient) {
         this.client = nextClient;
         this.setState(initialState);
     }
 };
/**
 * Whether two routes are the same.
 */
function areRoutesShallowEqual(
  one: ?NavigationRoute,
  two: ?NavigationRoute,
): boolean {
  if (!one || !two) {
    return one === two;
  }

  if (one.key !== two.key) {
    return false;
  }

  return shallowEqual(one, two);
}
Example #18
0
function onStateChange (store) {
  const {scenario, user} = store.getState()
  const {bundleId, name, id, variants} = scenario

  const newStoredState = JSON.stringify({
    scenario: {
      id
    },
    user
  })
  if (newStoredState !== storedState) {
    // Save parts of the state to localStorage
    window.localStorage.setItem('state', JSON.stringify({
      scenario: {
        id
      },
      user
    }))
    storedState = newStoredState
  }

  const newProjectState = {
    bundleId,
    id,
    name,
    variants
  }
  if (!shallowEqual(newProjectState, projectState)) {
    window.requestAnimationFrame(function () {
      // NB this won't overwrite the project when it is being loaded as the reducer for switching projects loads the modifications
      if (id && name) {
        projectStore.save({
          bundleId,
          id,
          name,
          variants
        })
      }
      projectState = newProjectState
    })
  }
}
Example #19
0
export const changeParams = (state, params) => {
  const {defaultParams, query, pathname} = state;
  const newQuery = sortedObject({...defaultParams, ...query, ...safeQuery(params.query)});
  const newPathname = params.pathname || pathname;

  if (shallowEqual(newQuery, query) && newPathname === pathname) {
    return state;
  }

  const cleanQuery = cleanupQuery({query: newQuery, defaultParams});
  const currentRoute = matchRoute(state.routes, defaultRoute)(newPathname);

  return {
    ...state,
    query: newQuery,
    pathname: newPathname,
    cleanQuery,
    currentRoute
  };
};
Example #20
0
 Query.prototype.componentWillReceiveProps = function (nextProps, nextContext) {
     if (nextProps.skip && !this.props.skip) {
         this.removeQuerySubscription();
         return;
     }
     var nextClient = getClient(nextProps, nextContext);
     if (shallowEqual(this.props, nextProps) && this.client === nextClient) {
         return;
     }
     if (this.client !== nextClient) {
         this.client = nextClient;
         this.removeQuerySubscription();
         this.queryObservable = null;
         this.previousData = {};
         this.updateQuery(nextProps);
     }
     if (this.props.query !== nextProps.query) {
         this.removeQuerySubscription();
     }
     this.updateQuery(nextProps);
     if (nextProps.skip)
         return;
     this.startQuerySubscription();
 };
Example #21
0
 var hoc = shouldUpdate(function (props, nextProps) {
   return !shallowEqual(props, nextProps);
 });
Example #22
0
/**
 * Does a shallow comparison for props and state.
 * See ReactComponentWithPureRenderMixin
 */
function shallowCompare(instance, nextProps, nextState) {
  return !shallowEqual(instance.props, nextProps) || !shallowEqual(instance.state, nextState);
}
  updateComponent: function(
    transaction,
    prevParentElement,
    nextParentElement,
    prevUnmaskedContext,
    nextUnmaskedContext
  ) {
    var inst = this._instance;
    invariant(
      inst != null,
      'Attempted to update component `%s` that has already been unmounted ' +
      '(or failed to mount).',
      this.getName() || 'ReactCompositeComponent'
    );

    var willReceive = false;
    var nextContext;

    // Determine if the context has changed or not
    if (this._context === nextUnmaskedContext) {
      nextContext = inst.context;
    } else {
      nextContext = this._processContext(nextUnmaskedContext);
      willReceive = true;
    }

    var prevProps = prevParentElement.props;
    var nextProps = nextParentElement.props;

    // Not a simple state update but a props update
    if (prevParentElement !== nextParentElement) {
      willReceive = true;
    }

    // An update here will schedule an update but immediately set
    // _pendingStateQueue which will ensure that any state updates gets
    // immediately reconciled instead of waiting for the next batch.
    if (willReceive && inst.componentWillReceiveProps) {
      const beforeState = inst.state;
      if (__DEV__) {
        measureLifeCyclePerf(
          () => inst.componentWillReceiveProps(nextProps, nextContext),
          this._debugID,
          'componentWillReceiveProps',
        );
      } else {
        inst.componentWillReceiveProps(nextProps, nextContext);
      }
      const afterState = inst.state;
      if (beforeState !== afterState) {
        inst.state = beforeState;
        inst.updater.enqueueReplaceState(inst, afterState);
        if (__DEV__) {
          warning(
            false,
            '%s.componentWillReceiveProps(): Assigning directly to ' +
            'this.state is deprecated (except inside a component\'s ' +
            'constructor). Use setState instead.',
            this.getName() || 'ReactCompositeComponent'
          );
        }
      }
    }

    // If updating happens to enqueue any new updates, we shouldn't execute new
    // callbacks until the next render happens, so stash the callbacks first.
    var callbacks = this._pendingCallbacks;
    this._pendingCallbacks = null;

    var nextState = this._processPendingState(nextProps, nextContext);
    var shouldUpdate = true;
    if (!this._pendingForceUpdate) {
      var prevState = inst.state;
      shouldUpdate = willReceive || nextState !== prevState;
      if (inst.shouldComponentUpdate) {
        if (__DEV__) {
          shouldUpdate = measureLifeCyclePerf(
            () => inst.shouldComponentUpdate(nextProps, nextState, nextContext),
            this._debugID,
            'shouldComponentUpdate'
          );
        } else {
          shouldUpdate = inst.shouldComponentUpdate(nextProps, nextState, nextContext);
        }
      } else {
        if (this._compositeType === ReactCompositeComponentTypes.PureClass) {
          shouldUpdate =
            !shallowEqual(prevProps, nextProps) ||
            !shallowEqual(inst.state, nextState);
        }
      }
    }

    if (__DEV__) {
      warning(
        shouldUpdate !== undefined,
        '%s.shouldComponentUpdate(): Returned undefined instead of a ' +
        'boolean value. Make sure to return true or false.',
        this.getName() || 'ReactCompositeComponent'
      );
    }

    this._updateBatchNumber = null;
    if (shouldUpdate) {
      this._pendingForceUpdate = false;
      // Will set `this.props`, `this.state` and `this.context`.
      this._performComponentUpdate(
        nextParentElement,
        nextProps,
        nextState,
        nextContext,
        transaction,
        nextUnmaskedContext
      );
    } else {
      // If it's determined that a component should not update, we still want
      // to set props and state but we shortcut the rest of the update.
      this._currentElement = nextParentElement;
      this._context = nextUnmaskedContext;
      inst.props = nextProps;
      inst.state = nextState;
      inst.context = nextContext;
    }

    if (callbacks) {
      for (var j = 0; j < callbacks.length; j++) {
        transaction.getReactMountReady().enqueue(
          callbacks[j],
          this.getPublicInstance()
        );
      }
    }
  },
const tradingTimesAreEqual = (prevProps, nextProps) =>
    shallowEqual(nextProps.tradingTimes, prevProps.tradingTimes);
const contractsAreEqual = (prevProps, nextProps) =>
    shallowEqual(prevProps.contract, nextProps.contract) &&
        shallowEqual(prevProps.trade, nextProps.trade);
Example #26
0
/**
 * Tells if a component should update given it's next props
 * and state.
 *
 * @param object nextProps Next props.
 * @param object nextState Next state.
 */
function shouldComponentUpdate(nextProps, nextState) {
  return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
}
Example #27
0
 RelayQueryNode.prototype.isEquivalent = function isEquivalent(that) {
   return this.__concreteNode__ === that.__concreteNode__ && this.__route__ === that.__route__ && shallowEqual(this.__variables__, that.__variables__);
 };
Example #28
0
 var hoc = shouldUpdate(function (props, nextProps) {
   return !shallowEqual(pick(nextProps, propKeys), pick(props, propKeys));
 });
 shouldComponentUpdate(nextProps: Object, nextState: Object) {
   return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState)
 }
Example #30
0
 var shouldMap = typeof shouldMapOrKeys === 'function' ? shouldMapOrKeys : function (props, nextProps) {
   return !shallowEqual(pick(props, shouldMapOrKeys), pick(nextProps, shouldMapOrKeys));
 };