uni-helper / uni-use

uni-app (vue3) 组合式工具集
MIT License
128 stars 16 forks source link

BUG: `useStorageAsync` didn't handle data-not-found exception and write default value #25

Closed MaikoTan closed 1 year ago

MaikoTan commented 1 year ago

Describe the bug

Unlike the useStorageAsync function in VueUse, instead, an exception would be thrown and the default value was not written into the storage in UniApp if the data didn't present initially.

image

https://github.com/uni-helper/uni-use/blob/974e6063713a640d33f7c5ad2c0d64a9e9d7775c/src/useStorageAsync/index.ts#L215-L241

I think it is because the line 217 throws the exception mentioned above rather than return a null value which leads the next line rawValue == null comparation makes no sense.

Reproduction

import { useStorageAsync } from '@uni-helper/uni-use'

const test = useStorageAsync('test', 'default-value') // throws exception
console.log(test.value)

System Info

System:
    OS: Linux 6.4 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz
    Memory: 3.59 GB / 11.51 GB
    Container: Yes
    Shell: 3.6.1 - /usr/bin/fish
  Binaries:
    Node: 20.5.0 - /tmp/xfs-582e2a7f/node
    Yarn: 3.4.1 - /tmp/xfs-582e2a7f/yarn
    npm: 9.8.1 - /usr/bin/npm
    pnpm: 8.6.12 - /usr/bin/pnpm

Used Package Manager

yarn

Validations

ModyQyW commented 1 year ago

Thanks a lot! Should be fixed in 0.14.1.