DEV Community

Cover image for You decide the new features!
JoelBonetR πŸ₯‡
JoelBonetR πŸ₯‡

Posted on

You decide the new features!

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)

Collapse
 
joelbonetr profile image
JoelBonetR πŸ₯‡ • Edited

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.

const MyDynamicClass = new makeStruct('name, surname');
Enter fullscreen mode Exit fullscreen mode

You can then, instantiate MyDynamicClass like that:

const myDynamicObject = new MyDynamicClass();
Enter fullscreen mode Exit fullscreen mode

Now you've an instance of that class and you can propagate data into it like that:

myDynamicObject.propagateArray(myArray);
myDynamicObject.propagateObject(myObject);
// or just like that:
myDynamicObject.name = 'Joel';
myDynamicObject.surname = 'Bonet';
Enter fullscreen mode Exit fullscreen mode

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!

Collapse
 
ecyrbe profile image
ecyrbe

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.

Collapse
 
jzombie profile image
jzombie

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.

Collapse
 
jzombie profile image
jzombie • Edited

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.

Collapse
 
adam_cyclones profile image
Adam Crockett πŸŒ€

The aim was to provide a Dynamic Object Constructor generator and methods to interact with.

I'm sorry I don't quite follow?

Collapse
 
adam_cyclones profile image
Adam Crockett πŸŒ€

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?