talyssonoc/structure

Getters / attributes not serialized

t3h2mas opened this issue · 2 comments

It would be convenient for getters and or attributes to be serializable via #toJSON or JSON.stringify

cont Thing = attributes({
    name: String
})(
    class Thing {
        get wild() {
            return 'wild thing'
        }
        get name() {
            return `Thing { ${this.get('name')} }`
        }
    }
)

Currently #toJSON would return an empty object, same with JSON.stringify

Could one or both of the getter or attribute be added to the sterilization results?

Hello, @t3h2mas. I'm not sure what you mean, running your example able like this:

const Thing = attributes({
      name: String,
    })(
      class Thing {
        get wild() {
          return 'wild thing';
        }
        get name() {
          return `Thing { ${this.get('name')} }`;
        }
      }
    );

    const thing = new Thing({ name: 'abc' });

    console.log(thing.toJSON());

it shows { name: 'Thing { abc }' } for me.

I must have been using v1 or messed up my trial code.

Non-issue, sorry for the confusion.