/**
 * Converts Arrays and Sets to DynamoDb "NS"
 *
 * @param item
 * @returns {*}
 */
var marshalNumberSet = transform(_.isArray, marshalArrayToNumberSet);

/**
 * Converts strings to DynamoDb "S"
 *
 * @param item
 * @returns {*}
 */
var marshalString = transform(_.overSome(_.isString, _.negate(_.isEmpty)), objOf('S'));

function isStringSet(arr) {
  return !_.isEmpty(arr) &&
     _.every(_.isString, arr) &&
      _.uniq(arr).length === arr.length
}

/**
 * Helper function for arrays to DynamoDb "SS"
 *
 * @param arr
 * @returns {*}
 */
var marshalArrayToStringSet = transform(isStringSet, objOf('SS'));
Beispiel #2
0
//------//
// Main //
//------//

const capIteratee = fp.curry((cap, fn) =>
  fp.curryN(fn.length, (iteratee, ...args) =>
    fn.apply(null, [fp.ary(cap, iteratee)].concat(args))
  )
);

const repeat = fp.curry((b, a) => fp.repeat(a, b));

const wrapStr = (str, wrap) => wrap + str + wrap;

const isDefined = fp.negate(fp.isUndefined)
  , getOpeningBrace = () => braceColor('{')
  , getClosingBrace = () => braceColor('}')
  , getEmptyObject = () => braceColor('{}')
  , getOpeningBracket = () => bracketColor('[')
  , getClosingBracket = () => bracketColor(']')
  , getEmptyArray = () => bracketColor('[]')
  , getIndent = repeat(indent)
  , isLadenArray = fp.allPass(fp.isArray, fp.size)
  , isLadenPlainObject = fp.allPass(fp.isPlainObject, fp.size)
  , reduceWithKey = capIteratee(3, fp.reduce.convert({ cap: false }))
  , keyToStr = key => {
    if (!stripKeyQuotes) key = wrapStr(key, '"');
    return isDefined(key)
      ? key + ': '
      : '';
};

export const fetchPatientsOnMount = ({
  componentDidMount() {
    this.props.actions.fetchPatientsRequest();
  },
});

export const fetchPatientsCountsOnMountAndUpdate = ({
  componentDidMount() {
    const { actions, currentPagePatients } = this.props;
    actions.fetchPatientCountsRequest(currentPagePatients);
  },

  componentWillReceiveProps({ currentPagePatients, actions, offset }) {
    const isNewPatients = _.negate(_.isEqual(this.props.currentPagePatients));
    return _.cond([
      [isNewPatients, actions.fetchPatientCountsRequest],
    ])(currentPagePatients)
  },
});

export const fetchHeaderToolbarOnMount = ({
  componentDidMount() {
    const { actions, match } = this.props;
    const userId = _.get('params.userId', match);
    if (userId && _.isEmpty(this.props.patientsDemographics[userId])) actions.fetchPatientDemographicsRequest({ userId })
  },
  componentWillReceiveProps(nextProps) {
    const { actions, match } = this.props;
    const nextUserId = _.get('match.params.userId', nextProps);
Beispiel #4
0
import {
  flatMap, constant, negate, allPass, lte, gte, flow, filter,
  findIndex, slice, eq, cond, first, last, includes, isEmpty,
} from 'lodash/fp';
import { hasAttributes, hasAttribute } from './util/attribute';
import hasTagName from './util/hasTagName';
import { findAncestor } from './basic';
import _ from '.';

const isDurational = allPass([hasAttribute('dur'), negate(hasAttribute('grace'))]);

const elementFromAttribute = (attribute) => (element) => {
  const id = element.getAttribute(attribute).substring(1);
  return _(findAncestor(hasTagName('score'))(element))
    .descendants()
    .find(e => e.getAttribute('xml:id') === id);
};

const getElementInTstamp = (tstampGetter, measureGetter) => (element) => {
  const tstamp = tstampGetter(element);

  const measures = _.spannedMeasures(element);
  const measure = measureGetter(measures);
  let elements = _.durationalsByTstamp(measure)[tstamp];

  if (isEmpty(elements)) throw new Error(`Could not find elements with tstamp=${tstamp}`);

  const staff = element.getAttribute('staff');
  if (staff) {
    elements = filter(flow(_.staffN, eq(staff)), elements);
    if (isEmpty(elements)) throw new Error(`Could not find elements with staff=${staff}`);
function fallbackValue (crypto, machine, instances) {
  const notNil = _.negate(_.isNil)
  const pickValue = arr => _.find(instance => matchesValue(arr[0], arr[1], instance), instances)
  const fallbackRec = _.find(notNil, _.map(pickValue, permutations(crypto, machine)))
  return fallbackRec && fallbackRec.fieldValue.value
}
// @flow
const _ = require('lodash/fp');
const {
  getCurrentFilePath,
  isCurrentScopeTypescriptScope,
  isCurrentScopeCssScope,
  isCurrentScopeJsonScope,
  isCurrentScopeGraphQlScope,
  isCurrentScopeMarkdownScope,
} = require('../editorInterface');
const { shouldUseEditorConfig, getPrettierOptions, getAtomTabLength } = require('../atomInterface');
const buildEditorConfigOptions = require('./buildEditorConfigOptions');
const { getPrettierInstance } = require('../helpers');

const isDefined: (x: any) => boolean = _.negate(_.isNil);

const isAppropriateToBuildEditorConfigOptions: (filePath: FilePath) => boolean = _.overEvery([
  isDefined,
  shouldUseEditorConfig,
]);

const buildEditorConfigOptionsIfAppropriate: (editor: TextEditor) => ?{} = _.flow(
  getCurrentFilePath,
  _.cond([[isAppropriateToBuildEditorConfigOptions, buildEditorConfigOptions]]),
);

const getPrettierConfigOptions: (editor: TextEditor) => ?{} = _.cond([
  [
    _.flow(getCurrentFilePath, isDefined),
    editor =>
      isDefined(getPrettierInstance(editor).resolveConfig.sync)
Beispiel #7
0
'use strict';

const {includes, isEmpty, isString, negate} = require('lodash/fp');

const isNotUniqueSelector = includes(',');
const isUniqueSelector = negate(isNotUniqueSelector);

exports.isSelector = isSelector;
exports.isNotUniqueSelector = isNotUniqueSelector;
exports.isUniqueSelector = isUniqueSelector;

function isSelector(selector) {
  if (!isString(selector) || isEmpty(selector)) {
    throw new Error(
      'The valid CSS selector should be non-empty string. ' +
      'Instead got `' + selector + '`'
    );
  }

  return selector;
}