<commit_before>'use strict';

var React = require('react-native');
var Reflux = require('reflux');
var store = require('react-native-simple-store');

var {
  ListView,
  Platform,
  Text,
  TouchableHighlight,
  View,
  Image,
} = React;

var {
  RefresherListView,
} = require('react-native-refresher');

// Flux
var StockActions = require('../../Utils/Stock/actions');
var StockStore = require('../../Utils/Stock/store');

// View Elements
var StockCell = require('./Elements/StockCell');

// Styles
var styles = require('./style');

var ViewReactClass = React.createClass({
  mixins: [Reflux.ListenerMixin],

  onUpdateStocks: function(result) {
    this._genRows(result);
  },

  onDeleteStock: function(result) {
    this._genRows(result);
  },

  getInitialState: function() {
    return {
      dataSource: new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2}),
      loaded: false,
      middleBlockShowing: 'DETAILS',
      chartTimeSpan: '1D',
    };
  },

  componentDidMount: function() {
    this.listenTo(StockStore, this.onDeleteStock);
    this.listenTo(StockStore, this.onUpdateStocks);

    StockActions.updateStocks();
  },

  _genRows: function(result) {
    var that = this;
    store.get('watchlist').then((result) => {
      this.setState({
        dataSource: that.state.dataSource.cloneWithRows(result),
        loaded: true,
        selectedStock: that.state.selectedStock || result[0],
      });
    });

    store.get('watchlistResult').then((result) => {
      this.setState({
        watchlistResult: result,
      });
    });
  },

  render: function() {
    if(!this.state.loaded){
      return(
        <View style={styles.container}>
          <Text style={styles.loadingText}>
            Loading...
          </Text>
        </View>
      );
    }
    return (
      this.renderListView()
    );
  },

  renderListView: function() {
    return(
      <View style={styles.container}>
        <View style={styles.stocksBlock}>
          <RefresherListView
            dataSource={this.state.dataSource}
            onRefresh={this._genRows}
            renderRow={this.renderStockCell}
            style={styles.stocksListView}/>
        </View>
        <View style={styles.middleBlock}>
          {(() => {
            switch (this.state.middleBlockShowing) {
              case 'DETAILS':              return this.renderDetails();
              case 'CHART':                return this.renderChart();
              case 'NEWS':                return this.renderNews();
              default:                     return this.renderDetails();
            }
          })()}
        </View><commit_msg>fix on pull refresh<commit_after>'use strict';

var React = require('react-native');
var Reflux = require('reflux');
var store = require('react-native-simple-store');

var {
  ListView,
  Platform,
  Text,
  TouchableHighlight,
  View,
  Image,
} = React;

var {
  RefresherListView,
} = require('react-native-refresher');

// Flux
var StockActions = require('../../Utils/Stock/actions');
var StockStore = require('../../Utils/Stock/store');

// View Elements
var StockCell = require('./Elements/StockCell');

// Styles
var styles = require('./style');

var ViewReactClass = React.createClass({
  mixins: [Reflux.ListenerMixin],

  onUpdateStocks: function(result) {
    this._genRows(result);
  },

  onDeleteStock: function(result) {
    this._genRows(result);
  },

  getInitialState: function() {
    return {
      dataSource: new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2}),
      loaded: false,
      middleBlockShowing: 'DETAILS',
      chartTimeSpan: '1D',
    };
  },

  componentDidMount: function() {
    this.listenTo(StockStore, this.onDeleteStock);
    this.listenTo(StockStore, this.onUpdateStocks);

    StockActions.updateStocks();
  },

  _genRows: function(result) {
    var that = this;
    store.get('watchlist').then((result) => {
      this.setState({
        dataSource: that.state.dataSource.cloneWithRows(result),
        loaded: true,
        selectedStock: that.state.selectedStock || result[0],
      });
    });

    store.get('watchlistResult').then((result) => {
      this.setState({
        watchlistResult: result,
      });
    });
  },

  render: function() {
    if(!this.state.loaded){
      return(
        <View style={styles.container}>
          <Text style={styles.loadingText}>
            Loading...
          </Text>
        </View>
      );
    }
    return (
      this.renderListView()
    );
  },

  renderListView: function() {
    return(
      <View style={styles.container}>
        <View style={styles.stocksBlock}>
          <RefresherListView
            dataSource={this.state.dataSource}
            onRefresh={() => StockActions.updateStocks()}
            renderRow={this.renderStockCell}
            style={styles.stocksListView}/>
        </View>
        <View style={styles.middleBlock}>
          {(() => {
            switch (this.state.middleBlockShowing) {
              case 'DETAILS':              return this.renderDetails();
              case 'CHART':                return this.renderChart();
              case 'NEWS':                return this.renderNews();
              default:                     return this.renderDetails();
            }
          })()}
        </View>
{'fraction_non_alphanumeric': 0.14784240150093808, 'fraction_numerical': 0.00225140712945591, 'mean_word_length': 2.3152985074626864, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 32, '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': '4117959', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1535, 'n_words': 275}