/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/preferences-persistence/src/index.js
47 строк
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import create from './create'; import convertLegacyLocalStorageData from './migrations/legacy-local-storage-data'; import convertPreferencesPackageData from './migrations/preferences-package-data'; export { create }; /** * Creates the persistence layer with preloaded data. * * It prioritizes any data from the server, but falls back first to localStorage * restore data, and then to any legacy data. * * This function is used internally by WordPress in an inline script, so * prefixed with `__unstable`. * * @param {Object} serverData Preferences data preloaded from the server. * @param {string} userId The user id. * * @return {Object} The persistence layer initialized with the preloaded data. */ export function __unstableCreatePersistenceLayer( serverData, userId ) { const localStorageRestoreKey = `WP_PREFERENCES_USER_${ userId }`; const localData = JSON.parse( window.localStorage.getItem( localStorageRestoreKey ) ); // Date parse returns NaN for invalid input. Coerce anything invalid // into a conveniently comparable zero. const serverModified = Date.parse( serverData && serverData._modified ) || 0; const localModified = Date.parse( localData && localData._modified ) || 0; let preloadedData; if ( serverData && serverModified >= localModified ) { preloadedData = convertPreferencesPackageData( serverData ); } else if ( localData ) { preloadedData = convertPreferencesPackageData( localData ); } else { // Check if there is data in the legacy format from the old persistence system. preloadedData = convertLegacyLocalStorageData( userId ); } return create( { preloadedData, localStorageRestoreKey, } ); }