Skip to content

Commit bcca723

Browse files
committed
chore(storage): do not return the cached ref item!
1 parent 1ce6d0d commit bcca723

File tree

4 files changed

+38
-372
lines changed

4 files changed

+38
-372
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ _2020-02-27_
1313

1414
### Breaking-Change
1515

16+
- [localStorage](https://pikax.me/vue-composable/composable/storage/localStorage): can only keep one `ref` per key!
17+
18+
## 1.0.0-dev.12
19+
20+
_2020-02-27_
21+
22+
### Breaking-Change
23+
1624
- [storage](https://pikax.me/vue-composable/composable/storage/storage) [sessionStorage](https://pikax.me/vue-composable/composable/storage/sessionStorage) [localStorage](https://pikax.me/vue-composable/composable/storage/localStorage) - Added `sync` argument, defaults to `true`, when true it will sync the storage with other tabs
1725
- [onScroll](https://pikax.me/vue-composable/composable/event/onScroll.html) - Now `scrollTop` and `scrollLeft` are watched automatically for changes and will call `scrollTopTo` and `scrollLeftTo` respectably on change
1826

docs/composable/storage/localStorage.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ const { remove, clear, setSync } = useLocalStorage(key);
4747
| `clear()` | Clears all used localStorage used so far |
4848
| `setSync(boolean)` | Update the local `storage` if the value is changed in other tab |
4949
50+
## Sync
51+
52+
::: warning
53+
When using `sync: true`, only the **last** ref per key will be able to update
54+
:::
55+
5056
## Example
5157
5258
![Local Storage Cross tab](/vue-composable/localStorage.gif)

packages/web/src/storage/webStorage.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,15 @@ export function useWebStorage(
175175
storage.removeItem(k);
176176
},
177177
getItem(k) {
178-
let r = this.$refMap.get(k);
179-
if (r) {
180-
return r;
181-
}
178+
/**
179+
* NOTE seems if the element who created the `ref` gets destroyed all the watchers assigned will be also disposed
180+
* making returning of the cached `ref` invalid
181+
*/
182+
183+
// let r = this.$refMap.get(k);
184+
// if (r) {
185+
// return r;
186+
// }
182187
const data = storage.getItem(k);
183188
if (!data) {
184189
return null;

0 commit comments

Comments
 (0)