I did this little package some time ago and I'd like to request feedback.
The aim was to provide a Dynamic Object Constructor generator and methods to interact with.
Requirements:
- It can be used in both frontend and backend.
- The package must be kept with 0 dependencies.
Any feature you feel necessary will be analysed to develop. I'll answer asap with the new version so you can test it and validate your idea implementation!
Of course you can add your Pull Request instead and become a collaborator 😁
Top comments (6)
Hi @ecyrbe , didn't found any other solution to this specifically.
It's nothing rocket science, it just creates a constructor based on a bunch of data in a string.
Either be from an object keys or a string gathered from a key-value array or simply a dynamically generated string.
You can then, instantiate
MyDynamicClass
like that:Now you've an instance of that class and you can propagate data into it like that:
That's what the lib automates. As I said, nothing rocket science but maybe we can come with some great ideas to add as methods so Objects generated this way will inherit and have available once instantiated, as example.
@jzombie You got a nice idea there, why don't you add a PR into the project so you appear as collaborator? 😀
@adam_cyclones The aim is to dynamically generate those constructors while providing a simple API into this generated objects, if you mind, you can create a PoC using TS instead so we can learn and see how it will work! 😁
Thank you guys!
Hello Joël,
Maybe improve the docs, by adding examples of what kind of problem your library solves. By reading it fastly i fail to see why i would use it?
If other librairies solves the same kind of problem, maybe add a comparison section or at least mention them.
And last, i would also add a performance section. And compare to other solutions.
You could add unit tests.
--- some opinions below
Second to that, you might gain performance benefit if you use Map (developer.mozilla.org/en-US/docs/W...) instead of your class.
You could still keep the API the same while having a more "native" backend w/ the Map usage.
If you do retain the class usage, I'd useJS classes, as it can be more easily extended with other functionality in the future.
You can also extend the "native" Map type (i.e. class StructMap extends Map) with a custom class for your needs.
If doing that, I'd highly recommend TypeScript because it will help you avoid returning the wrong types in your methods.
I'm sorry I don't quite follow?
Okay I spent some time looking at the code. Have you seen Typescript? It's probably the better way to go, defining an object literal is going to be way more straight forward than this, and you could just add an interface... I'm guessing that's kind of what a struct is meant to be?