Tuesday 22 December 2015

[Question] Dynamically instantiating classes

I'm posting messages to SQS to handle per-client integrations with other systems. This keeps my code bases separate and allows me to scale appropriate services with ease. The message I'm posting is JSON that describes the client name, integration type, and a few other bits of data that's needed.I'm going to build these background workers in a single project and use the worker tier on Elastic Beanstalk to run it. When they consume a message, I'd like it to instantiate the correct class in the project based on properties in the queue message and then work the message. From there I can invoke the .run() function of the class and let it do its thing.How would I go about this? I've seen examples of people using window['classname'] but I don't know if it's the best. I really don't want to manually maintain a huge switch statement. I also don't want to maintain repos and EB instances for every client integration.I could know the path by naming the class file a particular wayI'm using Babel and the ES2015 presetAny ideas?Edit: Looks like the import statement in ES6 requires the path to be static.

Submitted December 22, 2015 at 11:07PM by RickAndMorty_forever

No comments:

Post a Comment