<commit_before>/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

var React = require('react-native');

var {
  AppRegistry,
  StyleSheet,
  NavigatorIOS,
  AlertIOS,
  ListView,
  TouchableHighlight,
  Text,
  TextInput,
  View,
} = React;

var TodoItemSchema = {
  name: 'Todo',
  properties: [
    {name: 'text', type: RealmType.String},
  ]
};
var TodoListSchmea = {
    name: 'TodoList',
    properties: [
      {name: 'name', type: RealmType.String},
      {name: 'items', type: RealmType.Array, objectType: 'Todo'}
    ]
};

console.log(Realm.defaultPath);
var realm = new Realm({schema: [TodoItemSchema, TodoListSchmea]});

class Edit extends React.Component {
    componentWillMount() {
        this.setState({text: this.props.text});
    }

    save() {
        var list = this.props.list;
        var id = this.props.todoId;
        var text = this.state.text;
        realm.write(function () {
            if (id == list.items.length) {
                list.items.push({text: text});
            }
            else {
                var todoItem = list.items[id];
                todoItem.text = text;
            }
        });
        // should not be needed once we have notifications
        this.props.parent.updateDataSource();
        this.props.navigator.pop();
    }

    render() {
        return (
            <View style={{flex:1, justifyContent: 'flex-start'}}>
                <TextInput multiline={true} style={styles.textInput}
                    placeholder='Enter Todo' autoFocus={true}
                    onChangeText={(text) => this.setState({text})} value={this.state.text}/>
                <TouchableHighlight
                    style={styles.button}
                    onPress={this.save.bind(this)}
                    underlayColor='#99d9f4'>
                    <Text style={styles.buttonText}>Save</Text>
                </TouchableHighlight>
            </View>
        )
    }
};

class TodoList extends React.Component {
    componentWillMount() {
        this.lists = realm.objects('TodoList');
        if (this.lists.length < 1) {
          realm.write(function() {
            this.list = realm.create('TodoList', ['List', []]);
          });
        }
        else {
            this.list = this.lists[0];
        }
        this.menu = this.menu.bind(this);
        this.delete = this.delete.bind(this);
        var dataSource = new ListView.DataSource({
            rowHasChanged: (row1, row2) => row1 !== row2
        });

        this.updateDataSource(dataSource);
    }

    updateDataSource(oldDataSource) {
        if (!oldDataSource) {
            oldDataSource = this.state.dataSource;
        }
        this.setState({dataSource: oldDataSource.cloneWithRows(this.list.items)});
    }

    menu(todo, todoID) {
        AlertIOS.alert(
            todo.text,
            todoID,
            [
                {text: 'Complete', onPress: () => this.delete(todoID)},
                {text: 'Edit', onPress: () => this.edit(todoID, todo.text)},
                {text: 'Cancel'}<commit_msg>fix for example first run<commit_after>/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

var React = require('react-native');

var {
  AppRegistry,
  StyleSheet,
  NavigatorIOS,
  AlertIOS,
  ListView,
  TouchableHighlight,
  Text,
  TextInput,
  View,
} = React;

var TodoItemSchema = {
  name: 'Todo',
  properties: [
    {name: 'text', type: RealmType.String},
  ]
};
var TodoListSchmea = {
    name: 'TodoList',
    properties: [
      {name: 'name', type: RealmType.String},
      {name: 'items', type: RealmType.Array, objectType: 'Todo'}
    ]
};

console.log(Realm.defaultPath);
var realm = new Realm({schema: [TodoItemSchema, TodoListSchmea]});

class Edit extends React.Component {
    componentWillMount() {
        this.setState({text: this.props.text});
    }

    save() {
        realm.write(function () {
            if (id == this.props.list.items.length) {
                this.props.list.items.push({text: this.state.text});
            }
            else {
                var todoItem = this.props.list.items[this.props.todoId];
                todoItem.text = this.state.text;
            }
        }.bind(this));
        // should not be needed once we have notifications
        this.props.parent.updateDataSource();
        this.props.navigator.pop();
    }

    render() {
        return (
            <View style={{flex:1, justifyContent: 'flex-start'}}>
                <TextInput multiline={true} style={styles.textInput}
                    placeholder='Enter Todo' autoFocus={true}
                    onChangeText={(text) => this.setState({text})} value={this.state.text}/>
                <TouchableHighlight
                    style={styles.button}
                    onPress={this.save.bind(this)}
                    underlayColor='#99d9f4'>
                    <Text style={styles.buttonText}>Save</Text>
                </TouchableHighlight>
            </View>
        )
    }
};

class TodoList extends React.Component {
    componentWillMount() {
        this.lists = realm.objects('TodoList');
        if (this.lists.length < 1) {
          realm.write(function() {
            realm.create('TodoList', ['List', []]);
          });
        }
        this.list = this.lists[0];
        this.menu = this.menu.bind(this);
        this.delete = this.delete.bind(this);
        var dataSource = new ListView.DataSource({
            rowHasChanged: (row1, row2) => row1 !== row2
        });

        this.updateDataSource(dataSource);
    }

    updateDataSource(oldDataSource) {
        if (!oldDataSource) {
            oldDataSource = this.state.dataSource;
        }
        this.setState({dataSource: oldDataSource.cloneWithRows(this.list.items)});
    }

    menu(todo, todoID) {
        AlertIOS.alert(
            todo.text,
            todoID,
            [
                {text: 'Complete', onPress: () => this.delete(todoID)},
                {text: 'Edit', onPress: () => this.edit(todoID, todo.text)},
                {text: 'Cancel'}
{'fraction_non_alphanumeric': 0.1407782864617397, 'fraction_numerical': 0.0035971223021582736, 'mean_word_length': 1.9184160305343512, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '5880554', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1811, 'n_words': 331}