Lazy decoration (part 8, consistent call order) (#4153)

* Lazy decoration (part 8, consistent call order)

* Dedupe

* Flatten, no extra calls

* Dedupe more

* Adjust lazyVariants

* Additional flatten

* Adjust lazyVariants

* Reorder name/index

* Deupe strings

* Flatten createkeys

* Adjust
This commit is contained in:
Jaco
2021-11-03 10:47:04 +02:00
committed by GitHub
parent 5b0652c272
commit f5f67e795e
14 changed files with 192 additions and 223 deletions
+4 -4
View File
@@ -97,11 +97,11 @@ function injectFunctions (instanceId: string, api: ApiInterfaceRx, derives: Deri
)
);
const getKeys = (s: string) =>
Object.keys(derives[s]);
const getKeys = (section: string) =>
Object.keys(derives[section]);
const creator = (s: string, m: string) =>
derives[s][m](instanceId, api);
const creator = (section: string, method: string) =>
derives[section][method](instanceId, api);
const result: Record<string, Record<string, AnyFunction>> = {};
const names = Object.keys(derives);
+5 -1
View File
@@ -8,5 +8,9 @@ type LazySection <T> = Record<string, T>;
type LazyRecord <T> = Record<string, LazySection<T>>;
export function lazyDeriveSection <T> (result: LazyRecord<T>, section: string, getKeys: (s: string) => string[], creator: (s: string, m: string) => T): void {
lazyMethod(result, section, (s) => lazyMethods(getKeys(s), (m) => creator(s, m)));
lazyMethod(result, section, () =>
lazyMethods({}, getKeys(section), (method: string) =>
creator(section, method)
)
);
}