• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript bluebird.reduce函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中bluebird.reduce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript reduce函数的具体用法?TypeScript reduce怎么用?TypeScript reduce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了reduce函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: dispatch

export const addTagsToEntities: ImportGroupsAsTagsThunk = () => (
  dispatch,
  getState
) => {
  dispatch(handleUpdate());
  const entities = getEntitiesWithGroupsToImport(getState());

  const linodeAccumulator = createAccumulator<Linode.Linode>(
    'linode',
    dispatch
  );
  const domainAccumulator = createAccumulator<Linode.Domain>(
    'domain',
    dispatch
  );

  Bluebird.join(
    Bluebird.reduce(entities.linodes, linodeAccumulator, {
      success: [],
      errors: []
    }),
    Bluebird.reduce(entities.domains, domainAccumulator, {
      success: [],
      errors: []
    }),
    dispatch,
    handleAccumulatedResponsesAndErrors
  )
    .then((totalErrors: TagError[]) => {
      if (isEmpty(totalErrors)) {
        storage.hasImportedGroups.set();
      }
    })
    .catch(() =>
      dispatch(
        // Errors from individual requests will be accumulated and passed to .then(); hitting
        // this block indicates something went wrong with .reduce() or .join().
        // It's unclear under what circumstances this could ever actually fire.
        handleError([
          {
            entityId: 0,
            reason: 'There was an error importing your display groups.'
          }
        ])
      )
    );
};
开发者ID:linode,项目名称:manager,代码行数:47,代码来源:index.ts


示例2: collectSectionDirs

    /**
     * Read contentsDir to collect sectionDirs
     * @param {string[]} chapterDirs
     * @returns {string[]} sectionDirs
     */
    function collectSectionDirs(chapterDirs: string[]) {
        return Promise.reduce(chapterDirs, concatSectionDirs, [])

        ///// hoisted functions

        function concatSectionDirs(prev: string[], chapterDir: string) {
            let joinChapterDir = utils.join(chapterDir);
            let isMatchedSection = utils.isMatched(config.FILE_PATTERNS.SECTION);
            return fsp.readdirAsync(chapterDir)
                .map(joinChapterDir)
                .filter(isMatchedSection)
                .then(sectionDirs => prev.concat(sectionDirs))
        }
    }
开发者ID:TonyPythoneer,项目名称:node-cookbook,代码行数:19,代码来源:index.ts


示例3: async

export const getAllNodeBalancersWithConfigs: ThunkActionCreator<Promise<void>> = () => async (dispatch) => {
  const { started, done, failed } = getAllNodeBalancersActions;
  dispatch(started());

  try {
    const { data: nodeBalancers } = await getAllNodeBalancersRequest();

    const nodeBalancerConfigs = await Bluebird.reduce(
      nodeBalancers,
      async (result: NodeBalancerConfig[], nodeBalancer) => {
        const { data: configs } = await getAll<NodeBalancerConfig>(() => _getNodeBalancerConfigs(nodeBalancer.id))();
        return [...result, ...configs];
      },
      []);

      dispatch(addNodeBalancerConfigs(nodeBalancerConfigs));
    dispatch(done({ result: nodeBalancers }));
  } catch (error) {
    dispatch(failed({ error }));
  }
};
开发者ID:displague,项目名称:manager,代码行数:21,代码来源:nodeBalancer.requests.ts


示例4: playNotes

export function playNotes(
  notes: Note[],
  delay: number = getRandomNoteDelay(),
  shouldAbort?: () => boolean,
  volume?: number
): Promise<number> {
  return Promiz.reduce(
    notes,
    (notesPlayedCount: number, note: Note, index: number) => {
      if (shouldAbort && shouldAbort()) {
        return notesPlayedCount;
      } else {
        playNote(note, volume);
        return index === notes.length - 1
          ? notesPlayedCount + 1 // do not delay after playing the final note
          : Promiz.delay(delay).then((): number => notesPlayedCount + 1);
      }
    },
    0
  );
}
开发者ID:agaricus,项目名称:ear-sharpener,代码行数:21,代码来源:index.ts


示例5: getState

export const enableAllBackups: EnableAllBackupsThunk = () => (dispatch, getState) => {
  const { entities } = getState().__resources.linodes;

  const linodesWithoutBackups = entities
    .filter(linode => !linode.backups.enabled)

  dispatch(handleEnable());
  Bluebird.reduce(linodesWithoutBackups, gatherResponsesAndErrors, { success: [], errors: [] })
    .then(response => {
      if (response.errors && !isEmpty(response.errors)) {
        dispatch(handleEnableError(response));
      }
      else {
        dispatch(handleEnableSuccess(response.success));
      }
      dispatch(updateMultipleLinodes(response.success));
    })
    .catch(() => dispatch(
      handleEnableError([{ linodeId: 0, reason: "There was an error enabling backups." }])
    ));
}
开发者ID:displague,项目名称:manager,代码行数:21,代码来源:index.ts


示例6: getState

export const enableAllBackups: EnableAllBackupsThunk = () => (
  dispatch,
  getState
) => {
  const { entities } = getState().__resources.linodes;

  const linodesWithoutBackups = entities.filter(
    linode => !linode.backups.enabled
  );

  dispatch(handleEnable());
  Bluebird.reduce(linodesWithoutBackups, gatherResponsesAndErrors, {
    success: [],
    errors: []
  })
    .then(response => {
      if (response.errors && !isEmpty(response.errors)) {
        dispatch(handleEnableError(response));
      } else {
        dispatch(handleEnableSuccess(response.success));
      }
      dispatch(updateMultipleLinodes(response.success));
      // GA Event
      sendEvent({
        category: 'Backups',
        action: 'Enable All Backups',
        label: `Enabled backups for ${response.success.length} Linodes`
      });
    })
    .catch(() =>
      dispatch(
        handleEnableError([
          { linodeId: 0, reason: 'There was an error enabling backups.' }
        ])
      )
    );
};
开发者ID:linode,项目名称:manager,代码行数:37,代码来源:index.ts


示例7:

	concurrency: 1
});

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

barArrProm = fooArrProm.mapSeries((item: Foo, index: number, arrayLength: number) => {
	return bar;
});
barArrProm = fooArrProm.mapSeries((item: Foo) => {
	return bar;
});

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

barProm = fooArrProm.reduce((memo: Bar, item: Foo, index: number, arrayLength: number) => {
	return memo;
});
barProm = fooArrProm.reduce((memo: Bar, item: Foo) => {
	return memo;
}, bar);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

fooArrProm = fooArrProm.filter((item: Foo, index: number, arrayLength: number) => {
	return bool;
});
fooArrProm = fooArrProm.filter((item: Foo) => {
	return bool;
});

fooArrProm = fooArrProm.filter((item: Foo, index: number, arrayLength: number) => {
开发者ID:csrakowski,项目名称:DefinitelyTyped,代码行数:31,代码来源:bluebird-tests.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript bluebird.reject函数代码示例发布时间:2022-05-25
下一篇:
TypeScript bluebird.props函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap