<commit_before>import {observable, autorun} from 'mobservable';
import * as Utils from '../utils';

export class TodoModel {
	constructor(key) {
		observable(this, {
			key,
			todos: [],
			activeTodoCount: () =>
				this.todos.reduce(
					(sum, todo) => sum + (todo.completed ? 0 : 1),
					0
				)
			,
			completedCount: () => this.todos.length - this.activeTodoCount
		});

		this.readFromLocalStorage();
		this.subscribeLocalStorageToModel();
	}

	readFromLocalStorage(model) {
		this.todos = Utils.getDataFromLocalStore(this.key).map(
			data => Todo.fromJson(this, data)
		);
	}

	subscribeLocalStorageToModel(model) {
		autorun(() =>
			Utils.storeDataToLocalStore(this.key, this.todos.map(todo => todo.toJson()))
		);
	}

	addTodo (title) {
		this.todos.push(new Todo(this, Utils.uuid(), title, false));
	}

	toggleAll (checked) {
		this.todos.forEach(
			todo => todo.completed = checked
		);
	}

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

export class Todo {
	constructor(store, id, title, completed) {
		this.store = store;
		observable(this, { id, title, completed });
	}

	toggle() {
		this.completed = !this.completed;
	}

	destroy() {
		this.store.todos.remove(this);
	}

	setTitle(title) {
		this.title = title;
	}

	toJson() {
		return {
			id: this.id,
			title: this.title,
			completed: this.completed
		};
	}
<commit_msg>Fixed migration error introduced after upgrading to 1.0<commit_after>import {extendObservable, autorun} from 'mobservable';
import * as Utils from '../utils';

export class TodoModel {
	constructor(key) {
		extendObservable(this, {
			key,
			todos: [],
			activeTodoCount: () =>
				this.todos.reduce(
					(sum, todo) => sum + (todo.completed ? 0 : 1),
					0
				)
			,
			completedCount: () => this.todos.length - this.activeTodoCount
		});

		this.readFromLocalStorage();
		this.subscribeLocalStorageToModel();
	}

	readFromLocalStorage(model) {
		this.todos = Utils.getDataFromLocalStore(this.key).map(
			data => Todo.fromJson(this, data)
		);
	}

	subscribeLocalStorageToModel(model) {
		autorun(() =>
			Utils.storeDataToLocalStore(this.key, this.todos.map(todo => todo.toJson()))
		);
	}

	addTodo (title) {
		this.todos.push(new Todo(this, Utils.uuid(), title, false));
	}

	toggleAll (checked) {
		this.todos.forEach(
			todo => todo.completed = checked
		);
	}

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

export class Todo {
	constructor(store, id, title, completed) {
		this.store = store;
		extendObservable(this, { id, title, completed });
	}

	toggle() {
		this.completed = !this.completed;
	}

	destroy() {
		this.store.todos.remove(this);
	}

	setTitle(title) {
		this.title = title;
	}

	toJson() {
		return {
			id: this.id,
			title: this.title,
			completed: this.completed
		};
	}

{'fraction_non_alphanumeric': 0.156140350877193, 'fraction_numerical': 0.002807017543859649, 'mean_word_length': 3.4064914992272026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5967953', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1058, 'n_words': 185}