<commit_before>// @flow

import type { AppState } from '../redux/redux-setup';
import type { Orientations } from 'react-native-orientation-locker';
import type { DispatchActionPayload } from 'lib/utils/action-utils';
import { updateDeviceOrientationActionType } from '../redux/action-types';

import * as React from 'react';
import PropTypes from 'prop-types';
import Orientation from 'react-native-orientation-locker';

import { connect } from 'lib/utils/redux-utils';

type Props = {
  // Redux state
  deviceOrientation: Orientations,
  // Redux dispatch functions
  dispatchActionPayload: DispatchActionPayload,
};
class OrientationHandler extends React.PureComponent<Props> {

  static propTypes = {
    deviceOrientation: PropTypes.string.isRequired,
    dispatchActionPayload: PropTypes.func.isRequired,
  };

  componentDidMount() {
    Orientation.addOrientationListener(this.updateOrientation);
  }

  componentWillUnmount() {
    Orientation.removeOrientationListener(this.updateOrientation);
  }

  componentDidUpdate(prevProps: Props) {
    if (this.props.deviceOrientation !== prevProps.deviceOrientation) {
      Orientation.getOrientation(orientation => {
        if (orientation !== this.props.deviceOrientation) {
          // If the orientation in Redux changes, but it doesn't match what's
          // being reported by native, then update Redux. This should only
          // happen when importing a frozen app state via React Native Debugger
          this.updateOrientation(orientation);
        }
      });
    }
  }

  updateOrientation = orientation => {
    this.props.dispatchActionPayload(
      updateDeviceOrientationActionType,
      orientation,
    );
  }

  render() {
    return null;
  }

}

export default connect(
  (state: AppState) => ({
    deviceOrientation: state.deviceOrientation,
  }),
  null,
  true,
)(OrientationHandler);
<commit_msg>[native] Only dispatch UPDATE_DEVICE_ORIENTATION on changes<commit_after>// @flow

import type { AppState } from '../redux/redux-setup';
import type { Orientations } from 'react-native-orientation-locker';
import type { DispatchActionPayload } from 'lib/utils/action-utils';
import { updateDeviceOrientationActionType } from '../redux/action-types';

import * as React from 'react';
import PropTypes from 'prop-types';
import Orientation from 'react-native-orientation-locker';

import { connect } from 'lib/utils/redux-utils';

type Props = {
  // Redux state
  deviceOrientation: Orientations,
  // Redux dispatch functions
  dispatchActionPayload: DispatchActionPayload,
};
class OrientationHandler extends React.PureComponent<Props> {

  static propTypes = {
    deviceOrientation: PropTypes.string.isRequired,
    dispatchActionPayload: PropTypes.func.isRequired,
  };

  componentDidMount() {
    Orientation.addOrientationListener(this.updateOrientation);
  }

  componentWillUnmount() {
    Orientation.removeOrientationListener(this.updateOrientation);
  }

  componentDidUpdate(prevProps: Props) {
    if (this.props.deviceOrientation !== prevProps.deviceOrientation) {
      // Most of the time, this is triggered as a result of an action dispatched
      // by the handler attached above, so the updateOrientation call should be
      // a no-op. This conditional is here to correct Redux state when it is
      // imported from another device context.
      Orientation.getOrientation(this.updateOrientation);
    }
  }

  updateOrientation = orientation => {
    if (orientation !== this.props.deviceOrientation) {
      this.props.dispatchActionPayload(
        updateDeviceOrientationActionType,
        orientation,
      );
    }
  }

  render() {
    return null;
  }

}

export default connect(
  (state: AppState) => ({
    deviceOrientation: state.deviceOrientation,
  }),
  null,
  true,
)(OrientationHandler);

{'fraction_non_alphanumeric': 0.10133542812254517, 'fraction_numerical': 0.0, 'mean_word_length': 3.8110831234256928, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '405956', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1008, 'n_words': 261}