Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions packages/data/src/plugins/persistence/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { merge, isPlainObject, omit } from 'lodash';
import { merge, isPlainObject, get } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -72,7 +72,7 @@ export function createPersistenceInterface( options ) {
*
* @return {Object} Persisted data.
*/
function get() {
function getData() {
if ( data === undefined ) {
// If unset, getItem is expected to return null. Fall back to
// empty object.
Expand All @@ -99,12 +99,15 @@ export function createPersistenceInterface( options ) {
* @param {string} key Key to update.
* @param {*} value Updated value.
*/
function set( key, value ) {
function setData( key, value ) {
data = { ...data, [ key ]: value };
storage.setItem( storageKey, JSON.stringify( data ) );
}

return { get, set };
return {
get: getData,
set: setData,
};
}

/**
Expand Down Expand Up @@ -209,20 +212,18 @@ persistencePlugin.__unstableMigrate = ( pluginOptions ) => {
const persistence = createPersistenceInterface( pluginOptions );

// Preferences migration to introduce the block editor module
const persistedState = persistence.get();
const coreEditorState = persistedState[ 'core/editor' ];
if ( coreEditorState && coreEditorState.preferences && coreEditorState.preferences.insertUsage ) {
const blockEditorState = {
const insertUsage = get( persistence.get(), [
'core/editor',
'preferences',
'insertUsage',
] );

if ( insertUsage ) {
persistence.set( 'core/block-editor', {
preferences: {
insertUsage: coreEditorState.preferences.insertUsage,
insertUsage,
},
};

persistence.set( 'core/editor', {
...coreEditorState,
preferences: omit( coreEditorState.preferences, [ 'insertUsage' ] ),
} );
persistence.set( 'core/block-editor', blockEditorState );
}
};

Expand Down