-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Use flatted instead of devalue to be able to revive objects #5117
Comments
I was about to open a bug report, because the current behaviour with It is unexpected that what is passed in as a data model instance then comes out as an object (essentially only a dictionary mimicking the model) within the component. As far as I've understood this, Nuxt has forked |
Agreed that it would be really nice to have some ability to reconstitute an object. At a bare minimum having some ability to declare some kind of |
something to consider. flatted seems 2.5x slower than devalue. On 120kb i got this results |
+1 |
I've been working on this problem over the past couple of days. I have it working for my project but want to see what you guys think of my solution.
|
Let's track in #12831. |
What problem does this feature solve?
It is sometimes useful to save complex data (i.e. not primitive types nor POJOs) in the store.
Store data is passed from server to client in serialized form using devalue. Using
flatted
instead ofdevalue
, together with some configuration mechanism, would allow reviving objects that would then be usable client-side.For instance developers would add revivers to the store and these would be called client-side to revive serialized values.
What does the proposed changes look like?
I created an example repo which consists of two
npx create-nuxt-app
: https://github.com/vhf/nuxt-flatted-feature/commits/master . It's a dumb example because I wanted to keep it minimal, in a real-world use case I'm storing things like RDF dataset objects ( https://github.com/rdf-ext/rdf-dataset-indexed ) (initialized during serverIniti based on server data/request data).In this example I'm storing an object based on:
and the goal is to do
someBarInstance.transform()
in the frontend. The two apps have the sameindex.vue
, the basic one shows an error because.transform
is not a function on thedevalue
d object, the other one uses flatted to serialize and revive the object, properly displaying.transform()
's result.The text was updated successfully, but these errors were encountered: