本文整理汇总了TypeScript中Immutable.List.push方法的典型用法代码示例。如果您正苦于以下问题:TypeScript List.push方法的具体用法?TypeScript List.push怎么用?TypeScript List.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Immutable.List
的用法示例。
在下文中一共展示了List.push方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getAdjacencies
export function getAdjacencies(voucherBooks: List<EAPAVoucherBook>): List<VoucherBookAdjacency> {
let prevIds = voucherBooks.insert(0, undefined);
let nextIds = voucherBooks.push(undefined).skip(1);
return voucherBooks.zipWith(
(curr, prev, next) => getAdjacency(curr, prev, next),
voucherBooks.insert(0, undefined),
voucherBooks.push(undefined).skip(1)
).toList();
}
示例2: log
function log(state: List<Message> = List<Message>(), action: Action): List<Message> {
switch (action.type) {
case ActionType.CHANGE_CHANNEL:
// Clear log
return List<Message>()
case ActionType.LOG_LINE:
return state.push(Object.freeze({id: -1, channel: -1, username: "***", content: action.payload.log, timestamp: new Date()}))
case ActionType.CHAT_MESSAGE:
return state.push(action.payload.message)
default:
return state
}
}
示例3: reduceOutputs
export function reduceOutputs(
outputs: List<ImmutableOutput> = List(),
output: OnDiskOutput
): List<ImmutableOutput> {
// Find the last output to see if it's a stream type
// If we don't find one, default to null
const last = outputs.last(null);
if (!last || !last.output_type) {
return outputs.push(createImmutableOutput(output));
}
if (output.output_type !== "stream" || last.output_type !== "stream") {
// If the last output type or the incoming output type isn't a stream
// we just add it to the outputs
// This is kind of like a "break" between streams if we get error,
// display_data, execute_result, etc.
return outputs.push(createImmutableOutput(output));
}
const streamOutput: OnDiskStreamOutput = output;
if (typeof streamOutput.name === "undefined") {
return outputs.push(createImmutableOutput(streamOutput));
}
function appendText(text: string): string {
if (typeof streamOutput.text === "string") {
return escapeCarriageReturnSafe(text + streamOutput.text);
}
return text;
}
// Invariant: size > 0, outputs.last() exists
if (last.name === streamOutput.name) {
return outputs.updateIn([outputs.size - 1, "text"], appendText);
}
// Check if there's a separate stream to merge with
const nextToLast = outputs.butLast().last(null);
if (
nextToLast &&
nextToLast.output_type === "stream" &&
nextToLast.name === streamOutput.name
) {
return outputs.updateIn([outputs.size - 2, "text"], appendText);
}
// If nothing else matched, just append it
return outputs.push(createImmutableOutput(streamOutput));
}
示例4: addNode
addNode(node: any) {
var nodes = this.nodes.push(node);
var children = this.children.set(node.id, List<any>());
var parents = this.parents.set(node.id, List<any>());
return new Graph(nodes, children, parents);
}
示例5: reducer
export function reducer(state: List<SettingItem> = List<SettingItem>(), action: ITodoAction) {
function indexOf(uuid: string) {
return state.findIndex((i: SettingItem) => i.uuid === action.itemId);
}
function createItemObj(text: string) {
if (!text) {
return new SettingItem();
}
if (text.indexOf('|') >= 0) {
// parse the text for name|value format
let tokens = text.split('|');
if (tokens.length > 1) {
return new SettingItem({name: tokens[0], value: tokens[1], completed: false, uuid: uuid.v4()});
}
}
return new SettingItem({name: '[no name]', value: text, completed: false, uuid: uuid.v4()});
}
switch (action.type) {
case 'ADD':
return state.push(createItemObj(action.text));
case 'REMOVE':
return List<SettingItem>(state.filter((i: SettingItem) => i.uuid !== action.itemId));
case 'UPDATE_ITEM_VALUE':
return state.update(indexOf(action.itemId), (i: SettingItem) => i.setValue(action.text));
case 'UPDATE_ITEM_COMPLETION':
return state.update(indexOf(action.itemId), (i: SettingItem) => i.setCompleted(action.completed));
default:
return state;
}
}
示例6: deleteObjectIdRecur
function deleteObjectIdRecur(obj: any, stack: List<object>) {
for (let i=0; i< stack.size; i++) {
if (i > 10) {
logger.warn("deleteObjectIdRecur: Too deep stack");
logger.warn(obj);
return;
}
if (obj === stack[i]) {
logger.warn("deleteObjectIdRecur: recurrence found");
logger.warn(obj);
return;
}
}
if (obj !== null && typeof(obj) == 'object') {
if (obj instanceof Promise) {
logger.warn("deleteObjectIdRecur: Object is promise");
} else if (Array.isArray(obj)) {
for (let i = 0; i < obj.length; i++) {
if (obj[i] && obj[i]._id) deleteObjectIdRecur(obj[i], stack.push(obj)); //recursive del calls on array elements
}
} else {
delete obj._id;
Object.keys(obj).forEach(function(key) {
if (obj[key] && obj[key]._id) deleteObjectIdRecur(obj[key], stack.push(obj)); //recursive del calls on object elements
});
}
}
}
示例7: 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);
}
}
示例8: addTodo
public addTodo(title: string){
this.history = this.history.push(this.todos);
this.todos.push(fromJS({
id: Utils.uuid(),
title: title,
completed: false
}));
}
示例9: Epic
.subscribe(results => {
if (results.type === ItemNameDialogResultType.Saved) {
let epic = new Epic(this.modelId, this.router, this._createStoryDialog, results.name);
epic.observeEvents();
this._epics = this._epics.push(epic);
}
this._createEpicDialog.close();
});
示例10: adnet
export function adnet(state: Map<string,any> = Map<string,any>(), action: any): Map<string,any> {
var indexOfRateId = function (i_rateId: string) {
return rates.findIndex((i: AdnetRateModel) => i.rateId() === i_rateId);
}
var indexOfCustomerId = function (i_adnetCustomerId: string) {
return customers.findIndex((i: AdnetCustomerModel) => i.customerId() === i_adnetCustomerId);
}
switch (action.type) {
case AdnetActions.RECEIVE_CUSTOMERS: {
return state.setIn(['customers'], action.customers);
}
case AdnetActions.RECEIVE_RATES: {
return state.setIn(['rates'], action.rates);
}
case AdnetActions.UPDATE_ADNET_RATE_TABLE: {
var rates: List<AdnetRateModel> = state.getIn(['rates']);
rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
return rate.setField('rateMap', action.payload.rateTable)
});
rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
rate = rate.setField('hourRate0', action.payload.adHourlyRate["0"])
rate = rate.setField('hourRate1', action.payload.adHourlyRate["1"])
rate = rate.setField('hourRate2', action.payload.adHourlyRate["2"])
rate = rate.setField('hourRate3', action.payload.adHourlyRate["3"])
return rate;
});
return state.setIn(['rates'], rates);
}
case AdnetActions.ADD_ADNET_RATE_TABLE: {
var rates: List<AdnetRateModel> = state.getIn(['rates']);
rates = rates.push(action.adnetRateModel);
return state.setIn(['rates'], rates);
}
case AdnetActions.REMOVE_ADNET_RATE_TABLE: {
var rates: List<AdnetRateModel> = state.getIn(['rates']);
var updatedRates:List<AdnetRateModel> = rates.filter((adnetRateModel:AdnetRateModel) => adnetRateModel.rateId() !== action.rateId) as List<AdnetRateModel>;
return state.setIn(['rates'], updatedRates);
}
case AdnetActions.UPDATE_ADNET_CUSTOMER: {
var customers: List<AdnetCustomerModel> = state.getIn(['customers'])
customers = customers.update(indexOfCustomerId(action.payload.Key), (customer: AdnetCustomerModel) => {
return customer.setData<AdnetCustomerModel>(AdnetCustomerModel, action.payload)
});
return state.setIn(['customers'], customers);
}
case AdnetActions.RENAME_ADNET_RATE_TABLE: {
var rates: List<AdnetRateModel> = state.getIn(['rates']);
rates = rates.update(indexOfRateId(action.payload.rateId), (rate: AdnetRateModel) => {
return rate.setField('label', action.payload.newLabel)
});
return state.setIn(['rates'], rates);
}
default:
return state;
}
}