Beispiel #1
0
function extractBlocks(src: string): TestBlock[] {
  let blocks: Array<TestBlock | null> = []
  let matchBlock: any
  while (matchBlock = balanced('{', '}', src)) {
    blocks.push(extractBlock(matchBlock.pre, matchBlock.body))
    src = matchBlock.post
  }
  let droppedNulls: TestBlock[] = _.compact(blocks)
  return droppedNulls
}
 prompt(function postPrompt(result) {
   var tasks = [
     function writeConfig(cb) {
       configFile.writeConfig('.all-contributorsrc', result.config, cb);
     },
     function addContributorsList(cb) {
       injectInFile(result.contributorFile, initContent.addContributorsList, cb);
     },
     result.badgeFile && function addBadge(cb) {
       injectInFile(result.badgeFile, initContent.addBadge, cb);
     }
   ];
   series(_.compact(tasks), callback);
 });
Beispiel #3
0
  const { spanningElements } = reduce(({ index, spanningElements }, { start, end, type }) => {
    const preKey = `pre-${start}`;
    const key = `${start}-${end}`;

    const newSpanningElements = compact([
      start !== index
        ? <SpanningElement key={preKey}>{text.substring(index, start)}</SpanningElement>
        : null,
      <SpanningElement key={key} type={type}>{text.substring(start, end)}</SpanningElement>,
    ]);

    return {
      index: end,
      spanningElements: spanningElements.concat(newSpanningElements),
    };
  }, {
Beispiel #4
0
 comments: payload => compact(map('comment', payload.items))
  const updateStore = async (storageOperations: StorageOperation[], state) => {
    const documentsToSave = filter({ action: STORAGE_ACTION_SAVE }, storageOperations);
    const documentsToRemove = filter({ action: STORAGE_ACTION_REMOVE }, storageOperations);

    const now = Date.now();
    const storageLocations = map(storageOperation => {
      const storageKey =
        get(['storageLocation', 'storageKey'], storageOperation) || generateStorageKey();

      return {
        id: storageKey,
        accountId: storageOperation.account.id,
        storageKey,
        title: storageOperation.document.title,
        lastModified: now,
      };
    }, documentsToSave);

    const saveOperations = flow(
      zip(storageLocations),
      map(([storageLocation, storageOperation]) => [
        storageLocation.storageKey,
        JSON.stringify(storageOperation.document),
      ])
    )(documentsToSave);

    const removeOperations = flow(
      map('storageLocation'),
      map('storageKey')
    )(documentsToRemove);

    // Update saved list of documents
    const previousStorageLocation = documentId =>
      get(['documentStorageLocations', documentId], state);

    const newStorageLocationsByDocumentId =
      fromPairs(zip(map('document.id', documentsToSave), storageLocations));

    const documentsByAccountId = groupBy(flow(
      previousStorageLocation,
      get('accountId')
    ), state.documents);

    const accountsToUpdate = flow(
      map('accountId'),
      uniq
    )(storageLocations);

    const newStorageLocationsForAccountsToUpdate = map(flow(
      propertyOf(documentsByAccountId),
      map(docId => newStorageLocationsByDocumentId[docId] || previousStorageLocation(docId))
    ), accountsToUpdate);

    const storageLocationOperations = flow(
      map(value => JSON.stringify(map(omit(['accountId']), value))),
      zip(accountsToUpdate)
    )(newStorageLocationsForAccountsToUpdate);

    await Promise.all(compact([
      !isEmpty(removeOperations) ? storage.multiRemove(removeOperations) : null,
      storage.multiSet(concat(saveOperations, storageLocationOperations)),
    ]));

    return storageLocations;
  };