Skip to content

Commit

Permalink
fix: 🐛 Can save false values other than undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
haozi committed Mar 15, 2024
1 parent 6b772f4 commit 844116a
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 49 deletions.
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"dependencies": {
"idmp": "1.14.12"
"idmp": "1.15.0"
},
"_dependencies": {
"idmp": "1.13.0-alpha.5"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.11.26",
"@types/react": "^18.2.65",
"@types/react-dom": "^18.2.21",
"@types/node": "^20.11.27",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@vitejs/plugin-legacy": "^5.3.2",
"@vitejs/plugin-react-swc": "^3.6.0",
"@vitest/coverage-istanbul": "^1.3.1",
Expand Down
3 changes: 2 additions & 1 deletion plugins/browser-storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ If the data is in the memory, it is read from the memory first. If it is not in

## Notice

Data persistence only supports string type `globalKey` and data structures that can be serialized by `JSON.stringify`
- Data persistence only supports string type `globalKey` and data structures that can be serialized by `JSON.stringify`
- If return value is `undefined` it will not be cached, you must return `null`
4 changes: 2 additions & 2 deletions plugins/browser-storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const storageIdmpWrap = (
globalKey,
async () => {
const localData = storage.get(globalKey)
if (localData) {
if (localData !== udf) {
if (process.env.NODE_ENV !== 'production') {
console.log(
`[idmp-plugin browser-storage debug] ${globalKey} from ${storageType}["${getCacheKey(globalKey)}"]`,
Expand All @@ -84,7 +84,7 @@ const storageIdmpWrap = (
}

const memoryData = await promiseFunc()
if (memoryData) {
if (memoryData !== udf) {
// console.log('from memoryData')s a
storage.set(globalKey, memoryData, finalOptions.maxAge) // no need wait
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/node-fs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ If the data is in the memory, it is read from the memory first. If it is not in

## Notice

Data persistence only supports string type `globalKey` and data structures that can be serialized by [serialize-javascript](https://www.npmjs.com/package/serialize-javascript)
- Data persistence only supports string type `globalKey` and data structures that can be serialized by [serialize-javascript](https://www.npmjs.com/package/serialize-javascript)
- If return value is `undefined` it will not be cached, you must return `null`
4 changes: 2 additions & 2 deletions plugins/node-fs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ const fsIdmpWrap = (_idmp: Idmp) => {
globalKey,
async () => {
const localData = await getData(globalKey)
if (localData) {
if (localData !== udf) {
// console.log('from localData')
return localData
}

const memoryData = await promiseFunc()
if (memoryData) {
if (memoryData !== udf) {
// console.log('from memoryData')s a
setData(globalKey, memoryData, finalOptions.maxAge) // no need wait
}
Expand Down
84 changes: 45 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 844116a

Please sign in to comment.