mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-02 13:51:48 +00:00
First batch of ramda removals
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import type { IContainer } from 'bottlejs';
|
||||
import Bottle from 'bottlejs';
|
||||
import { pick } from 'ramda';
|
||||
import { connect as reduxConnect } from 'react-redux';
|
||||
import { provideServices as provideApiServices } from '../api/services/provideServices';
|
||||
import { provideServices as provideAppServices } from '../app/services/provideServices';
|
||||
@@ -18,14 +17,20 @@ export const { container } = bottle;
|
||||
|
||||
const lazyService = <T extends Function, K>(cont: IContainer, serviceName: string) =>
|
||||
(...args: any[]) => (cont[serviceName] as T)(...args) as K;
|
||||
|
||||
const mapActionService = (map: LazyActionMap, actionName: string): LazyActionMap => ({
|
||||
...map,
|
||||
// Wrap actual action service in a function so that it is lazily created the first time it is called
|
||||
[actionName]: lazyService(container, actionName),
|
||||
});
|
||||
|
||||
const pickProps = (propsToPick: string[]) => (obj: any) => Object.fromEntries(
|
||||
propsToPick.map((key) => [key, obj[key]]),
|
||||
);
|
||||
|
||||
const connect: ConnectDecorator = (propsFromState: string[] | null, actionServiceNames: string[] = []) =>
|
||||
reduxConnect(
|
||||
propsFromState ? pick(propsFromState) : null,
|
||||
propsFromState ? pickProps(propsFromState) : null,
|
||||
actionServiceNames.reduce(mapActionService, {}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user