mobx-persist icon indicating copy to clipboard operation
mobx-persist copied to clipboard

Is it possible to define custom storage keys for @observable properties?

Open jaltin opened this issue 3 years ago • 1 comments

Hi,

In the example of readme, one can persist in this way:

class SomeItem { @persist @observable name = 'some' }

This is nice and straightforward, but causes problems if I want to refactor a property name (e.g. if I want to rename observable from 'name' to 'firstName'.

If I do that renaming, the value persisted in 'name' will be lost.

Ideally to get around this, I would like to have the possibility to optionally define a storage key, something similar to this:

class SomeItem { @persist('MY_CUSTOM_KEY_THAT_DOES_NOT_CHANGE') @observable name = 'some' }

Is this possible to achieve?

jaltin avatar Oct 04 '21 12:10 jaltin

Same situation, I want to rename the variable name and I am losing all the data.

agestaun avatar Oct 25 '22 13:10 agestaun