<commit_before>import { setInitialState } from "./actions";
/* global Db object :( */
let db;

function insertTask(Task) {
  var toDoListObjectStore = db
    .transaction(["toDoList"], "readwrite")
    .objectStore("toDoList");
  return toDoListObjectStore.add(Task);
}

function deleteTask(taskId) {
  let transaction = db.transaction(["toDoList"], "readwrite");
  let toDoListObjectStore = transaction.objectStore("toDoList");
  let dbItem = toDoListObjectStore.delete(taskId);
  return dbItem;
}

function onsuccess(store) {
  return function(event) {
    db = event.target.result;
    // Store values in the newly created objectStore.
    getInitialState(store);
  };
}
function onerror(event) {
  console.log(event);
}
function reorderTask(sourceId, targetId){
  //TODO: updare task from sourceId to targetId in the Db

}
function getInitialState(store) {
  let reduxState = { tasks: [] };
  let transaction = db.transaction(["toDoList"]);
  let objectStore = transaction.objectStore("toDoList");
  objectStore.openCursor().onsuccess = event => {
    let cursor = event.target.result;
    if (cursor) {
      reduxState.tasks.push(cursor.value);
      cursor.continue();
    } else {
      store.dispatch(setInitialState(reduxState));
    }
  };
}

function onupgradeneeded(event) {
  let objectStoreNames = ["toDoList"];
  var db = event.target.result;
  try {
    objectStoreNames.map(name => db.deleteObjectStore(name));
  } catch (e) {
    console.log(e);
  }
  var objectStore = db.createObjectStore("toDoList", { keyPath: "taskId" });<commit_msg>TODO added<commit_after>import { setInitialState } from "./actions";
/* global Db object :( */
let db;

function insertTask(Task) {
  var toDoListObjectStore = db
    .transaction(["toDoList"], "readwrite")
    .objectStore("toDoList");
  return toDoListObjectStore.add(Task);
}

function deleteTask(taskId) {
  let transaction = db.transaction(["toDoList"], "readwrite");
  let toDoListObjectStore = transaction.objectStore("toDoList");
  let dbItem = toDoListObjectStore.delete(taskId);
  return dbItem;
}

function onsuccess(store) {
  return function(event) {
    db = event.target.result;
    // Store values in the newly created objectStore.
    getInitialState(store);
  };
}
function onerror(event) {
  console.log(event);
}
function reorderTask(sourceId, targetId){
  //TODO: updare task from sourceId to targetId in the Db
}
function getInitialState(store) {
  let reduxState = { tasks: [] };
  let transaction = db.transaction(["toDoList"]);
  let objectStore = transaction.objectStore("toDoList");
  objectStore.openCursor().onsuccess = event => {
    let cursor = event.target.result;
    if (cursor) {
      reduxState.tasks.push(cursor.value);
      cursor.continue();
    } else {
      store.dispatch(setInitialState(reduxState));
    }
  };
}

function onupgradeneeded(event) {
  let objectStoreNames = ["toDoList"];
  var db = event.target.result;
  try {
    objectStoreNames.map(name => db.deleteObjectStore(name));
  } catch (e) {
    console.log(e);
  }
  var objectStore = db.createObjectStore("toDoList", { keyPath: "taskId" });
{'fraction_non_alphanumeric': 0.13762057877813505, 'fraction_numerical': 0.0, 'mean_word_length': 4.228571428571429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6128135', 'n_tokens_mistral': 998, 'n_tokens_neox': 987, 'n_words': 209}