Elements are overridden after reload with vuex-persist

If you use vuex-orm with vuex-persist you onccur the problem, that, after a reload, vuex-orm starts to count at 1 again. So your persisted elements will be overridden.
Here you have an simple repo to check this out. https://github.com/Maqsyo/vuex-orm-uid-bug
Ah... yea. I think this would happen. Hmmm, maybe we should store uid increment numbers to Vuex State as well, or either implement a real UID feature.
I think storing it in the state could be a really good quick fix. Thats how MySQL is doing it.
I tried two implementations yesterday, store method as @Maqsyo suggested and the UID refactoring as @kiaking suggested.
I found there are side-effects to both approaches but the store is more feasible especially since no additional logic is required when using third party persist tools.
UID’s are especially important when generating indexes so a lot of logic is required when refactoring. Where as we can simply use the mutate action to update the UID count to the store when a store is available.
@cuebit Thank you for trying out! Yea, I think storing inside Vuex State would work. There're lot of UID implementation out there, and if you really need UUID in client side, the work needed for the app would vary from user to user I guess. So keeping Vuex ORM default UID as simple as possible would be the way to go, I think 👍
My current quick-fix: I'm using the current timestamp and concatenate it with an increment-value to reduce collisions.
import {Model} from '@vuex-orm/core';
let increment = 0;
export default class Post extends Model
{
static entity = 'posts'
static fields()
{
return {
id: this.uid(() => `${new Date().getTime()}_${increment++}`),
[...]
};
}
}
Ah yea, that’s smart 👍