<commit_before>import * as actions from './actions';
import Todo from './todo';
import {Range} from 'immutable';
import {getRandomString} from '../../lib/getrandomstring';
import {register} from '../dispatcher';
import {todosCursor} from '../state';

export const dispatchToken = register(({action, data}) => {

  switch (action) {
    case actions.addHundredTodos:
      todosCursor(todos => {
        return todos.update('list', list => {
          return list.withMutations(list => {
            Range(0, 100).forEach(i => {
              const id = getRandomString();
              list.push(new Todo({
                id: id,
                title: `Item #${id}`
              }));
            });
          });
        });
      });
      break;

    case actions.addTodo:
      todosCursor(todos => {
        return todos
          .update('list', (list) => {
            // Always denote what data represents. Favour readability over wtf.
            // Try to resist being smart ass. Fuck pride.
            // https://www.youtube.com/watch?v=ruhFmBrl4GM
            const todo = data;
            const newTodo = todo.merge({
              id: getRandomString()
            });
            return list.push(newTodo);
          })
          .set('newTodo', new Todo);
      });
      break;

    case actions.clearAll:
      todosCursor(todos => {
        return todos
          .update('list', list => list.clear())
          .set('newTodo', new Todo);
      });
      break;

    case actions.deleteTodo:
      todosCursor(todos => {
        const todo = data;
        return todos.update('list', list => list.delete(list.indexOf(todo)));
      });
      break;

    case actions.onEditableState:
      todosCursor(todos => {
        const {id, name, state} = data;
        return todos.setIn(['editables', id, name], state);
      });
      break;

    case actions.onNewTodoFieldChange:
      todosCursor(todos => {
        const {name, value} = data;
        return todos.setIn(['newTodo', name], value);
      });
      break;

    case actions.saveTitle:
      todosCursor(todos => {
        // najit todo podle id, a zmenit mu title
        const {id, title} = data;
        return todos.update('list', list => {
          const idx = list.findIndex(todo => todo.id === id);
          return list.setIn([idx, 'title'], title);
        });
      });
      break;

  }

});<commit_msg>Remove comment.<commit_after>import * as actions from './actions';
import Todo from './todo';
import {Range} from 'immutable';
import {getRandomString} from '../../lib/getrandomstring';
import {register} from '../dispatcher';
import {todosCursor} from '../state';

export const dispatchToken = register(({action, data}) => {

  switch (action) {
    case actions.addHundredTodos:
      todosCursor(todos => {
        return todos.update('list', list => {
          return list.withMutations(list => {
            Range(0, 100).forEach(i => {
              const id = getRandomString();
              list.push(new Todo({
                id: id,
                title: `Item #${id}`
              }));
            });
          });
        });
      });
      break;

    case actions.addTodo:
      todosCursor(todos => {
        return todos
          .update('list', (list) => {
            // Always denote what data represents. Favour readability over wtf.
            // Try to resist being smart ass. Fuck pride.
            // https://www.youtube.com/watch?v=ruhFmBrl4GM
            const todo = data;
            const newTodo = todo.merge({
              id: getRandomString()
            });
            return list.push(newTodo);
          })
          .set('newTodo', new Todo);
      });
      break;

    case actions.clearAll:
      todosCursor(todos => {
        return todos
          .update('list', list => list.clear())
          .set('newTodo', new Todo);
      });
      break;

    case actions.deleteTodo:
      todosCursor(todos => {
        const todo = data;
        return todos.update('list', list => list.delete(list.indexOf(todo)));
      });
      break;

    case actions.onEditableState:
      todosCursor(todos => {
        const {id, name, state} = data;
        return todos.setIn(['editables', id, name], state);
      });
      break;

    case actions.onNewTodoFieldChange:
      todosCursor(todos => {
        const {name, value} = data;
        return todos.setIn(['newTodo', name], value);
      });
      break;

    case actions.saveTitle:
      todosCursor(todos => {
        const {id, title} = data;
        return todos.update('list', list => {
          const idx = list.findIndex(todo => todo.id === id);
          return list.setIn([idx, 'title'], title);
        });
      });
      break;

  }

});
{'fraction_non_alphanumeric': 0.1447811447811448, 'fraction_numerical': 0.0021043771043771043, 'mean_word_length': 1.8024764150943395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4119270', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1399, 'n_words': 331}