First batch of ramda removals

This commit is contained in:
Alejandro Celaya
2023-11-01 10:03:09 +01:00
parent 98b2db99b3
commit 8699eaca32
8 changed files with 39 additions and 34 deletions

View File

@@ -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, {}),
);