本文整理汇总了TypeScript中lodash.sortedIndexBy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sortedIndexBy函数的具体用法?TypeScript sortedIndexBy怎么用?TypeScript sortedIndexBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sortedIndexBy函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
_.forEach(newObjects, (newObject: any) => {
let uiObject = _.find(uiObjects, {id: newObject.id});
if (uiObject) {
Object.assign(uiObject, newObject);
} else {
uiObjects.splice(_.sortedIndexBy(uiObjects, newObject, options.sort || 'id'), 0, newObject);
}
});
示例2: getIndexBoundsForPointData
export function getIndexBoundsForPointData(data: SeriesData, xValueBounds: Interval, xValuePath: string): IndexBounds {
const lowerBound = _.set({}, xValuePath, xValueBounds.min);
const upperBound = _.set({}, xValuePath, xValueBounds.max);
const firstIndex = _.sortedIndexBy(data, lowerBound, xValuePath);
const lastIndex = _.sortedLastIndexBy(data, upperBound, xValuePath);
return adjustBounds(firstIndex, lastIndex, data.length);
}
示例3: getBoundsForInstantaeousData
export function getBoundsForInstantaeousData(timestampedData: SeriesData, timeRange: Range, timestampPath: string = 'timestamp'): IndexBounds {
const lowerBound = _.set({}, timestampPath, timeRange.min);
const upperBound = _.set({}, timestampPath, timeRange.max);
const firstIndex = _.sortedIndexBy(timestampedData, lowerBound, timestampPath);
const lastIndex = _.sortedLastIndexBy(timestampedData, upperBound, timestampPath);
return adjustBounds(firstIndex, lastIndex, timestampedData.length);
}
示例4: createRoom
export function createRoom(roomName: string, socket: LobbySocket) {
const room = new Room(roomName);
byName[roomName] = room;
const index = _.sortedIndexBy(sortedByPlayerCount, room.entry, (x) => -x.playerCount);
sortedByPlayerCount.splice(index, 0, room.entry);
return room;
}
示例5:
return _.mapValues(dataBySeriesId, (data: any[], seriesId: SeriesId) => {
// -1 because sortedIndexBy returns the first index that would be /after/ the input value, but we're trying to
// get whichever value comes before. Note that this may return undefined, but that's specifically allowed:
// there may not be an appropriate hover value for this series.
return data[ _.sortedIndexBy(data, haxWrappedHover, xIterator.bind(null, seriesId)) - 1 ];
});
示例6: switch
const todos = (state = initialState, action: Action): TodosState => {
switch (action.type) {
case TodoActionType.Add:
const lastTodo = state.todosById[last(state.orderedTodos)]
const addId = lastTodo ? last(state.todos) + 1 : 0
return assign({}, state, {
todos: [...state.todos, addId],
orderedTodos: [...state.orderedTodos, addId],
todosById: assign({}, state.todosById, {
[addId]: {
id: addId,
order: state.orderedTodos.length,
isDone: false,
startHour: lastTodo ? (
moment(lastTodo.startHour)
.add(lastTodo.duration, 'minutes')
.toDate()
) : (
moment({ hour: 9 }).toDate()
),
duration: 60,
task: '',
detail: '',
isCreating: true,
isDeleting: false
}
})
})
case TodoActionType.Added:
return assign({}, state, {
todosById: state.todos.reduce((obj, id) => {
let todo = state.todosById[id]
if (todo.isCreating) {
todo = assign({}, todo, {
isCreating: false
})
}
obj[id] = todo
return obj
}, {} as TodosMap)
})
case TodoActionType.Delete:
const { id: deleteId } = action as TodoAction
return assign({}, state, {
todosById: assign({}, state.todosById, {
[deleteId]: assign({}, state.todosById[deleteId], {
isDeleting: true
})
})
})
case TodoActionType.Deleted:
const { id: deletedId } = action as TodoAction
const deletedTodo = state.todosById[deletedId]
if (!deletedTodo) {
return state
}
return assign({}, state, {
todos: without(state.todos, deletedId),
orderedTodos: without(state.orderedTodos, deletedId),
todosById: state.todos.reduce((obj, id) => {
if (id === deletedId) {
return obj
}
let todo = state.todosById[id]
if (todo.order > deletedTodo.order) {
todo = assign({}, todo, {
order: todo.order - 1,
startHour: moment(todo.startHour)
.subtract(deletedTodo.duration, 'minutes')
.toDate()
})
}
obj[id] = todo
return obj
}, {} as TodosMap)
})
case TodoActionType.Move:
const { fromPos: moveFromPos, toPos: moveToPos } = action as MoveAction
return moveTodo(state, moveFromPos, moveToPos)
case TodoActionType.SetStartHour:
const { id: startHourId, value: startHour } = action as SetValueAction
let startHourTodo = state.todosById[startHourId]
let nextState = state
if (startHourTodo.startHour > startHour) {
const startHourFromPos = startHourTodo.order
const startHourToPos = sortedIndexBy(
state.orderedTodos,
startHourId,
id => {
if (id === startHourId) {
return startHour
}
return state.todosById[id].startHour
}
)
nextState = moveTodo(state, startHourFromPos, startHourToPos)
startHourTodo = nextState.todosById[startHourId]
}
const startHourDiff = moment(startHour)
.diff(moment(startHourTodo.startHour), 'minutes')
//.........这里部分代码省略.........
示例7: sortedIndexBy
this.on(eventType, (data: T) => {
if (!matcher || matcher(data)) {
const index = sortedIndexBy(list, data, 'id');
list.splice(index, 0, data);
}
});