adopted-ember-addons / adopted-ember-addons/ember-local-storage

Creating new nested key

未关闭
#262 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
JavaScript
星标
220
派生
78
PR 合并指标
30 天内没有已合并 PR

描述

I have a settings local-storage model with nested attributes. This is working great, but when trying to add more attributes I'm confused as to why the ember-local-storage plugin isn't simply creating the new key for the missing nested attribute. For example:

My settings when project was first launched in the browser:
```
lastWifi: false,
lastConnected: null,
settings: {
language: 'en',
about: {
version: "0.5"
}
}
```

This created a localStorage object, works like a charm. However in developing the app, I need to add more nested keys.

```
lastWifi: false,
lastConnected: null,
settings: {
language: 'en',
about: {
version: "0.5"
},
bluetooth: {
allow: true
}
```

When trying to access the bluetooth and it's allow key, I'm getting this error:
```
ember.debug.js:19818 Property set failed: object in path "settings.bluetooth" could not be found or was destroyed.
Error
at setPath (http://localhost:4200/assets/vendor.js:35584:15)
at Object.set (http://localhost:4200/assets/vendor.js:35504:14)
at Class.set (http://localhost:4200/assets/vendor.js:48371:26)
at Class.saveIfChanged (http://localhost:4200/assets/vendor.js:74170:17)
at Class.superWrapper [as set] (http://localhost:4200/assets/vendor.js:54095:22)
at Class.toggleSetting (http://localhost:4200/assets/www.js:1207:30)
at Backburner.join (http://localhost:4200/assets/vendor.js:13883:21)
at Function.run.join (http://localhost:4200/assets/vendor.js:35754:28)
at http://localhost:4200/assets/vendor.js:23468:37
at Object.flaggedInstrument (http://localhost:4200/assets/vendor.js:31850:14)
```

I understand I could use the `.isInitialContent()` `.clear()` or `.reset()` functions, however I would then have to do this for every update I deploy or on every new key I add? Seems somewhat counter productive and could lead to a bad user experience.

I've now added my local-storage to a model, as recommended for nested attributes. However the behavior does not change.

贡献指南

打开贡献指南

调研方向

Start by reproducing the reported case in ember-local-storage with an existing localStorage object that lacks a newly added nested key such as settings.bluetooth.allow. The relevant entry point named in the repository is the storageFor computed property and its proxy persistence to localStorage/sessionStorage. Done means the addon either creates missing nested keys without requiring clear/reset, or the unsupported behavior is documented.

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
frontend, web-dev
Issue 类型
缺陷
难度
3/5
预计耗时
半天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。