/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/reader/data/stream/utils.js
33 строки
1 KB
Gabriel Caires
Reader: Finish Reader stream migration to the new stream data layer (#110971)
25 май 2026, 15:06
Не верифицирован
25 май 2026, 15:06
f3b2cdd
Код
Авторство
О чём код?
import { sameXPost } from 'calypso/reader/stream/utils'; /** * Add the post URL from a duplicate x-post to an existing post key * @param {Object} postKey1 First post key * @param {Object} postKey2 Second (duplicate) post key * @returns {Object} Post key */ const addDuplicateXPostToPostKey = ( postKey1, postKey2 ) => { return { ...postKey1, // Add the URL from the second post key xPostUrls: Array.isArray( postKey1.xPostUrls ) ? [ ...postKey1.xPostUrls, postKey2.url ] : [ postKey2.url ], }; }; /** * Combine adjacent x-posts that refer to the same original post * @param {Array} postKeys Array of post key objects * @returns {Array} Array of post key objects */ export const combineXPosts = ( postKeys ) => postKeys.reduce( ( accumulator, postKey ) => { const lastPostKey = accumulator[ accumulator.length - 1 ]; if ( sameXPost( lastPostKey, postKey ) ) { accumulator[ accumulator.length - 1 ] = addDuplicateXPostToPostKey( lastPostKey, postKey ); } else { accumulator.push( postKey ); } return accumulator; }, [] );