ember-learn / ember-learn/guides-source
Octane @tracked properties in native classes models do not JSON.stringify
- Dominant language
- HTML
- Stars
- 161
- Forks
- 512
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 4
Description
declaring models as util classes and using `@tracked` property (as described here https://octane-guides-preview.emberjs.com/release/state-management/tracked-properties/#toc_tracked-properties-in-custom-classes) causes any such model passed to a `JSON.stringify` call to omit any tracked properties from the json output.
in short doing this
```javascript
class Person {
@tracked firstName;
@tracked lastName;
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
get fullName() {
return `${this.firstName} ${this.lastName}`;
}
}
JSON.stringify(new Person('Tobias', 'Bieniek')); // --> "{}"
```
solution would be implementing `toJSON` method in the class
the guides should be updated to reflect that as it's very likely someone would want to pass those models to a persistence layer of any sort (this would be a problem even with localStorage)
Contributor guide
Assessment
This issue has not been assessed yet.