-
Notifications
You must be signed in to change notification settings - Fork 44
/
mixin.runtime-common.js
47 lines (39 loc) · 1.06 KB
/
mixin.runtime-common.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
import { createElement } from 'react';
import { Provider } from 'react-redux';
import { applyMiddleware } from 'redux';
import ReduxThunkMiddleware from 'redux-thunk';
import { Mixin, strategies } from 'hops-mixin';
const {
sync: { override },
} = strategies;
class ReduxRuntimeCommonMixin extends Mixin {
constructor(config, element, { redux: options = {} } = {}) {
super(config);
this.middlewares = options.middlewares || [];
this.reducers = options.reducers || {};
}
getReduxMiddlewares() {
return [
...this.middlewares,
ReduxThunkMiddleware.withExtraArgument({
config: this.config,
}),
];
}
applyMiddlewares() {
const middlewares = this.getReduxMiddlewares();
return middlewares.map((m) => applyMiddleware(m));
}
enhanceElement(reactElement) {
return createElement(
Provider,
{ store: this.getReduxStore() },
reactElement
);
}
}
ReduxRuntimeCommonMixin.strategies = {
getReduxMiddlewares: override,
getReduxStore: override,
};
export default ReduxRuntimeCommonMixin;