About a real world case
zxdong262 opened this issue · 3 comments
zxdong262 commented
class Store {
_config: '{}',
get config () {
return JSON.parse(store._config || '{}')
}
}
const store = useProxy(new Store())
store._config = JSON.stringify({
someString: 'sss',
someArr: []
})
expect(store.config).toBeSimpleObject()
// store.someArr would be Proxy, which would cause trouble in some situation like worker.postMessage(store.config)
// anyway here would expect store.config be a simple obejct without any proxy
// any suggestion on this situation? Any proper way to get simple object without Proxy?
tylerlong commented
I think the by default behavior is just as you expected.
The getter method returns is a plain object.
https://github.com/tylerlong/use-proxy/blob/main/test/plainObject.spec.ts
tylerlong commented
If you really want something to be a plain object. You may do a translation when you need it:
JSON.parse(JSON.stringify(something));
tylerlong commented
Nowadays I use https://github.com/typestack/class-transformer