File size: 798 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
 * Console dispatcher Redux store enhancer
 *
 * Inject at the top of the `createStore` enhancer chain
 * to provide access to actionTypes and store methods directly
 * from the console.
 *
 * Will only attach if the `window` variable is available
 * globally. If not it will simply be an empty link in the
 * chain, passing straight through.
 * @param {Function} next next store enhancer in chain
 * @returns {Function} console dispatcher store enhancer
 */
export const consoleDispatcher =
	( next ) =>
	( ...args ) => {
		const store = next( ...args );

		if ( 'undefined' !== typeof window ) {
			Object.assign( window, store );

			Object.defineProperty( window, 'state', {
				enumerable: true,
				get: store.getState,
			} );
		}

		return store;
	};

export default consoleDispatcher;