-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
36 lines (30 loc) · 879 Bytes
/
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
/**
* External dependencies
*/
import { applyMiddleware } from 'redux';
import { mapValues } from 'lodash';
/**
* WordPress dependencies
*/
import createMiddleware from '@wordpress/redux-routine';
export default function( registry ) {
return {
registerStore( reducerKey, options ) {
const store = registry.registerStore( reducerKey, options );
if ( options.controls ) {
const normalizedControls = mapValues( options.controls, ( control ) => {
return control.isRegistryControl ? control( registry ) : control;
} );
const middleware = createMiddleware( normalizedControls );
const enhancer = applyMiddleware( middleware );
const createStore = () => store;
Object.assign(
store,
enhancer( createStore )( options.reducer )
);
registry.namespaces[ reducerKey ].supportControls = true;
}
return store;
},
};
}