2018-12-17 22:03:36 +03:00
|
|
|
import Bottle from 'bottlejs';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
2018-12-18 16:54:54 +03:00
|
|
|
import { connect as reduxConnect } from 'react-redux';
|
2018-12-18 21:59:50 +03:00
|
|
|
import { pick } from 'ramda';
|
2018-12-17 22:03:36 +03:00
|
|
|
import App from '../App';
|
2018-12-18 22:19:22 +03:00
|
|
|
import provideCommonServices from '../common/services/provideServices';
|
2018-12-18 21:59:50 +03:00
|
|
|
import provideShortUrlsServices from '../short-urls/services/provideServices';
|
2018-12-18 21:45:09 +03:00
|
|
|
import provideServersServices from '../servers/services/provideServices';
|
2018-12-18 16:54:54 +03:00
|
|
|
import provideVisitsServices from '../visits/services/provideServices';
|
|
|
|
import provideTagsServices from '../tags/services/provideServices';
|
2018-12-18 22:19:22 +03:00
|
|
|
import provideUtilsServices from '../utils/services/provideServices';
|
2020-04-17 16:51:18 +03:00
|
|
|
import provideMercureServices from '../mercure/services/provideServices';
|
2020-04-25 10:49:54 +03:00
|
|
|
import provideSettingsServices from '../settings/services/provideServices';
|
2018-12-17 22:03:36 +03:00
|
|
|
|
|
|
|
const bottle = new Bottle();
|
2018-12-18 06:34:37 +03:00
|
|
|
const { container } = bottle;
|
|
|
|
|
2019-01-13 01:47:41 +03:00
|
|
|
const lazyService = (container, serviceName) => (...args) => container[serviceName](...args);
|
2018-12-18 12:14:25 +03:00
|
|
|
const mapActionService = (map, actionName) => ({
|
|
|
|
...map,
|
2018-12-18 06:34:37 +03:00
|
|
|
|
2018-12-18 12:14:25 +03:00
|
|
|
// Wrap actual action service in a function so that it is lazily created the first time it is called
|
2019-01-13 01:47:41 +03:00
|
|
|
[actionName]: lazyService(container, actionName),
|
2018-12-18 12:14:25 +03:00
|
|
|
});
|
2020-01-28 21:46:36 +03:00
|
|
|
const connect = (propsFromState, actionServiceNames = []) =>
|
2018-12-18 16:54:54 +03:00
|
|
|
reduxConnect(
|
2018-12-18 21:45:09 +03:00
|
|
|
propsFromState ? pick(propsFromState) : null,
|
2020-08-22 09:10:31 +03:00
|
|
|
actionServiceNames.reduce(mapActionService, {}),
|
2018-12-18 06:34:37 +03:00
|
|
|
);
|
2018-12-17 22:03:36 +03:00
|
|
|
|
2020-04-25 10:49:54 +03:00
|
|
|
bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer', 'EditServer', 'Settings');
|
2020-04-27 13:54:52 +03:00
|
|
|
bottle.decorator('App', connect([ 'servers' ], [ 'fetchServers' ]));
|
2018-12-18 21:45:09 +03:00
|
|
|
|
2018-12-18 22:19:22 +03:00
|
|
|
provideCommonServices(bottle, connect, withRouter);
|
2018-12-18 21:59:50 +03:00
|
|
|
provideShortUrlsServices(bottle, connect);
|
2018-12-18 21:45:09 +03:00
|
|
|
provideServersServices(bottle, connect, withRouter);
|
2018-12-18 16:54:54 +03:00
|
|
|
provideTagsServices(bottle, connect);
|
|
|
|
provideVisitsServices(bottle, connect);
|
2018-12-18 22:19:22 +03:00
|
|
|
provideUtilsServices(bottle);
|
2020-04-17 16:51:18 +03:00
|
|
|
provideMercureServices(bottle);
|
2020-04-25 10:49:54 +03:00
|
|
|
provideSettingsServices(bottle, connect);
|
2018-12-18 16:32:02 +03:00
|
|
|
|
2018-12-18 06:34:37 +03:00
|
|
|
export default container;
|