本文整理汇总了TypeScript中ramda.evolve函数的典型用法代码示例。如果您正苦于以下问题:TypeScript evolve函数的具体用法?TypeScript evolve怎么用?TypeScript evolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了evolve函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: characterReducer
const characterHandler = (
state: EntityContainer,
action: Action<EntityPayload<Object>>
): EntityContainer =>
R.evolve(
{
[action.payload.id]: (character: Character) =>
characterReducer(character, action),
},
state
);
示例2: curryN
export let defaults = curryN(2, (transformations, obj) => compose<any, any, any, () => any>(
evolve(transformations),
pickAll)(
chain(keys, [transformations, obj]),
obj))
示例3: actionCreatorFactory
import { reducerWithInitialState } from 'typescript-fsa-reducers';
import { gainMana, restoreMana } from './Board/Hero/actions';
import { Game, getDeck, State } from '../Game';
import { activeHero, getOpponent, getPlayer, other } from '../Hero';
import initialState from './initialState';
import { drawCard } from './Deck/deckReducer';
import { selectCards } from '../Card';
import { PlayState, Step } from '../enums';
const actionCreator = actionCreatorFactory();
export const finishGame = actionCreator('FINISH_GAME');
export const nextTurn = actionCreator('NEXT_TURN');
const finishGameHandler = R.evolve<State>({
step: () => Step.FinalGameOver,
});
const nextTurnHandler = R.evolve<State>({
turn: R.inc,
activePlayer: other,
});
export const checkForEndGame = (): ThunkAction<void, Game, {}> => (
dispatch,
getState
) => {
const state = getState();
const player = getPlayer(state);
const opponent = getOpponent(state);
示例4: reduceHealth
import * as R from 'ramda';
import { upcastingReducer } from 'typescript-fsa-reducers';
import { reduceHealth } from '../../../Hero';
import { attackCharacter, dealDamage, DealDamagePayload } from '../actions';
import { Minion } from '../../../Minion';
import { Character } from '../../../Character';
const attackCharacterHandler = R.evolve({ attacksPerformed: R.inc });
const damageMinionHandler = (
state: Minion,
payload: DealDamagePayload
): Minion => {
const health = reduceHealth(state, payload.amount);
return R.merge(state, {
destroyed: health <= 0,
health: health,
});
};
export default upcastingReducer<Minion, Character>()
.case(attackCharacter, attackCharacterHandler)
.case(dealDamage, damageMinionHandler);
示例5: dissoc
dissoc(field, val, obj) {
return R.dissoc(field, val, obj)
},
// [Idx] → {k: v} → {k: v}
// Idx = String | Int
dissocPath(fieldsLevelArr, obj) {
return R.dissocPath(fieldsLevelArr, obj)
},
// omit :: [String] → {String: *} → {String: *}
omit(fieldsArr, obj) {
return R.omit(fieldsArr, obj)
},
// evolve :: {k: (v → v)} → {k: v} → {k: v}
evolve(fnOrKV, obj) {
return R.evolve(fnOrKV, obj)
},
// merge :: {k: v} → {k: v} → {k: v}
merge(objA, objB) {
return R.merge(objA, objB)
},
//// Logic ////
// defaultTo :: a → b → a | b
defaultTo(V1, V2) {
return R.defaultTo(V1, V2)
},
示例6:
destroyWeapon,
equipWeapon,
EquipWeaponPayload,
gainMana,
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;
示例7: updateToUpperCase
import * as R from 'ramda';
const obj = {
name: 'John',
age: 22
};
const obj2 = {
name: 'Steve',
age: 22
};
// const newObj = R.clone(obj);
// console.log(newObj);
const updateToUpperCase = R.evolve({ name: R.toUpper});
console.log(
// R.eqProps('name', obj, obj2)
// R.has('name', obj)
// R.mergeDeepRight(obj, obj2)
updateToUpperCase(obj)
);