mrWh1te / Botmation

A simple TypeScript framework for declaratively composing bots with Puppeteer
https://botmation.dev
MIT License
18 stars 2 forks source link

injectMap()() #58

Open mrWh1te opened 4 years ago

mrWh1te commented 4 years ago

This sets the first inject with a hash-map of injectables for assembled BotAction's

This can be helpful if you have advanced injecting needs, as a way to distinguish injectables by key.

Goal is to resolve deep nesting of higher-order injectors, because then the functions assembled within, have an imposed injects order (inner array typing) that couples the functions to a particular injects structure, it gets worse the deeper nested you go. So if you need to make a major injector change, like in React, adding new Provider Context component, it can impose large amounts of required dev work to update other functions with new injects order, unless you just add it to the end, over and over again, which then imposes structure on itself in how injectors are assembled in the Bot.

By advancing injects with keys, slight more control can be gained to de-couple some of the imposed order.

Purely concept, the goal is more important

It would be nice to be able to use this over and over again, in a nesting way, that continues to enrich that same 1st injected hash-map with new injectables. Or would it be nice to collect injectables in various hash-maps injected as new injects, as nesting occurs? Maybe on assembly customizable?

Key collisions could override?

mrWh1te commented 4 years ago

another approach could be to extend inject()() with 1 other param like orderNumber, injectsIndex, to dynamically set the injects order of assembled BotAction's, but how would that "state" be passed down when overridden with nested inject()()'s

some kind of injects sorter, maybe with the ability to set index / inject while maintaining that with further nested inject()()