boenfu / vuex-along

:memo: auto save and restore state for vuex
https://boenfu.github.io/vuex-along/
MIT License
259 stars 36 forks source link

存储内容格式的建议 #22

Closed han-feng closed 5 years ago

han-feng commented 5 years ago

目前存储到 storage 中 value 的 json 对象顶层用 name 值作为属性名称,与key值重复了。建议简化 value 格式。因为 name 是使用者定义的,name 的值可能很长,也可能包含 ‘.’ 这样的特殊符号,会导致存储格式很怪异。

例如,当前 demo 存储格式:

hello-vuex-along = {"hello-vuex-along": {"count": 10}}

能否简化为

hello-vuex-along = {"count": 10}

或者用固定的简单属性名:

hello-vuex-along = {"root": {"count": 10}}
boenfu commented 5 years ago

当前的储存格式有一个好处是,能够一定程度避免其他应用对这个 key 所对应 value 的覆写,可以通过检查 value 的 name 来简单的验证 value 是否还能被使用。也为之后可能存在的扩展存储块保留了空间,避免版本再次的不兼容。

han-feng commented 5 years ago

有一个bug请看一下,name带‘.’时格式会比较乱,例如下面这个name为‘admin-1.6.5-beta’:

{
  "admin-1": [
    null,
    null,
    null,
    null,
    null,
    null,
    {
      "5-beta": {
         ......
      }
    }
  ]
}

如果考虑加上校验功能的话,可以考虑对name进行hash,用hash值做value顶层属性名,这样也可以避免‘.’带来的格式混乱。

boenfu commented 5 years ago

👍 不知道你愿意为此提 pr 吗,如果你没空,我可能在五月初更新一下

han-feng commented 5 years ago

好的,我这两天提一个pr

boenfu commented 5 years ago

感谢

boenfu commented 5 years ago

已更新 1.2.5