本文整理汇总了TypeScript中Immutable.List.concat方法的典型用法代码示例。如果您正苦于以下问题:TypeScript List.concat方法的具体用法?TypeScript List.concat怎么用?TypeScript List.concat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Immutable.List
的用法示例。
在下文中一共展示了List.concat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: todosReducer
function todosReducer(state:List<ITask>, action:IAction):List<ITask> {
console.log(`todosReducer: Action(${JSON.stringify(action)})`);
switch(action.type) {
case Keys.AddTodo:
var todos: List<ITask> = List<ITask>(state.concat([action.payload]));
console.log(`todosReducer: todos(${JSON.stringify(todos)})`);
return todos;
case Keys.CompleteTodo:
return List<ITask>(state.map((task:ITask) => {
if (task.Id === action.payload.Id) {
return new Task(
task.Id,
task.Title,
task.Description,
action.payload.Complete
);
} else {
return task;
}
}));
case Keys.RemoveTodo:
return List<ITask>(state.filter((task:ITask) => {
return task.Id !== action.payload.Id;
}))
}
return state || initialState.todos;
}
示例2: getState
getState(path: Array<string> | List<string> | string = List([])): any {
let newPath: List<string>;
if (typeof path === 'string') {
newPath = List([path]);
} else {
newPath = fromJS(path);
}
return this.rootStore.state.getIn(this.path.concat(newPath));
}
示例3: process
/**
* Function that intented to be used by the table plugin manager to
* perform the sorting process. It supports sorting with mutiple sorter,
* which will be performed in ASC order.
*
* NOTE: the sorting process will short circuit on any non-zero sorter
* result.
*/
process(tableData: TableData, columns: List<ColumnDef>) {
const columnSorters: Iterable<number, TableSorter> = columns
.filterNot(s => _.isUndefined(s.sortable))
.map(columnDef => {
const sorter = columnDef.sortable
const selector = columnDef.field
const type = columnDef.type
const order = sorter.order
const comparator = sorter.comparator || this.getComparator(type)
return { order, selector, comparator }
})
const sorters = this.sorters.concat(columnSorters)
.filter(s => this.getSortOrder(s.order) !== NONE)
if (sorters.size > 1 && !this.multiSortable) {
if (process.env.NODE_ENV === 'development') {
throw new Error(`[RCBOX] Found multiple sorter enabled while this` +
`feature is disabled. To enable this feature, set 'multiSortable' ` +
`property to 'true' on TableSortPlugin. Those unexpected sorters ` +
`are: ${sorters.toJS()}`)
}
// NOTE: Returns unsorted table data as fallback to avoid uncertain
// data will be used in production environment.
return tableData
}
const sorted = tableData.sort((row1, row2) => {
const reducer = (result: number, sorter: TableSorter) => {
const { selector, comparator } = sorter
const order = this.getSortOrder(sorter.order)
const factor = order === DESC ? -1 : 1
return result !== 0
? result
: comparator(selector(row1), selector(row2)) * factor
}
return sorters.reduce(reducer, 0)
})
return sorted
}
示例4: todosReducer
function todosReducer(state:List<ITask>, action:IAction):List<ITask> {
switch(action.key) {
case Keys.AddTodo:
return List<ITask>(state.concat([action.payload]))
case Keys.CompleteTodo:
return List<ITask>(state.map((task:ITask) => {
if (task.Id === action.payload.Id) {
return new Task(
task.Id,
task.Title,
task.Description,
action.payload.Complete
);
} else {
return task;
}
}));
case Keys.RemoveTodo:
return List<ITask>(state.filter((task:ITask) => {
return task.Id !== action.payload.Id;
}))
}
return state;
}