Example #1
0
    updateActivityInMention(kind: TimelineActivityKind, status: Tweet, from: TwitterUser): [List<Item>, number] {
        const status_id = status.id;
        const index = this.mention.findIndex(item => {
            if (item instanceof TimelineActivity) {
                return item.kind === kind && item.status.id === status_id;
            } else {
                return false;
            }
        });

        const next_focus_index =
            this.kind === 'mention' && (index === -1 || index < this.focus_index) ?
                this.nextFocusIndex(this.mention.size + 1) : this.focus_index;

        if (index === -1) {
            return [this.mention.unshift(new TimelineActivity(kind, status, [from])), next_focus_index];
        } else {
            const will_updated = this.mention.get(index);
            if (will_updated instanceof TimelineActivity) {
                const updated = will_updated.update(status, from);
                return [this.mention.delete(index).unshift(updated), next_focus_index];
            } else {
                log.error('Invalid activity for update:', will_updated);
                return [this.mention, next_focus_index];
            }
        }
    }
Example #2
0
export default function(state: List<TaskModel>, action: ITaskAction) {

  function indexOf(id: string): number {
    return state.findIndex((i: TaskModel) => i.id === id);
  }

  switch (action.type) {
    case LOAD_TASKS:
      state = action.taskList;
      return List<TaskModel>(state);
    case UPDATE_TASK:
      let index = state.findIndex((task) => task.id === action.task.id);
      return state.set(
        index,
        new TaskModel({
          id: action.task.id,
          title: action.task.title,
          details: action.task.details,
          dueDate: action.task.dueDate,
          completed: action.task.completed,
          completedDate: action.task.completedDate
        })
      );
    case COMPLETE_TASK:
      let completedTaskIndex = state.findIndex((task) => task.id === action.id);
      return state.delete(completedTaskIndex);
    case ADD_TASK:
      return state.push(action.task);
    default:
      return List<TaskModel>(state);
  }
}
Example #3
0
function rowRemoved(rows: List<any>, { row }) {
  let index = indexForRow(rows, row.id);

  if (index > -1) {
    return rows.delete(index)
  } else {
    return rows;
  }
}
Example #4
0
function rowMoved(rows: List<any>, { row, prevRowId }) {
  const currIndex = indexForRow(rows, row.id);

  if (currIndex > -1) {
    const row = rows.get(currIndex);
    rows = rows.delete(currIndex);

    const newIndex = nextRowIndex(rows, prevRowId);
    rows = rows.splice(newIndex, 0, row).toList();

    return rows;
  }

  return rows;
}
function todos(state: List<Todo>, action) {
    if (!state) {
        return List([]);
    }
    switch(action.type) {
        case LOAD_TODOS:
            return List(action.todos);
        case ADD_TODO:
            return state.push(action.newTodo);
        case TOGGLE_TODO:
            return toggleTodo(state, action);
        case DELETE_TODO:
            let index = state.findIndex((todo) => todo.id === action.todo.id);
            return state.delete(index);
        default:
            return state;
    }
}
Example #6
0
function todosReducer(state: List<Todo> = List([]), action) {
  switch (action.type) {
    case LOAD_TODOS:
      return List(action.todos);
    case ADD_TODO:
      return state.push(action.newTodo);
    case TOGGLE_TODO:
      return toggleTodo(state, action);
    case TOGGLE_ALL_TODO:
      return toggleAllTodo(state, action.completed);
    case DELETE_TODO:
      let index = state.findIndex((todo) => todo.id === action.todo.id);
      return state.delete(index);
    case SET_CURRENT_FILTER:
      return state.map(todo => todo);
    case '@@redux-pouchdb-plus/SET_REDUCER':
      return state.map(todo => new Todo(todo.toJS()));
    default:
      return state;
  }
}
export function calculateTodos(state: List<Todo>, action) {
    if (!state) {
        return List([]);
    }

    if (action instanceof  LoadTodosAction) {
        return List(action.todos);
    }
    else if (action instanceof AddTodoAction) {
        return state.push(action.newTodo);
    }
    else if (action instanceof ToggleTodoAction) {
        return toggleTodo(state, action);
    }
    else if (action instanceof DeleteTodoAction) {
        let index = state.findIndex((todo) => todo.id === action.todo.id);
        return state.delete(index);
    }
    else {
        return state;
    }
}
Example #8
0
    putInHome(status: Tweet): [List<Item>, number] {
        if (!status.isRetweet()) {
            return [this.home.unshift(status), this.nextFocusIndex(this.home.size + 1)];
        }

        const status_id = status.retweeted_status.id;
        const index = this.home.findIndex(item => {
            if (item instanceof Tweet) {
                return item.isRetweet() && item.retweeted_status.id === status_id;
            } else {
                return false;
            }
        });

        const next_focus_index =
            this.kind === 'home' && (index === -1 || index < this.focus_index) ?
                this.nextFocusIndex(this.home.size + 1) : this.focus_index;

        if (index === -1) {
            return [this.home.unshift(status), next_focus_index];
        }

        return [this.home.delete(index).unshift(status), next_focus_index];
    }