Example #1
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 #2
0
 (cellOrder: List<CellId>) => {
   const oldIndex = cellOrder.findIndex(
     (id: string) => id === action.payload.id
   );
   const newIndex =
     cellOrder.findIndex(
       (id: string) => id === action.payload.destinationId
     ) + (action.payload.above ? 0 : 1);
   if (oldIndex === newIndex) {
     return cellOrder;
   }
   return cellOrder
     .splice(oldIndex, 1)
     .splice(newIndex - (oldIndex < newIndex ? 1 : 0), 0, action.payload.id);
 }
Example #3
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 #4
0
function updateStatusIn(items: List<Item>, status: Tweet) {
    'use strict';
    const status_id = status.id;
    const index = items.findIndex(item => {
        if (item instanceof Tweet) {
            return item.getMainStatus().id === status_id;
        } else {
            return false;
        }
    });

    if (index === -1) {
        return items;
    }

    return items.update(index, item => {
        if (item instanceof Tweet) {
            if (item.isRetweet()) {
                const cloned = item.clone();
                cloned.json.retweeted_status = status.json;
                return cloned;
            } else {
                return status;
            }
        } else {
            log.error('Never reaches here');
            return item;
        }
    });
}
Example #5
0
function focusPreviousCellEditor(
  state: NotebookModel,
  action: actionTypes.FocusPreviousCellEditor
): RecordOf<DocumentRecordProps> {
  const cellOrder: List<CellId> = state.getIn(["notebook", "cellOrder"]);
  const curIndex = cellOrder.findIndex(
    (id: CellId) => id === action.payload.id
  );
  const nextIndex = Math.max(0, curIndex - 1);

  return state.set("editorFocused", cellOrder.get(nextIndex));
}
 onRated(event) {
   let key = this.talks.findIndex(e => e.id === event);
   this.talks = this.talks.update(key, talk => {
       return {
         id: talk.id,
         title: talk.title,
         speaker: talk.speaker,
         avgRating: 10,
         watched: talk.watched,
         rated: true
       };
   });
 }
 _.forEach(action.payload, (v, k)=> {
     var type = k.split('_')[0]
     var key = k.split('_')[1]
     var value = v;
     var accountModels:List<AccountModel> = state.getIn(['accounts']);
     var index = accountModels.findIndex((i:AccountModel) => i.getType().toLowerCase() === type.toLowerCase());
     if (index == -1)
         return state;
     accountModels = accountModels.update(index, (accountModel:AccountModel) => {
         return accountModel.setKey<AccountModel>(AccountModel, key, value);
     });
     state = state.setIn(['accounts'], accountModels);
 });
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 #9
0
function focusNextCellEditor(
  state: NotebookModel,
  action: actionTypes.FocusNextCellEditor
): RecordOf<DocumentRecordProps> {
  const cellOrder: List<CellId> = state.getIn(["notebook", "cellOrder"]);

  const id = action.payload.id ? action.payload.id : state.get("editorFocused");

  // If for some reason we neither have an ID here or a focused editor, we just
  // keep the state consistent
  if (!id) {
    return state;
  }

  const curIndex = cellOrder.findIndex((foundId: CellId) => id === foundId);
  const nextIndex = curIndex + 1;

  return state.set("editorFocused", cellOrder.get(nextIndex));
}
Example #10
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;
  }
}