<commit_before>import {Injectable} from "@angular/core";
import {Todo} from "../models/todo.model";

const STORAGE_KEY = 'angular2-todo';

@Injectable()
export class TodoService {

  todos:Todo[];

  constructor() {
    const persistedTodos = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
    this.todos = persistedTodos.map(todo => {
      return new Todo(
        todo.id,
        todo.title,
        todo.isCompleted
      );
    });
  }

  add(title:string) {
    let newTodo = new Todo(
      this.todos.length + 1,
      title,
      false
    );
    this.todos.push(newTodo);
    this.save();
  }

  remove(todo:Todo) {
    const index = this.todos.indexOf(todo);
    this.todos.splice(index, 1);
    this.save();
  }

  toggleComplate(todo:Todo) {
    this.todos.filter(t => t.id === todo.id)
      .map(t => t.isCompleted = !t.isCompleted);
    this.save();
  }

  getComplatedCount():number {
    // TODO newTodoのInputがchangeするたびに呼び出されている
    return this.todos.filter(todo => todo.isCompleted).length;
  }

  private save() {
    console.log('saving : ', this.todos);
    localStorage.setItem(STORAGE_KEY, JSON.stringify(this.todos));
  }

}
<commit_msg>:+1: Change generated id to using random number<commit_after>import {Injectable} from "@angular/core";
import {Todo} from "../models/todo.model";

const STORAGE_KEY = 'angular2-todo';

@Injectable()
export class TodoService {

  todos:Todo[];

  constructor() {
    const persistedTodos = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
    this.todos = persistedTodos.map(todo => {
      return new Todo(
        todo.id,
        todo.title,
        todo.isCompleted
      );
    });
  }

  add(title:string) {
    let newTodo = new Todo(
      Math.floor(Math.random() * 100000), // ランダムにIDを発番する
      title,
      false
    );
    this.todos.push(newTodo);
    this.save();
  }

  remove(todo:Todo) {
    const index = this.todos.indexOf(todo);
    this.todos.splice(index, 1);
    this.save();
  }

  toggleComplate(todo:Todo) {
    this.todos.filter(t => t.id === todo.id)
      .map(t => t.isCompleted = !t.isCompleted);
    this.save();
  }

  getComplatedCount():number {
    // TODO newTodoのInputがchangeするたびに呼び出されている
    return this.todos.filter(todo => todo.isCompleted).length;
  }

  private save() {
    console.log('saving : ', this.todos);
    localStorage.setItem(STORAGE_KEY, JSON.stringify(this.todos));
  }

}

{'fraction_non_alphanumeric': 0.15483603154836031, 'fraction_numerical': 0.0049813200498132005, 'mean_word_length': 2.8870967741935485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4093696', 'n_tokens_mistral': 937, 'n_tokens_neox': 915, 'n_words': 140}