本文整理汇总了TypeScript中Immutable.List.update方法的典型用法代码示例。如果您正苦于以下问题:TypeScript List.update方法的具体用法?TypeScript List.update怎么用?TypeScript List.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Immutable.List
的用法示例。
在下文中一共展示了List.update方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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;
}
}
示例2: 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;
}
}
示例3: stations
export function stations(state:Map<string,any> = Map<string,any>(), action:any):Map<string, List<StationModel>> {
function indexOfStation(businessId, stationId):any {
return stations.findIndex((i:StationModel) => {
return i.getKey('businessId') === businessId && i.getKey('id') == stationId;
});
}
switch (action.type) {
case StationsAction.RECEIVE_STATIONS:
return state.update(action.source, (value) => action.stations);
case StationsAction.RECEIVE_STATIONS_GEO:
for (var i in action.payload) {
var station = action.payload[i];
var source = station.source;
var stations:List<StationModel> = state.get(source);
stations = stations.update(indexOfStation(station.businessId, station.id), (i_station:StationModel) => {
return i_station.setKey<StationModel>(StationModel, 'geoLocation', {
lat: station.lat,
lon: station.lon,
city: station.city,
country: station.country
})
});
state = state.setIn([source], stations);
}
return state;
default:
return state;
}
}
示例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;
}
});
}
示例5: reducer
export function reducer(state: List<TodoItem> = List<TodoItem>(), action: ITodoAction) {
function indexOf(uuid: string) {
return state.findIndex((i: TodoItem) => i.uuid === action.itemId);
}
switch (action.type) {
case 'ADD':
return state.push(new TodoItem().setText(action.text));
case 'REMOVE':
return List<TodoItem>(state.filter((i: TodoItem) => i.uuid !== action.itemId));
case 'UPDATE_ITEM_TEXT':
return state.update(indexOf(action.itemId), (i: TodoItem) => i.setText(action.text));
case 'UPDATE_ITEM_COMPLETION':
return state.update(indexOf(action.itemId), (i: TodoItem) => i.setCompleted(action.completed));
default:
return state;
}
}
示例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
};
});
}
示例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);
});
示例8: default
export default (state:List<BusinessModel> = List<BusinessModel>(), action:IBusinessAction):List<BusinessModel> => {
function indexOf(businessId:string) {
return state.findIndex((i:BusinessModel) => i.getBusinessId() === businessId);
}
switch (action.type) {
case BusinessAction.REQUEST_BUSINESSES:
return state;
case BusinessAction.RECEIVE_BUSINESSES:
return List(action.businesses);
case BusinessAction.SET_BUSINESS_DATA:
return state.update(indexOf(action.businessId), (business:BusinessModel) => {
return business.setKey<BusinessModel>(BusinessModel, action.key, action.value)
});
default:
return state;
}
}
示例9: todos
export function todos(state:List<TodoModel> = List<TodoModel>(), action:ITodoAction):List<TodoModel> {
function indexOf(id:string) {
return state.findIndex((i:TodoModel) => i.getModelId() === id);
}
switch (action.type) {
case TodoAction.ADD_TODO:
return state.push(action.todoModel);
case TodoAction.REMOVE_TODO:
return List<TodoModel>(state.filter((i:TodoModel) => i.getKey('modelId') !== action.modelId));
case TodoAction.CLEAR_TODOS:
return List<TodoModel>();
case TodoAction.EDIT_TODO:
return state.update(indexOf(action.modelId), (todoModel:TodoModel) => {
return todoModel.setKey<TodoModel>(TodoModel, action.key, action.value)
});
default:
return state;
}
}
示例10:
(tByAccount: List<ITransactionRecord>)=>{
return tByAccount.update(tByAccount.indexOf(originalTransaction),
(v)=>modifiedTransaction);
}