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


TypeScript ramda.evolve函数代码示例

本文整理汇总了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
  );
开发者ID:zernie,项目名称:typescript-redux-card-game,代码行数:11,代码来源:boardReducer.ts

示例2: curryN

export let defaults = curryN(2, (transformations, obj) => compose<any, any, any, () => any>(
  evolve(transformations),
  pickAll)(
    chain(keys, [transformations, obj]),
    obj))
开发者ID:goodmind,项目名称:cycle-telegram,代码行数:5,代码来源:index.ts

示例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);
开发者ID:zernie,项目名称:typescript-redux-card-game,代码行数:30,代码来源:gameStateReducer.ts

示例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);
开发者ID:zernie,项目名称:typescript-redux-card-game,代码行数:24,代码来源:minionReducer.ts

示例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)
  },

开发者ID:stefaniepei,项目名称:react-redux-scaffold,代码行数:29,代码来源:ramda.ts

示例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;
开发者ID:zernie,项目名称:typescript-redux-card-game,代码行数:31,代码来源:heroReducer.ts

示例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)
);
开发者ID:marley-js,项目名称:Mastering-TypeScript-Programming-Techniques,代码行数:21,代码来源:object.ts


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