本文整理汇总了TypeScript中ramda.assoc函数的典型用法代码示例。如果您正苦于以下问题:TypeScript assoc函数的具体用法?TypeScript assoc怎么用?TypeScript assoc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assoc函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: async
const setKeyValues = async (acc, entries) => {
if (entries.length) return acc;
const [[key, value], ...tail] = entries;
const maybeValue = await formatData(key, value);
const newAcc = maybeValue.map(assoc(key, __, acc)).getOrElse(acc);
return await setKeyValues(newAcc, tail);
};
开发者ID:benjambles,项目名称:my-own-world,代码行数:9,代码来源:formatter.ts
示例2: update
const noteDragMod$ = noteDrag$.map(({ id, x, y }) => (state: State) => {
const update = R.compose<State, State, State>(
R.set(
R.lensPath(['notes', id, 'pos']),
{ x, y } as Position
),
R.assoc('draggingNoteId', id)
)
return update(state)
})
开发者ID:JamesHageman,项目名称:xstream-scrumbler,代码行数:10,代码来源:index.ts
示例3: catch
export const jsonDecorator = ({
modelName,
fields,
}: {
modelName: string;
fields: (Fields & WithHidden) | PositionsField;
}): { modelName; fields: (Fields & WithHidden) | PositionsField } => {
const TAG = '[jsonDecorator]';
logger.log(TAG, { fields });
const jsonFields = R.filter(R.pathEq(['options', 'json'], 'str'))(fields);
if (R.not(R.isEmpty(jsonFields))) {
logger.debug(TAG, { jsonFields });
const toJson = value => {
if (R.is(String, value) && value.length) {
try {
return JSON.parse(value);
} catch (e) {
logger.warn(TAG, e, { jsonFields });
return null;
}
}
if (R.is(Object, value)) {
return value;
}
return null;
};
const transformValue = R.over(R.lens(R.prop('value'), R.assoc('value')), toJson);
const transformedFields = R.map(transformValue)(jsonFields);
const wrappedFields = R.mergeDeepRight(fields, transformedFields);
logger.log(TAG, 'wrappedFields', { wrappedFields });
return { modelName, fields: wrappedFields };
}
return { modelName, fields };
};
开发者ID:danielwii,项目名称:asuna-admin,代码行数:39,代码来源:index.ts
示例4: assoc
answer => assoc('id', Math.random().toString(36).substring(2), answer),
开发者ID:goodmind,项目名称:cycle-telegram,代码行数:1,代码来源:sinks.ts
示例5: dispatch
if (
attacker.type === CardType.Hero &&
attacker.weapon &&
attacker.weapon.durability <= 0
) {
dispatch(destroyWeapon({ id: attacker.id }));
}
if (shouldExhaust(attacker)) {
dispatch(exhaust({ id: attacker.id }));
}
dispatch(processDeaths());
dispatch(checkForEndGame());
};
const exhaustHandler = R.assoc<keyof Character, boolean>('exhausted', true);
export default (state: Character, action: Action<EntityPayload<Object>>) => {
if (isType(action, exhaust)) {
return reducerWithoutInitialState<Character>().case(
exhaust,
exhaustHandler
)(state, action);
}
return state.type === CardType.Minion
? minionReducer(state, action)
: heroReducer(state, action);
};
开发者ID:zernie,项目名称:typescript-redux-card-game,代码行数:30,代码来源:characterReducer.ts
示例6: assoc
(updatedItemsById, config) => assoc(String(config.id), config, updatedItemsById),
开发者ID:displague,项目名称:manager,代码行数:1,代码来源:nodeBalancerConfig.reducer.ts
示例7:
const noteEditStartMod$ = noteEditId$.map(id => (state: State) => {
if (state.editingNoteId === id) {
return state
}
return R.assoc('editingNoteId', id, state) as State
})
开发者ID:JamesHageman,项目名称:xstream-scrumbler,代码行数:6,代码来源:index.ts
示例8: path
// Idx = String | Int
path(fieldsLevelArr, obj) {
return R.path(fieldsLevelArr, obj)
},
pathOr(defaultVal, fieldsLevelArr, obj) {
return R.path(defaultVal, fieldsLevelArr, obj)
},
// pick :: [k] → {k: v} → {k: v}
pick(fieldsArr, obj) {
return R.pick(fieldsArr, obj)
},
// assoc/assocPath
// assoc :: String → a → {k: v} → {k: v}
assoc(field, val, obj) {
return R.assoc(field, val, obj)
},
// [Idx] → a → {a} → {a}
// Idx = String | Int
assocPath(fieldsLevelArr, val, obj) {
return R.assocPath(fieldsLevelArr, val, obj)
},
// dissoc/dissocPath
// String → {k: v} → {k: v}
dissoc(field, val, obj) {
return R.dissoc(field, val, obj)
},
// [Idx] → {k: v} → {k: v}
// Idx = String | Int
dissocPath(fieldsLevelArr, obj) {
开发者ID:stefaniepei,项目名称:react-redux-scaffold,代码行数:31,代码来源:ramda.ts
示例9:
GainManaPayload,
restoreMana,
spendMana,
SpendManaPayload,
} from './actions';
import { PlayState } from '../../../enums';
const maximumManaLens = R.lensProp<number, Hero>('maximumMana');
const manaLens = R.lensProp<number, Hero>('mana');
const attackCharacterHandler = R.evolve<Hero>({
attacksPerformed: R.inc,
weapon: { durability: R.dec },
});
const destroyWeaponHandler = R.assoc<keyof Hero, null>('weapon', null);
const equipWeaponHandler = (state: Hero, payload: EquipWeaponPayload) =>
R.merge<Hero, {}>(state, {
attack: payload.weapon.attack,
weapon: payload.weapon,
});
const gainManaHandler = (state: Hero, payload: GainManaPayload) =>
state.maximumMana < 10
? R.over(maximumManaLens, R.add(payload.amount || 1), state)
: state;
const restoreManaHandler = (state: Hero) =>
R.set(manaLens, R.view(maximumManaLens, state), state);
开发者ID:zernie,项目名称:typescript-redux-card-game,代码行数:30,代码来源:heroReducer.ts
注:本文中的ramda.assoc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论