You decide the new features!
JoelBonetR 🥇

JoelBonetR 🥇 @joelbonetr

About: Tech Lead/Team Lead. Senior WebDev. Intermediate Grade on Computer Systems- High Grade on Web Application Development- MBA (+Marketing+HHRR). Studied a bit of law, economics and design

Location:
Spain
Joined:
Apr 19, 2019

You decide the new features!

Publish Date: Jul 7 '22
11 6

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 😁

Comments 6 total

  • ecyrbe
    ecyrbeJul 7, 2022

    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.

  • Adam Crockett 🌀
    Adam Crockett 🌀Jul 7, 2022

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

    I'm sorry I don't quite follow?

    • Adam Crockett 🌀
      Adam Crockett 🌀Jul 7, 2022

      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?

  • jzombie
    jzombieJul 8, 2022

    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.

    • jzombie
      jzombieJul 8, 2022

      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.

  • JoelBonetR 🥇
    JoelBonetR 🥇Jul 18, 2022

    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!

Add comment