Skip to content

Commit

Permalink
Avoid separate buffer key in history reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 9, 2018
1 parent bbb2fb1 commit a27fbd8
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 186 deletions.
41 changes: 20 additions & 21 deletions editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function getCurrentPostLastRevisionId( state ) {
* @return {Object} Object of key value pairs comprising unsaved edits.
*/
export function getPostEdits( state ) {
return get( state, [ 'editor', 'buffer', 'edits' ], {} );
return get( state, [ 'editor', 'present', 'edits' ], {} );
}

/**
Expand Down Expand Up @@ -368,10 +368,9 @@ export function getDocumentTitle( state ) {
* @return {string} Raw post excerpt.
*/
export function getEditedPostExcerpt( state ) {
const edits = getPostEdits( state );
return edits.excerpt === undefined ?
return state.editor.present.edits.excerpt === undefined ?
state.currentPost.excerpt :
edits.excerpt;
state.editor.present.edits.excerpt;
}

/**
Expand Down Expand Up @@ -403,7 +402,7 @@ export function getEditedPostPreviewLink( state ) {
*/
export const getBlock = createSelector(
( state, uid ) => {
const block = state.editor.buffer.blocksByUid[ uid ];
const block = state.editor.present.blocksByUid[ uid ];
if ( ! block ) {
return null;
}
Expand Down Expand Up @@ -436,15 +435,15 @@ export const getBlock = createSelector(
};
},
( state ) => [
get( state, [ 'editor', 'buffer', 'blocksByUid' ] ),
get( state, [ 'editor', 'buffer', 'edits', 'meta' ] ),
get( state, [ 'editor', 'present', 'blocksByUid' ] ),
get( state, [ 'editor', 'present', 'edits', 'meta' ] ),
get( state, 'currentPost.meta' ),
]
);

function getPostMeta( state, key ) {
return has( state, [ 'editor', 'buffer', 'edits', 'meta', key ] ) ?
get( state, [ 'editor', 'buffer', 'edits', 'meta', key ] ) :
return has( state, [ 'editor', 'present', 'edits', 'meta', key ] ) ?
get( state, [ 'editor', 'present', 'edits', 'meta', key ] ) :
get( state, [ 'currentPost', 'meta', key ] );
}

Expand All @@ -466,8 +465,8 @@ export const getBlocks = createSelector(
);
},
( state ) => [
state.editor.buffer.blockOrder,
state.editor.buffer.blocksByUid,
state.editor.present.blockOrder,
state.editor.present.blocksByUid,
]
);

Expand Down Expand Up @@ -526,7 +525,7 @@ export function getSelectedBlock( state ) {
* @return {?string} Root UID, if exists
*/
export function getBlockRootUID( state, uid ) {
const { blockOrder } = state.editor.buffer;
const { blockOrder } = state.editor.present;

for ( const rootUID in blockOrder ) {
if ( includes( blockOrder[ rootUID ], uid ) ) {
Expand Down Expand Up @@ -575,7 +574,7 @@ export function getAdjacentBlock( state, startUID, modifier = 1 ) {
return null;
}

const { blockOrder } = state.editor.buffer;
const { blockOrder } = state.editor.present;
const orderSet = blockOrder[ rootUID ];
const index = orderSet.indexOf( startUID );
const nextIndex = ( index + ( 1 * modifier ) );
Expand Down Expand Up @@ -671,7 +670,7 @@ export const getMultiSelectedBlockUids = createSelector(
return blockOrder.slice( startIndex, endIndex + 1 );
},
( state ) => [
state.editor.buffer.blockOrder,
state.editor.present.blockOrder,
state.blockSelection.start,
state.blockSelection.end,
],
Expand All @@ -688,11 +687,11 @@ export const getMultiSelectedBlockUids = createSelector(
export const getMultiSelectedBlocks = createSelector(
( state ) => getMultiSelectedBlockUids( state ).map( ( uid ) => getBlock( state, uid ) ),
( state ) => [
state.editor.buffer.blockOrder,
state.editor.present.blockOrder,
state.blockSelection.start,
state.blockSelection.end,
state.editor.buffer.blocksByUid,
state.editor.buffer.edits.meta,
state.editor.present.blocksByUid,
state.editor.present.edits.meta,
state.currentPost.meta,
]
);
Expand Down Expand Up @@ -798,7 +797,7 @@ export function getMultiSelectedBlocksEndUid( state ) {
* @return {Array} Ordered unique IDs of post blocks.
*/
export function getBlockOrder( state, rootUID ) {
return state.editor.buffer.blockOrder[ rootUID || '' ] || DEFAULT_BLOCK_ORDER;
return state.editor.present.blockOrder[ rootUID || '' ] || DEFAULT_BLOCK_ORDER;
}

/**
Expand Down Expand Up @@ -1050,9 +1049,9 @@ export const getEditedPostContent = createSelector(
return serialize( getBlocks( state ) );
},
( state ) => [
state.editor.buffer.edits.content,
state.editor.buffer.blocksByUid,
state.editor.buffer.blockOrder,
state.editor.present.edits.content,
state.editor.present.blocksByUid,
state.editor.present.blockOrder,
],
);

Expand Down
Loading

0 comments on commit a27fbd8

Please sign in to comment.