本文整理汇总了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);
};
示例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)
})
示例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 };
};
示例4: assoc
answer => assoc('id', Math.random().toString(36).substring(2), answer),
示例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);
};
示例6: assoc
(updatedItemsById, config) => assoc(String(config.id), config, updatedItemsById),
示例7:
const noteEditStartMod$ = noteEditId$.map(id => (state: State) => {
if (state.editingNoteId === id) {
return state
}
return R.assoc('editingNoteId', id, state) as State
})
示例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) {
示例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);