Example #1
0
 canvas.on('mouse:over', ({target}) => {
   if (target && target.type && target.type === 'planet') {
     const hover = R.compose(
       R.forEach(pair => R.head(pair).set({fill: 'crimson'})),
       R.filter(_ => R.head(_).index === target.index)
     )
     hover(planets)
     //hover palents on same orbit
     R.compose(
       R.forEach(p => p[0].set({stroke: 'crimson'})),
       R.map(({index}) => {
         return R.find(
           p => p[0].index === index, planets
         )
       }),
       R.chain(R.prop('technologies')),
       R.filter(({action}) => ACTIONS[target.level] === action)
     )(groups)
     // hover orbit
     R.compose(
       R.forEach(orbit => orbit.set({stroke: 'crimson'})),
       R.filter(R.eqProps('level', target))
     )(orbits)
   }
 })
Example #2
0
import R from 'ramda'

/**
 * Compares two objects to see if their length
 * properties are the same.
 *
 * @since v1.0.0
 * @param {x} (String|Array|Object) The first thing to compare.
 * @param {y} (String|Array|Object) The 2nd thing to compare.
 * @return {Bool} Wether the objects have the same length.
 * @example
 * RS.eqLength([], []) //=> true
 * RS.eqLength({length: 2}, 'ab') //=> true
 */
const eqLength = R.eqProps('length')

export default eqLength
const objects = [{}, {}, {}];
const objectsClone: Array<Object> = _.clone(objects);
const objectsClone1: number = _.clone(1);
const objectsClone2: typeof tomato = _.clone(tomato);
//$ExpectError
const objectsClone3: $Shape<typeof tomato1> = _.clone(tomato);
const objectsClone4: $Shape<typeof tomato1> = _.clone(tomato1);

const id = objectsClone2.id;
//$ExpectError
const idE = objectsClone4.id;

const o1 = { a: 1, b: 2, c: 3, d: 4 };
const o2 = { a: 10, b: 20, c: 3, d: 40 };
const ep: boolean = _.eqProps("a")(o1, o2);
const ep2: boolean = _.eqProps("c", o1)(o2);

const hasid = _.has("id");
const has: boolean = hasid(tomato);

function Rectangle(width, height) {
  this.width = width;
  this.height = height;
}
Rectangle.prototype.area = function() {
  return this.width * this.height;
};

const square = new Rectangle(2, 2);
const hasIn: boolean = _.hasIn("width", square);
const objects = [ {}, {}, {} ]
const objectsClone: Array<Object> = _.clone(objects)
const objectsClone1: number = _.clone(1)
const objectsClone2: typeof tomato = _.clone(tomato)
//$ExpectError
const objectsClone3: $Shape<typeof tomato1> = _.clone(tomato)
const objectsClone4: $Shape<typeof tomato1> = _.clone(tomato1)

const id = objectsClone2.id
//$ExpectError
const idE = objectsClone4.id

const o1 = { a: 1, b: 2, c: 3, d: 4 }
const o2 = { a: 10, b: 20, c: 3, d: 40 }
const ep: boolean = _.eqProps('a')(o1, o2)
const ep2: boolean = _.eqProps('c', o1)(o2)

const hasid = _.has('id')
const has: boolean = hasid(tomato)

function Rectangle(width, height) {
  this.width = width
  this.height = height
}
Rectangle.prototype.area = function () {
  return this.width * this.height
}

const square = new Rectangle(2, 2)
const hasIn: boolean = _.hasIn('width', square)
import R from 'ramda';

export const lensMatching = pred => toF => entities => {
    const index = R.findIndex(pred, entities);
    return R.map(entity => R.update(index, entity, entities), toF(entities[index]));
};

export const lensById = R.compose(lensMatching, R.propEq('id'));
export const hasSameId = R.eqProps('id');
export const rejectById = (id, arr) => R.reject(hasSameId({ id }), arr);
export const strLen = R.curry(str => !str ? 0 : str.length);
export const isStringEmpty = R.compose(R.isEmpty, R.trim);
export const isNilOrEmpty = R.either(R.isNil, isStringEmpty);
export const notNilOrEmpty = R.compose(R.not, isNilOrEmpty);
 const removePredicate = n => R.eqProps('name', n, predicate)