Skip to content

Commit

Permalink
Gutenboarding: Add wp-data to window (#36985)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal authored Oct 24, 2019
1 parent ea7478c commit 18ec5d5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
20 changes: 20 additions & 0 deletions client/gutenboarding/devtools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
interface MagicWindow extends Window {
wp: undefined | Record< string, any >;
}

// Don't complain about window.wp.data types in our debug function
declare const window: undefined | MagicWindow;

export const wpDataDebugMiddleware: PageJS.Callback = ( context, next ) => {
if ( process.env.NODE_ENV !== 'production' ) {
if ( typeof window === 'object' ) {
if ( ! window.wp ) {
window.wp = {};
}
if ( ! window.wp.data ) {
window.wp.data = require( '@wordpress/data' );
}
}
}
next();
};
11 changes: 10 additions & 1 deletion client/gutenboarding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ import page from 'page';
*/
import { hideMasterbar, main, redirectIfNotEnabled } from './controller';
import { makeLayout, render as clientRender } from 'controller';
import { wpDataDebugMiddleware } from './devtools';

export default function() {
page( '/gutenboarding', redirectIfNotEnabled, hideMasterbar, main, makeLayout, clientRender );
page(
'/gutenboarding',
redirectIfNotEnabled,
wpDataDebugMiddleware,
hideMasterbar,
main,
makeLayout,
clientRender
);
}

0 comments on commit 18ec5d5

Please sign in to comment.