robinvdvleuten / vuex-persistedstate

💾 Persist and rehydrate your Vuex state between page reloads.
https://npm.im/vuex-persistedstate
MIT License
5.77k stars 378 forks source link

Accessors/Getters have a different name after rehydrating #208

Closed thomaspaulin closed 5 years ago

thomaspaulin commented 5 years ago

Do you want to request a feature or report a bug? bug/feature request

What is the current behavior? After rehydrating some accessors have an incorrect name if using _ to denote a private field.

I'm going down the route of using classes whose intended private members are prefixed with _. In order to access said private fields I am using accessors whose name DO NOT include this underscore prefix. Based on the current functionality this means that when the store state is rehydrated my accessors have the wrong name.

Example:

export default class Vehicle {
   _position;

  constructor(...) { ... }

  get position() {
    return this._position;
  }
}

After rehydrating the accessor is no longer position() but is instead _position().

If the current behavior is a bug, please provide the steps to reproduce.

  1. Create a Vue project with Vuex and Vuex-persistedstate using the default createPersistedState()
  2. Create the class above, or another with prefixed members and accessors which lack the
  3. Save such an object into the store and persist it to local storage
  4. Rehydrate the store state from local storage
  5. Notice the position() accessor has been replaced with _position().

What is the expected behavior? The data will be deserialised to the class provided in the first place. i.e., Vehicle in = Vehicle out.

If this is a feature request, what is motivation or use case for changing the behavior? So members intended to be private can be distinguished from public ones and still work before and after the store state is persisted.

robinvdvleuten commented 5 years ago

Yeah you have to serialize and deserialize class instance yourself. The plugin is not going to do that. Please move the question to the Vue Forum or StackOverflow.