mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
7aef81b984
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49406 ## Motivation Modernising the RN codebase to allow for modern Flow tooling to process it. ## This diff - Migrates Utilities/infoLog, Utilities/logError, Utilities/mapWithSeparator & Utilities/warnOnce to use the export syntax. - Updates deep-imports of these files to use `.default` - Updates the current iteration of API snapshots (intended). Changelog: [General][Breaking] - Deep imports to `Utilities/infoLog`, `Utilities/logError`, `Utilities/mapWithSeparator` or `Utilities/warnOnce` with `require` syntax need to be appended with '.default'. Reviewed By: huntie Differential Revision: D69601174 fbshipit-source-id: 821f9ae59d4f898c95631eb7a9aeed138ace3567
29 lines
719 B
JavaScript
29 lines
719 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
function mapWithSeparator<TFrom, TTo>(
|
|
items: Array<TFrom>,
|
|
itemRenderer: (item: TFrom, index: number, items: Array<TFrom>) => TTo,
|
|
spacerRenderer: (index: number) => TTo,
|
|
): Array<TTo> {
|
|
const mapped = [];
|
|
if (items.length > 0) {
|
|
mapped.push(itemRenderer(items[0], 0, items));
|
|
for (let ii = 1; ii < items.length; ii++) {
|
|
mapped.push(spacerRenderer(ii - 1), itemRenderer(items[ii], ii, items));
|
|
}
|
|
}
|
|
return mapped;
|
|
}
|
|
|
|
export default mapWithSeparator;
|