Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getters / attributes not serialized #136

Closed
t3h2mas opened this issue Jun 1, 2020 · 2 comments
Closed

Getters / attributes not serialized #136

t3h2mas opened this issue Jun 1, 2020 · 2 comments

Comments

@t3h2mas
Copy link
Contributor

t3h2mas commented Jun 1, 2020

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?

@talyssonoc
Copy link
Owner

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.

@t3h2mas
Copy link
Contributor Author

t3h2mas commented Jun 19, 2020

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

Non-issue, sorry for the confusion.

@t3h2mas t3h2mas closed this as completed Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants