Skip to content

Commit

Permalink
chore: 🤖 v1.14.11
Browse files Browse the repository at this point in the history
  • Loading branch information
haozi committed Mar 12, 2024
1 parent 97f5ed2 commit ea4fa9b
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 51 deletions.
16 changes: 8 additions & 8 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
.vscode
.npmrc
coverage
demo
mock
**/demo
**/mock
**/src
**/docs
**/test
**/scripts
.vite
node_modules
index.html
pnpm-lock.yaml
pnpm-workspace.yaml
yarn.lock
package-lock.json
tsconfig.json
vite.config.ts
vite.*.config.ts

plugins/**/scripts/
plugins/**/src/
plugins/**/package.json
plugins/**/tsconfig.json
plugins/**/node_modules
vercel.json
SECURITY.md
index.html
.*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ An elegant library to solve duplicate and concurrent calls for idempotent functi

English | [简体中文](README.zh-CN.md)

- Demo <https://idmp.vercel.app>
- Demo <https://idmp-ha0z1.vercel.app>

## Usage

Expand Down Expand Up @@ -141,7 +141,7 @@ In React, you can share requests using swr, Provider and more complex state mana
2. Provider: Needs centralized data management. The data center can't perceive which modules will consume the data, need to maintain the data for a long time, and dare not delete it in time
3. Redux: Should focus on state changes and sequences, not data sharing. `idmp` lets you focus more on local state

See [demo](https://idmp.vercel.app) and [source code](https://github.com/ha0z1/idmp/tree/main/demo)
See [demo](https://idmp-ha0z1.vercel.app) and [source code](https://github.com/ha0z1/idmp/tree/main/demo)

So when module A or module B's code is deleted, there is no need to maintain their cache.

Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

[English](README.md) | 简体中文

- Demo <https://idmp.vercel.app>
- Demo <https://idmp-ha0z1.vercel.app>

## 使用

Expand Down Expand Up @@ -141,7 +141,7 @@ fetchData2().then(...) // will skip cache
2. Provider 数据共享: 需要一个中心化的数据管理。数据中心无法感知到哪些模块会消费数据,需要长期维护这些数据,而不敢及时删除
3. Redux 等状态管理库:应该专注的是状态的变化和时序,而非共享数据。`idmp` 让你更关注于局部状态

查看 [demo](https://idmp.vercel.app)[源码](https://github.com/ha0z1/idmp/tree/main/demo)
查看 [demo](https://idmp-ha0z1.vercel.app)[源码](https://github.com/ha0z1/idmp/tree/main/demo)

这样当模块 A 或者模块 B 的代码删除后,是不需要维护他们的缓存的。

Expand Down
File renamed without changes.
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.4"
"idmp": "1.14.10"
},
"_dependencies": {
"idmp": "1.13.0-alpha.5"
Expand Down
8 changes: 4 additions & 4 deletions demo/pages/Storage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import React, { useEffect, useState } from 'react'
import { getUserData } from '../../api'
import { Link } from 'react-router-dom'

const localStorageIdmp = storageWrap(idmp, 'localStorage')
const lsIdmp = storageWrap(idmp, 'localStorage')

const getUserDataWithlocalStorageIdmp = (userId: string) =>
localStorageIdmp(`getUserData${userId}`, () => getUserData(userId), {
const getUserDataWithLsIdmp = (userId: string) =>
lsIdmp(`getUserDataWithLsIdmp${userId}`, () => getUserData(userId), {
maxAge: 5000,
})

export default () => {
const [data, setData] = useState(null)
useEffect(() => {
getUserDataWithlocalStorageIdmp('123').then((data) => {
getUserDataWithLsIdmp('123').then((data) => {
setData(data)
})
}, [])
Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "idmp",
"version": "1.14.6",
"version": "1.14.11",
"keywords": [
"deduplicate network requests",
"idempotent function",
Expand All @@ -16,7 +16,7 @@
"immutable data",
"auto retry"
],
"homepage": "https://idmp.vercel.app",
"homepage": "https://idmp-ha0z1.vercel.app",
"bugs": "https://github.com/ha0z1/idmp/issues",
"repository": {
"type": "git",
Expand All @@ -26,15 +26,12 @@
"type": "module",
"exports": {
".": "./dist/index.js",
"./node-fs": "./plugins/node-fs/dist/index.js"
"./node-fs": "./plugins/node-fs/dist/index.js",
"./browser-storage": "./plugins/browser-storage/dist/index.js"
},
"main": "./dist/index.node.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"**/dist",
"*.d.ts"
],
"scripts": {
"api": "pnpm vite-node -w mock/api.ts",
"build": "tsc && vite-node scripts/build.ts && pnpm run -r build",
Expand Down
31 changes: 14 additions & 17 deletions plugins/browser-storage/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# idmp/node-fs
# idmp/browser-storage

## Useage
## Usage

```typescript
import idmp from 'idmp'
import storageWrap, { getCacheKey } from 'idmp/browser-storage'

const localStorageIdmp = storageWrap(
idmp,
'localStorage' /* default is 'sessionStorage' */,
)

const getUserDataWithlocalStorageIdmp = (userId: string) =>
localStorageIdmp(
`getUserDataWithlocalStorageIdmp${userId}`,
() => getUserData(userId),
{
maxAge: 5000,
},
)

getUserDataWithlocalStorageIdmp('123').then((data) => {
const lsIdmp = storageWrap(idmp, 'localStorage')

const getUserDataWithLsIdmp = (userId: string) =>
lsIdmp(`getUserDataWithLsIdmp${userId}`, () => getUserData(userId), {
maxAge: 5000,
})

getUserDataWithLsIdmp('123').then((data) => {
console.log(data)
})
```

Cache data will be stored in `localStorage / sessionStorage` temporary directory and follow the same cache options as `idmp`.
If the data is in the memory, it is read from the memory first. If it is not in the memory, it is read from the `localStorage / sessionStorage`. If the cache validity period expires, it will be read from the remote end.

## Notice

Data persistence only supports string type `globalKey` and data structures that can be serialized by `JSON.stringify`
4 changes: 3 additions & 1 deletion plugins/browser-storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const storageIdmpWrap = (
const localData = storage.get(globalKey)
if (localData) {
if (process.env.NODE_ENV !== 'production') {
console.log(`[idmp-plugin browser-storage debug] ${globalKey} from ${storageType}["${getCacheKey(globalKey)}"]`)
console.log(
`[idmp-plugin browser-storage debug] ${globalKey} from ${storageType}["${getCacheKey(globalKey)}"]`,
)
}
return localData
}
Expand Down
6 changes: 5 additions & 1 deletion plugins/node-fs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# idmp/node-fs

## Useage
## Usage

```typescript
import idmp from 'idmp'
Expand All @@ -19,3 +19,7 @@ await fsIdmp(

Cache data will be stored in the `cacheDir` temporary directory and follow the same cache options as `idmp`.
If the data is in the memory, it is read from the memory first. If it is not in the memory, it is read from the file system. If the cache validity period expires, it will be read from the remote end.

## Notice

Data persistence only supports string type `globalKey` and data structures that can be serialized by `JSON.stringify`
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

4 changes: 1 addition & 3 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"rewrites": [
{"source": "/(.*)", "destination": "/"}
]
"rewrites": [{ "source": "/(.*)", "destination": "/" }]
}
2 changes: 1 addition & 1 deletion vite.demo.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default defineConfig({
define: {
// __DEV__: "process.env.NODE_ENV !== 'production'",
// 'process.env.NODE_ENV': JSON.stringify('production'),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
},
})

0 comments on commit ea4fa9b

Please sign in to comment.