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

Support a .toJSON-like interface #31

Closed
coyotte508 opened this issue Dec 11, 2021 · 0 comments
Closed

Support a .toJSON-like interface #31

coyotte508 opened this issue Dec 11, 2021 · 0 comments

Comments

@coyotte508
Copy link

coyotte508 commented Dec 11, 2021

Feature request

Make it so that if an object as a .toJSON() function, devalue runs on the result of that function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior

Why

It would be nice to have feature parity with JSON.stringify.

My particular usecase is regarding SvelteKit: I'm engineering a pinia-like global store that works no matter the context (layout/page load in browser/ssr, or component initialization during browser/ssr), and so I store some writable stores in the session. The issue of course being that I don't want multiple users accessing the same shared stores during ssr.

I can achieve what I want by using Object.defineProperty with non-enumerable, regardless a toJSON api would be nice.

Other

If the feature is approved, I can do the PR.

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

1 participant