quarrant / mobx-persist-store

Persist and rehydrate observable properties in mobx store.
270 stars 14 forks source link

How to support data versioning? #59

Closed ducNgbk closed 3 years ago

ducNgbk commented 3 years ago

Hi, how can I support versioning of my data?

For example

makePersistable(
      this,
      {
        storage: AsyncStorage,
        name: this.PersistKey,
        properties: ['listData'],
        version: 1.0.0,
      },
      {delay: 100, fireImmediately: false},
    );

then in future, I increase 1.0.0 to 1.1.0, my persisted properties will be initialized again (not getting data from previous version)

I know, this library has

    expireIn: 86400000,
    removeOnExpiration: true,

But I don't know exactly when I will change my properties structure

kubk commented 3 years ago

What if you just rename the key? Example:

class Store {
-  persistKey = 'key';
+  persistKey = 'key-1';
}

Would it work out?

quarrant commented 3 years ago

@kubk yep, you'll right

ducNgbk commented 3 years ago

@kubk brilliant, thanks very much, you rock it