本文整理汇总了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.'
}
])
)
);
};
示例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))
}
}
示例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 }));
}
};
示例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
);
}
示例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." }])
));
}
示例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.' }
])
)
);
};
示例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) => {