spraypaint.js icon indicating copy to clipboard operation
spraypaint.js copied to clipboard

Model to json payload

Open steventhan opened this issue 4 years ago • 2 comments

Is there a way to generate json payload from a model's instance? Right now I have this in my code which seems to work, but curious if an alternative exists

import { WritePayload } from 'spraypaint/lib-esm/util/write-payload';

@Model()
class Model extends SpraypaintBase {
  toJsonPayload = () => {
    return new WritePayload(this).asJSON();
  };
}

steventhan avatar Sep 21 '20 01:09 steventhan

I think this is easier for read operations, but what you have is probably the only way to go for writes. I'd accept a PR for it if you'd like to add it with some tests!

richmolj avatar Sep 21 '20 12:09 richmolj

I'll try to find some time to send a pr, thanks @richmolj !

steventhan avatar Sep 21 '20 16:09 steventhan