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


TypeScript List.update方法代码示例

本文整理汇总了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;
  }

}
开发者ID:tanchifu,项目名称:angular2-todo,代码行数:34,代码来源:reducer.ts

示例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;
    }
}
开发者ID:nubiofs,项目名称:studioDashboard,代码行数:58,代码来源:AdnetReducer.ts

示例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;
    }
}
开发者ID:Floodlight-Studios,项目名称:studioDashboard,代码行数:32,代码来源:StationsReducer.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: 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;
  }
}
开发者ID:dominikgoss,项目名称:WunderListTreeMap,代码行数:19,代码来源:reducer.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: 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;
    }
}
开发者ID:Floodlight-Studios,项目名称:studioDashboard,代码行数:19,代码来源:BusinessesReducer.ts

示例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;
    }
}
开发者ID:DavyDuDu,项目名称:ng2Boilerplate,代码行数:21,代码来源:TodoReducer.ts

示例10:

 (tByAccount: List<ITransactionRecord>)=>{
     return tByAccount.update(tByAccount.indexOf(originalTransaction),
                              (v)=>modifiedTransaction);
 }
开发者ID:bryanerayner,项目名称:bank-accounts-model,代码行数:4,代码来源:bank-accounts.reducer.ts


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