-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Labels
FrameworkIssues related to broader framework topics, especially as it relates to javascriptIssues related to broader framework topics, especially as it relates to javascript[Feature] ExtensibilityThe ability to extend blocks or the editing experienceThe ability to extend blocks or the editing experience[Type] QuestionQuestions about the design or development of the editor.Questions about the design or development of the editor.
Description
Related: #594
In #594, when a post draft finishes saving, we adjust the current browser URL to reflect the new post ID. While this is necessary in the context of the dedicated editor screen, this reduces the portability of the editor as these URL changes are not applicable outside this context. If we'd want to allow initializing an editor on other screens (e.g. front-end, Customizer), we might need to explore options for injecting context-specific middlewares. This could serve as a generic extensibility pattern for any side effects of state changes.
For the post save navigation example, this could look something like:
wp.editor.injectMiddleware( ( store ) => ( next ) => ( action ) => {
const { type, isNew, post } = action;
if ( 'REQUEST_POST_UPDATE_SUCCESS' === type ) {
const [ baseUrl, query ] = window.location.href.split( '?' );
const qs = parse( query || '' );
const newUrl = baseUrl + '?' + stringify( {
...qs,
post_id: newPost.id,
} );
window.history.replaceState( {}, 'Post ' + newPost.id, newUrl );
}
return next( action );
} );See also:
gziolo
Metadata
Metadata
Assignees
Labels
FrameworkIssues related to broader framework topics, especially as it relates to javascriptIssues related to broader framework topics, especially as it relates to javascript[Feature] ExtensibilityThe ability to extend blocks or the editing experienceThe ability to extend blocks or the editing experience[Type] QuestionQuestions about the design or development of the editor.Questions about the design or development of the editor.