-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
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 of devalue, 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:
export default class Bar {
constructor (id = Math.random()) {
this.id = id
}
transform () {
return this.id * 2
}
}and the goal is to do someBarInstance.transform() in the frontend. The two apps have the same index.vue, the basic one shows an error because .transform is not a function on the devalued object, the other one uses flatted to serialize and revive the object, properly displaying .transform()'s result.