Skip to content

Commit

Permalink
Store: Avoid Lodash get for getPostEdits (#7381)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth authored Jun 20, 2018
1 parent c6cbfb0 commit 657c368
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function getCurrentPostLastRevisionId( state ) {
* @return {Object} Object of key value pairs comprising unsaved edits.
*/
export function getPostEdits( state ) {
return get( state, [ 'editor', 'present', 'edits' ], {} );
return state.editor.present.edits;
}

/**
Expand Down
45 changes: 45 additions & 0 deletions editor/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ describe( 'selectors', () => {
it( 'should return the current post\'s slug if no edits have been made', () => {
const state = {
currentPost: { slug: 'post slug' },
editor: {
present: {
edits: {},
},
},
};

expect( getEditedPostAttribute( state, 'slug' ) ).toBe( 'post slug' );
Expand Down Expand Up @@ -3583,6 +3588,11 @@ describe( 'selectors', () => {
it( 'should be false if there is no permalink', () => {
const state = {
currentPost: { permalink_template: '' },
editor: {
present: {
edits: {},
},
},
};

expect( isPermalinkEditable( state ) ).toBe( false );
Expand All @@ -3591,6 +3601,11 @@ describe( 'selectors', () => {
it( 'should be false if the permalink is not of an editable kind', () => {
const state = {
currentPost: { permalink_template: 'http://foo.test/bar/%baz%/' },
editor: {
present: {
edits: {},
},
},
};

expect( isPermalinkEditable( state ) ).toBe( false );
Expand All @@ -3599,6 +3614,11 @@ describe( 'selectors', () => {
it( 'should be true if the permalink has %postname%', () => {
const state = {
currentPost: { permalink_template: 'http://foo.test/bar/%postname%/' },
editor: {
present: {
edits: {},
},
},
};

expect( isPermalinkEditable( state ) ).toBe( true );
Expand All @@ -3607,6 +3627,11 @@ describe( 'selectors', () => {
it( 'should be true if the permalink has %pagename%', () => {
const state = {
currentPost: { permalink_template: 'http://foo.test/bar/%pagename%/' },
editor: {
present: {
edits: {},
},
},
};

expect( isPermalinkEditable( state ) ).toBe( true );
Expand All @@ -3618,6 +3643,11 @@ describe( 'selectors', () => {
const url = 'http://foo.test/?post=1';
const state = {
currentPost: { permalink_template: url },
editor: {
present: {
edits: {},
},
},
};

expect( getPermalink( state ) ).toBe( url );
Expand All @@ -3629,6 +3659,11 @@ describe( 'selectors', () => {
permalink_template: 'http://foo.test/bar/%postname%/',
slug: 'baz',
},
editor: {
present: {
edits: {},
},
},
};

expect( getPermalink( state ) ).toBe( 'http://foo.test/bar/baz/' );
Expand All @@ -3647,6 +3682,11 @@ describe( 'selectors', () => {
permalink_template: 'http://foo.test/bar/%postname%/',
slug: 'baz',
},
editor: {
present: {
edits: {},
},
},
};

expect( getPermalinkParts( state ) ).toEqual( parts );
Expand All @@ -3662,6 +3702,11 @@ describe( 'selectors', () => {
permalink_template: 'http://foo.test/?post=1',
slug: 'baz',
},
editor: {
present: {
edits: {},
},
},
};

expect( getPermalinkParts( state ) ).toEqual( parts );
Expand Down

0 comments on commit 657c368

Please sign in to comment.