-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
47 lines (40 loc) · 1.01 KB
/
index.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* WordPress Dependencies
*/
import {
registerStore,
withRehydratation,
loadAndPersist,
subscribe,
dispatch,
select,
} from '@wordpress/data';
/**
* Internal dependencies
*/
import reducer from './reducer';
import applyMiddlewares from './middlewares';
import * as actions from './actions';
import * as selectors from './selectors';
/**
* Module Constants
*/
const STORAGE_KEY = `WP_EDIT_POST_PREFERENCES_${ window.userSettings.uid }`;
const store = registerStore( 'core/edit-post', {
reducer: withRehydratation( reducer, 'preferences', STORAGE_KEY ),
actions,
selectors,
} );
applyMiddlewares( store );
loadAndPersist( store, reducer, 'preferences', STORAGE_KEY );
let lastIsSmall;
subscribe( () => {
const isSmall = select( 'core/viewport' ).isViewportMatch( '< medium' );
const hasViewportShrunk = isSmall && ! lastIsSmall;
lastIsSmall = isSmall;
// Collapse sidebar when viewport shrinks.
if ( hasViewportShrunk ) {
dispatch( 'core/edit-post' ).closeGeneralSidebar();
}
} );
export default store;