当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript List.findIndex方法代码示例

本文整理汇总了TypeScript中Immutable.List.findIndex方法的典型用法代码示例。如果您正苦于以下问题:TypeScript List.findIndex方法的具体用法?TypeScript List.findIndex怎么用?TypeScript List.findIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Immutable.List的用法示例。


在下文中一共展示了List.findIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

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);
  }
}
开发者ID:wsquared,项目名称:angular2-task,代码行数:32,代码来源:taskReducer.ts

示例2:

 (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);
 }
开发者ID:nteract,项目名称:nteract,代码行数:15,代码来源:notebook.ts

示例3: updateActivityInMention

    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];
            }
        }
    }
开发者ID:DevenLu,项目名称:YourFukurou,代码行数:27,代码来源:timeline.ts

示例4: updateStatusIn

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;
        }
    });
}
开发者ID:DevenLu,项目名称:YourFukurou,代码行数:30,代码来源:timeline.ts

示例5: focusPreviousCellEditor

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));
}
开发者ID:nteract,项目名称:nteract,代码行数:12,代码来源:notebook.ts

示例6: onRated

 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
       };
   });
 }
开发者ID:Vincent-Pang,项目名称:conf-app-v2,代码行数:13,代码来源:talks.component.ts

示例7:

 _.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);
 });
开发者ID:alexbraisch,项目名称:studioDashboard,代码行数:13,代码来源:ResellerReducer.ts

示例8: todos

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;
    }
}
开发者ID:pedrogusman,项目名称:ionic-2-redux-starter,代码行数:18,代码来源:todoReducers.ts

示例9: focusNextCellEditor

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));
}
开发者ID:nteract,项目名称:nteract,代码行数:19,代码来源:notebook.ts

示例10: todosReducer

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;
  }
}
开发者ID:tedliang,项目名称:angular2-redux-starter,代码行数:21,代码来源:todo.ts


注:本文中的Immutable.List.findIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。