本文整理汇总了TypeScript中Immutable.Map.setIn方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Map.setIn方法的具体用法?TypeScript Map.setIn怎么用?TypeScript Map.setIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Immutable.Map
的用法示例。
在下文中一共展示了Map.setIn方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reducer
function reducer(state: IReduxState = initial, { type, payload }: IAction): IReduxState {
const imState: Map<string, any> = fromJS(state);
switch (type) {
case 'VIEW_POLLS:LOAD_POLLS_SUCCESS':
return imState.set('polls', payload).toJS();
case 'VIEW_POLLS:LOAD_POLL_SUCCESS': {
interface IData { results: IPollResult[]; poll: IPoll; }
const data = payload as IData;
return imState.set('selectedPoll', data).toJS();
}
case 'VIEW_POLLS:SELECT_ANSWER': {
interface IData { questionIndex: number; answerIndex: number; }
const data = payload as IData;
const questions = imState.getIn(['selectedPoll', 'poll', 'questions']);
const question = questions.get(data.questionIndex);
return imState.setIn(
['selectedPoll', 'poll', 'questions', data.questionIndex],
question.set('answers', question.get('answers').map(
(answer: Map<string, any>, index: number) => answer.set('isSelected', index === data.answerIndex),
)),
).toJS();
}
default: return state;
}
}
示例2:
return imState.withMutations((mutable: Map<string, any>) => mutable.setIn(
['newPoll', 'questions'],
questions.set(
data.questionIndex,
question.set('answers', answers.set(data.answerIndex, answer.set('text', data.value))),
),
)).toJS();
示例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: 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;
}
}
示例5: adnet
export function adnet(state:Map<string,any> = Map<string,any>(), action:any):Map<string,any> {
switch (action.type) {
case AdnetActions.RECEIVE_CUSTOMERS:
{
return state.setIn(['customers'], action.customers);
}
default:
return state;
}
}
示例6: adnet
export function adnet(state:Map<string,any> = Map<string,any>(), action:any):Map<string,any> {
switch (action.type) {
case AdnetActions.RECEIVE_ADNET:
{
return state.setIn(['adnet'], action.payload);
}
default:
return state;
}
}
示例7: orders
export function orders(state:Map<string,any> = Map<string,any>(), action:any):Map<string,any> {
switch (action.type) {
case OrderActions.REQUEST_ORDERS:
return state;
case OrderActions.REQUEST_ORDER:
return state.setIn(['statusOrder'], OrderActions.REQUEST_ORDER);
case OrderActions.RECEIVED_ORDER:
state = state.setIn(['statusOrder'], OrderActions.RECEIVED_ORDER);
return state.setIn(['selectedOrder'], action.order);
case OrderActions.RECEIVED_ORDERS:
return state.setIn(['customerOrders'], action.orders);
default:
return state;
}
}
示例8:
_.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);
});
示例9: to3
3: function to3(nb : Map<string, any>) {
return nb
.setIn(['metadata', 'orig_nbformat'], nb.getIn(['metadata', 'orig_nbformat'], 2))
.set('nbformat', 3)
.set('nbformat_minor', 0)
.setIn(['worksheets', 'cels'], nb
.getIn(['worksheets', 0, 'cells'])
.map(cell => {
const newCell = cell.set('metadata', Map<string, any>());
return newCell;
})
);
},
示例10:
(cells: Map<CellId, ImmutableCell>) =>
cells.setIn(
[id, "metadata", "outputExpanded"],
!cells.getIn([id, "metadata", "outputExpanded"])
)