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);
  }
}
function decrement(state: List<number>, action: DecrementAction): List<number> {
    if(action.index >= state.size) {
      throw "index out of bounds"
    }
    if(action.index < 0) {
      throw "index out of bounds"
    }
    return state.set(action.index, state.get(action.index) - 1)
}
Example #3
0
function rowChanged(rows: List<any>, { row }) {
  const index = indexForRow(rows, row.id);

  if (index > -1) {
    return rows.set(index, row);
  } else {
    return rows;
  }
}
Example #4
0
 .flatMap(previousAuthorName => {
     if (previousAuthorName === currentCommit.authorName) {
         const currentCommitsByAuthor = previousGroup[1];
         const index = accumulator.indexOf(previousGroup);
         return new Some(accumulator.set(index, [ previousAuthorName, currentCommitsByAuthor.push(currentCommit) ]))
     } else {
         return None;
     }
 })
Example #5
0
function reducer(state: IReduxState = initial, { type, payload }: IAction): IReduxState {
  const imState: Map<string, any> = fromJS(state);

  switch (type) {
  case 'CREATE_POLL:CHANGE_FIELD_VALUE': {
    interface IData { fieldName: string; fieldValue: string; }
    const data: IData = payload as IData;
    return imState
      .setIn(['newPoll', data.fieldName], data.fieldValue)
      .toJS();
  }
  case 'CREATE_POLL:ADD_ANSWER': {
    const index: number = payload as number;
    const questions: List<Map<string, any>> = imState.getIn(['newPoll', 'questions']);
    const question: Map<string, any> = questions.get(index);

    return imState
      .setIn(
        ['newPoll', 'questions'],
        questions.set(index, question.set('answers', question.get('answers').push(initialAnswer))),
      ).toJS();
  }
  case 'CREATE_POLL:ADD_QUESTION': {
    return imState.setIn(
      ['newPoll', 'questions'],
      (imState.getIn(['newPoll', 'questions']) as List<IEditableQuestion>).push(initialQuestion),
    ).toJS();
  }
  case 'CREATE_POLL:CHANGE_ANSWER_TEXT': {
    interface IData { questionIndex: number; answerIndex: number; value: string; }
    const data: IData = payload as IData;
    const questions = imState.getIn(['newPoll', 'questions']);
    const question = questions.get(data.questionIndex);
    const answers = question.get('answers');
    const answer = answers.get(data.answerIndex);

    return imState.withMutations((mutable: Map<string, any>) => mutable.setIn(
      ['newPoll', 'questions'],
      questions.set(
        data.questionIndex,
        question.set('answers', answers.set(data.answerIndex, answer.set('text', data.value))),
      ),
    )).toJS();
  }
  case 'CREATE_POLL:CHANGE_QUESTION_FIELD': {
    interface IData { questionIndex: number; value: string; fieldName: string; }
    const data = payload as IData;
    const questions = imState.getIn(['newPoll', 'questions']);
    return imState.setIn(
      ['newPoll', 'questions'],
      questions.set(
        data.questionIndex,
        questions.get(data.questionIndex).set(data.fieldName, data.value),
      ),
    ).toJS();
  }
  case 'CREATE_POLL:SEND_NEW_POLL_SUCCESS':
    return imState.set('newPoll', initial.newPoll).toJS();
  case 'CREATE_POLL:LOAD_POLL_SUCCESS':
    return imState.set('newPoll', payload).toJS();
  case 'CREATE_POLL:CLEAR_DATA':
    return imState.set('newPoll', initial.newPoll).toJS();
  default:
    return state;
  }
}
Example #6
0
export function embedAnnotations(timelineDuration: number, annotationStacks: List<List<Record<Annotation>>>, annotationStackIndex: number,
  addAnnotations: List<Record<Annotation>>, removeAnnotations: List<Record<Annotation>>): List<List<Record<Annotation>>> {
  if(annotationStackIndex < 0 || annotationStackIndex >= annotationStacks.size) {
    return annotationStacks
  }
  const selStack = annotationStacks.get(annotationStackIndex)!

  const withRemovals = selStack.filter(a => {
    return removeAnnotations.find(annotation => {
      return annotation.get('id', null) === a.get('id', null)
    }) === undefined
  })

  let updatedStacks = annotationStacks.set(annotationStackIndex, withRemovals)
  const vCollisions = findVerticalCollisions(timelineDuration, updatedStacks, annotationStackIndex+1, removeAnnotations)

  updatedStacks = updatedStacks.withMutations(mStacks => {
    mStacks.forEach((stack, stackIndex) => {
      const filtered = stack.filter((annotation, annotationIndex) => {
        return vCollisions.find(vColl => {
          return vColl.index === annotationIndex && vColl.annotationStackIndex === stackIndex
        }) === undefined
      })
      mStacks.set(stackIndex, filtered)
    })
  })

  const withInsertions = withRemovals.concat(addAnnotations).sort(recordSort)

  const insertionIndices = addAnnotations.map(mapIndicesFunc(withInsertions))

  const hCollisions: {annotation: Record<Annotation>, index: number}[] = findHorizontalCollisions(timelineDuration, withInsertions, insertionIndices)

  const collisions = vCollisions.map(({annotation, index}) => ({annotation, index})).concat(hCollisions)

  if(collisions.length > 0) {
    const withoutHCollisions = withInsertions.filter((a, i) => {
      return hCollisions.find(({index}) => {
        return i === index
      }) === undefined
    })
    const stackInsertions = updatedStacks.set(annotationStackIndex, withoutHCollisions)
    const stacksFitted = fitOptimized(timelineDuration, stackInsertions, List(collisions.map(({annotation}) => annotation)))
    const maxSize = Math.max(stackInsertions.size, stacksFitted.size)

    const tmp: List<List<Record<Annotation>>> = List()
    const ret = tmp.withMutations(mRet => {
      for(let i = 0; i < maxSize; i++) {
        if(i < stackInsertions.size && i < stacksFitted.size) {
          mRet.push(stackInsertions.get(i)!.concat(stacksFitted.get(i)!).sort(recordSort))
        } else if(i < stackInsertions.size) {
          mRet.push(stackInsertions.get(i)!)
        } else {
          mRet.push(stacksFitted.get(i)!)
        }
      }
    })
    return ret.filter(stack => stack.size > 0)
  } else {
    return annotationStacks.set(annotationStackIndex, withInsertions)
  }
}