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-18 00:18:47 +03:00
|
|
|
import axios from 'axios';
|
2018-12-17 22:03:36 +03:00
|
|
|
import App from '../App';
|
|
|
|
import ScrollToTop from '../common/ScrollToTop';
|
|
|
|
import MainHeader from '../common/MainHeader';
|
|
|
|
import Home from '../common/Home';
|
2018-12-17 22:24:31 +03:00
|
|
|
import MenuLayout from '../common/MenuLayout';
|
2018-12-18 00:18:47 +03:00
|
|
|
import AsideMenu from '../common/AsideMenu';
|
2018-12-18 21:59:50 +03:00
|
|
|
import ColorGenerator from '../utils/ColorGenerator';
|
|
|
|
import Storage from '../utils/Storage';
|
2018-12-18 12:14:25 +03:00
|
|
|
import buildShlinkApiClient from '../api/ShlinkApiClientBuilder';
|
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-17 22:03:36 +03:00
|
|
|
|
|
|
|
const bottle = new Bottle();
|
2018-12-18 06:34:37 +03:00
|
|
|
const { container } = bottle;
|
|
|
|
|
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
|
|
|
|
[actionName]: (...args) => container[actionName](...args),
|
|
|
|
});
|
2018-12-18 16:54:54 +03:00
|
|
|
const connect = (propsFromState, actionServiceNames) =>
|
|
|
|
reduxConnect(
|
2018-12-18 21:45:09 +03:00
|
|
|
propsFromState ? pick(propsFromState) : null,
|
2018-12-18 06:34:37 +03:00
|
|
|
Array.isArray(actionServiceNames) ? actionServiceNames.reduce(mapActionService, {}) : actionServiceNames
|
|
|
|
);
|
2018-12-17 22:03:36 +03:00
|
|
|
|
2018-12-18 00:18:47 +03:00
|
|
|
bottle.constant('ScrollToTop', ScrollToTop);
|
|
|
|
bottle.decorator('ScrollToTop', withRouter);
|
|
|
|
|
2018-12-18 21:45:09 +03:00
|
|
|
bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer');
|
|
|
|
|
2018-12-18 00:18:47 +03:00
|
|
|
bottle.serviceFactory('MainHeader', MainHeader, 'ServersDropdown');
|
|
|
|
bottle.decorator('MainHeader', withRouter);
|
|
|
|
|
|
|
|
bottle.serviceFactory('Home', () => Home);
|
2018-12-18 21:59:50 +03:00
|
|
|
bottle.decorator('Home', connect([ 'servers' ], [ 'resetSelectedServer' ]));
|
2018-12-18 00:18:47 +03:00
|
|
|
|
2018-12-18 16:32:02 +03:00
|
|
|
bottle.serviceFactory(
|
|
|
|
'MenuLayout',
|
|
|
|
MenuLayout,
|
|
|
|
'TagsList',
|
|
|
|
'ShortUrls',
|
|
|
|
'AsideMenu',
|
|
|
|
'CreateShortUrl',
|
|
|
|
'ShortUrlVisits'
|
|
|
|
);
|
2018-12-18 21:45:09 +03:00
|
|
|
bottle.decorator('MenuLayout', connect([ 'selectedServer', 'shortUrlsListParams' ], [ 'selectServer' ]));
|
2018-12-18 06:34:37 +03:00
|
|
|
bottle.decorator('MenuLayout', withRouter);
|
2018-12-18 00:18:47 +03:00
|
|
|
|
2018-12-18 21:45:09 +03:00
|
|
|
bottle.serviceFactory('AsideMenu', AsideMenu, 'DeleteServerButton');
|
2018-12-18 00:18:47 +03:00
|
|
|
|
2018-12-18 21:45:09 +03:00
|
|
|
bottle.constant('localStorage', global.localStorage);
|
|
|
|
bottle.service('Storage', Storage, 'localStorage');
|
|
|
|
bottle.service('ColorGenerator', ColorGenerator, 'Storage');
|
2018-12-17 22:03:36 +03:00
|
|
|
|
2018-12-18 21:45:09 +03:00
|
|
|
bottle.constant('axios', axios);
|
|
|
|
bottle.serviceFactory('buildShlinkApiClient', buildShlinkApiClient, 'axios');
|
2018-12-18 00:18:47 +03:00
|
|
|
|
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 16:32:02 +03:00
|
|
|
|
2018-12-18 06:34:37 +03:00
|
|
|
export default container;
|