<commit_before>/*jshint quotmark:false */
/*jshint white:false */
/*jshint trailing:false */
/*jshint newcap:false */
var app = app || {};

(function () {
        'use strict';

        const Utils = app.Utils;

        //Setup RethinkDB
        const Fusion = require("Fusion");
        const fusion = new Fusion(location.host, {
                secure: location.protocol == 'https:'
        });

        // Generic "model" object. You can use whatever
        // framework you want. For this application it
        // may not even be worth separating this logic
        // out, but we do this to demonstrate one way to
        // separate out parts of your application.
        app.TodoModel = function (table_key) {
                this.todos = [];
                this.onChanges = [];
                this.todosDB = fusion(table_key);
        };

        app.TodoModel.prototype.subscribe = function (onChange) {
                this.onChanges.push(onChange);
        };

        app.TodoModel.prototype.inform = function () {
                this.onChanges.forEach(function (cb) { cb(); });
        };

        app.TodoModel.prototype.addTodo = function (title) {
                const newTodo = {
                        id: Utils.uuid(),
                        title: title,
                        completed: false
                };

                this.todosDB.store(newTodo);
        };

        app.TodoModel.prototype.toggleAll = function (checked) {
                console.log(checked);
                this.todosDB.replace(this.todos.map(function (todo) {
                        return Utils.extend({}, todo, {completed: checked});
                }));
        };

        app.TodoModel.prototype.toggle = function (todoToToggle) {
                console.log(todoToToggle);
                this.todosDB.replace(
                        Utils.extend({}, todoToToggle, {completed: !todoToToggle.completed})
                );
        };

        app.TodoModel.prototype.destroy = function (todo) {
                this.todosDB.remove(todo);
        };

        app.TodoModel.prototype.save = function (todoToSave, text) {
                this.todosDB.store(Utils.extend({}, todoToSave, {title: text}));
        };

        app.TodoModel.prototype.clearCompleted = function () {
                const oldTodos = this.todos.slice();

                this.todos = this.todos.filter((todo) => {
                        return !todo.completed;
                });

                // Send batched deletion of completed todos
                this.todosDB.removeAll(oldTodos.filter((todo) => {
                        return !this.todos.includes(todo);
                }));
        };

        app.TodoModel.prototype.subscribeChangefeeds = function(){
                this.todosDB.subscribe({
                        onAdded: (added) => {
                                this.todos = this.todos.concat(added);
                                this.inform();
                        },
                  onChanged: (changed) => {
                                this.todos = this.todos.map((todo) => {
                                        return todo.id !== changed.new_val.id ? todo : Utils.extend({}, todo, changed.new_val);
                                });
                                this.inform();
                        },
                        onRemoved: (removed) => {
                                this.todos = this.todos.filter((todo) => {
                                        return todo.id !== removed.id;
                                });
                                this.inform();
                        }
                });
        };
})();<commit_msg>Fixed react todo example<commit_after>/*jshint quotmark:false */
/*jshint white:false */
/*jshint trailing:false */
/*jshint newcap:false */
var app = app || {};

(function () {
        'use strict';

        const Utils = app.Utils;

        //Setup RethinkDB
        const Fusion = require("Fusion");
        const fusion = Fusion(location.host, {
                secure: location.protocol == 'https:'
        });

        // Generic "model" object. You can use whatever
        // framework you want. For this application it
        // may not even be worth separating this logic
        // out, but we do this to demonstrate one way to
        // separate out parts of your application.
        app.TodoModel = function (table_key) {
                this.todos = [];
                this.onChanges = [];
                this.todosDB = fusion(table_key);
        };

        app.TodoModel.prototype.subscribe = function (onChange) {
                this.onChanges.push(onChange);
        };

        app.TodoModel.prototype.inform = function () {
                this.onChanges.forEach(function (cb) { cb(); });
        };

        app.TodoModel.prototype.addTodo = function (title) {
                const newTodo = {
                        id: Utils.uuid(),
                        title: title,
                        completed: false
                };

          this.todosDB.store(newTodo).subscribe();
        };

        app.TodoModel.prototype.toggleAll = function (checked) {
                console.log(checked);
                this.todosDB.replace(this.todos.map(function (todo) {
                        return Utils.extend({}, todo, {completed: checked});
                })).subscribe();
        };

        app.TodoModel.prototype.toggle = function (todoToToggle) {
                console.log(todoToToggle);
                this.todosDB.replace(
                        Utils.extend({}, todoToToggle, {completed: !todoToToggle.completed})
                ).subscribe();
        };

        app.TodoModel.prototype.destroy = function (todo) {
            this.todosDB.remove(todo).subscribe();
        };

        app.TodoModel.prototype.save = function (todoToSave, text) {
          this.todosDB.store(Utils.extend({}, todoToSave, {title: text})).subscribe();
        };

        app.TodoModel.prototype.clearCompleted = function () {
                const oldTodos = this.todos.slice();

                this.todos = this.todos.filter((todo) => {
                        return !todo.completed;
                });

                // Send batched deletion of completed todos
                this.todosDB.removeAll(oldTodos.filter((todo) => {
                        return !this.todos.includes(todo);
                })).subscribe();
        };

        app.TodoModel.prototype.subscribeChangefeeds = function(){
                this.todosDB.watch().subscribe(todos => {
                  this.todos = todos;
                  this.inform()
                })
        };
})();
{'fraction_non_alphanumeric': 0.11946308724832215, 'fraction_numerical': 0.0, 'mean_word_length': 1.3317107093184979, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2874802', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1714, 'n_words': 329}