@taicode/common-web 1.0.5 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/output/helpers/cache-api/cache-api.d.ts +13 -0
- package/output/helpers/cache-api/cache-api.d.ts.map +1 -0
- package/{source/utils/cache/aside.js → output/helpers/cache-api/cache-api.js} +54 -46
- package/output/helpers/cache-api/cache-api.test.d.ts +2 -0
- package/output/helpers/cache-api/cache-api.test.d.ts.map +1 -0
- package/output/helpers/cache-api/cache-api.test.js +348 -0
- package/output/helpers/cache-api/index.d.ts +2 -0
- package/output/helpers/cache-api/index.d.ts.map +1 -0
- package/output/helpers/cache-api/index.js +1 -0
- package/output/helpers/service/index.d.ts +1 -0
- package/output/helpers/service/index.d.ts.map +1 -0
- package/output/helpers/service/index.js +1 -0
- package/output/helpers/service/service.d.ts +5 -0
- package/output/helpers/service/service.d.ts.map +1 -0
- package/output/helpers/service/service.js +2 -0
- package/output/helpers/side-cache/index.d.ts +2 -0
- package/output/helpers/side-cache/index.d.ts.map +1 -0
- package/output/helpers/side-cache/index.js +1 -0
- package/output/helpers/side-cache/side-cache.d.ts +10 -0
- package/output/helpers/side-cache/side-cache.d.ts.map +1 -0
- package/output/{utils/cache/aside.js → helpers/side-cache/side-cache.js} +51 -20
- package/output/helpers/side-cache/side-cache.test.d.ts +2 -0
- package/output/helpers/side-cache/side-cache.test.d.ts.map +1 -0
- package/output/helpers/side-cache/side-cache.test.js +179 -0
- package/output/helpers/use-observer/index.d.ts +2 -0
- package/output/helpers/use-observer/index.d.ts.map +1 -0
- package/output/helpers/use-observer/index.js +1 -0
- package/output/{hooks/mobx.d.ts → helpers/use-observer/use-observer.d.ts} +1 -1
- package/output/helpers/use-observer/use-observer.d.ts.map +1 -0
- package/output/helpers/use-observer/use-observer.test.d.ts +2 -0
- package/output/helpers/use-observer/use-observer.test.d.ts.map +1 -0
- package/output/helpers/use-observer/use-observer.test.jsx +134 -0
- package/package.json +24 -16
- package/output/hooks/mobx.d.ts.map +0 -1
- package/output/utils/cache/aside.d.ts +0 -7
- package/output/utils/cache/aside.d.ts.map +0 -1
- package/output/utils/cache/index.d.ts +0 -2
- package/output/utils/cache/index.d.ts.map +0 -1
- package/output/utils/cache/index.js +0 -1
- package/source/catalyst/CHANGELOG.md +0 -136
- package/source/catalyst/README.md +0 -65
- package/source/catalyst/alert.tsx +0 -95
- package/source/catalyst/auth-layout.tsx +0 -11
- package/source/catalyst/avatar.tsx +0 -84
- package/source/catalyst/badge.tsx +0 -82
- package/source/catalyst/button.tsx +0 -204
- package/source/catalyst/checkbox.tsx +0 -157
- package/source/catalyst/combobox.tsx +0 -188
- package/source/catalyst/description-list.tsx +0 -37
- package/source/catalyst/dialog.tsx +0 -86
- package/source/catalyst/divider.tsx +0 -20
- package/source/catalyst/dropdown.tsx +0 -183
- package/source/catalyst/fieldset.tsx +0 -91
- package/source/catalyst/heading.tsx +0 -27
- package/source/catalyst/input.tsx +0 -94
- package/source/catalyst/link.tsx +0 -21
- package/source/catalyst/listbox.tsx +0 -177
- package/source/catalyst/navbar.tsx +0 -96
- package/source/catalyst/pagination.tsx +0 -98
- package/source/catalyst/radio.tsx +0 -142
- package/source/catalyst/select.tsx +0 -68
- package/source/catalyst/sidebar-layout.tsx +0 -82
- package/source/catalyst/sidebar.tsx +0 -142
- package/source/catalyst/stacked-layout.tsx +0 -79
- package/source/catalyst/switch.tsx +0 -195
- package/source/catalyst/table.tsx +0 -124
- package/source/catalyst/text.tsx +0 -40
- package/source/catalyst/textarea.tsx +0 -54
- package/source/hooks/mobx.d.ts +0 -3
- package/source/hooks/mobx.d.ts.map +0 -1
- package/source/hooks/mobx.js +0 -16
- package/source/hooks/mobx.ts +0 -24
- package/source/utils/cache/aside.d.ts +0 -7
- package/source/utils/cache/aside.d.ts.map +0 -1
- package/source/utils/cache/aside.ts +0 -39
- package/source/utils/cache/index.d.ts +0 -2
- package/source/utils/cache/index.d.ts.map +0 -1
- package/source/utils/cache/index.js +0 -1
- package/source/utils/cache/index.ts +0 -1
- /package/output/{hooks/mobx.js → helpers/use-observer/use-observer.js} +0 -0
package/source/hooks/mobx.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { reaction } from 'mobx'
|
|
2
|
-
import React, { useState } from 'react'
|
|
3
|
-
|
|
4
|
-
export function useObserver<T>(initialValue: T): T
|
|
5
|
-
export function useObserver<T, U>(initialValue: T, selector: (v: T) => U): U
|
|
6
|
-
export function useObserver<T, U>(initialValue: T, selector?: (v: T) => U): U | T {
|
|
7
|
-
const [, refresh] = useState({})
|
|
8
|
-
|
|
9
|
-
React.useEffect(() => {
|
|
10
|
-
if (initialValue == null) return
|
|
11
|
-
if (selector == null) return
|
|
12
|
-
return reaction(
|
|
13
|
-
() => selector(initialValue),
|
|
14
|
-
() => refresh({})
|
|
15
|
-
)
|
|
16
|
-
}, [selector, initialValue])
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (selector == null) {
|
|
20
|
-
return initialValue as T
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return selector(initialValue)
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aside.d.ts","sourceRoot":"","sources":["aside.ts"],"names":[],"mappings":"AAOA,qBAAa,UAAU,CAAC,CAAC;IAEvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IAGjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoC;IAE1D,IACW,KAAK,IAAI,CAAC,GAAG,IAAI,CAG3B;IAGY,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;CAiBrH"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { action, computed, observable, runInAction } from 'mobx'
|
|
2
|
-
|
|
3
|
-
interface CacheValue<T> {
|
|
4
|
-
data: T
|
|
5
|
-
createTime: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class AsideCache<T> {
|
|
9
|
-
@observable
|
|
10
|
-
private accessor currentKey: string | null = null
|
|
11
|
-
|
|
12
|
-
@observable.ref
|
|
13
|
-
private accessor cache: Record<string, CacheValue<T>> = {}
|
|
14
|
-
|
|
15
|
-
@computed
|
|
16
|
-
public get value(): T | null {
|
|
17
|
-
if (this.currentKey == null) return null
|
|
18
|
-
return this.cache[this.currentKey]?.data || null
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@action.bound
|
|
22
|
-
public async handle<F extends ((...args: unknown[]) => Promise<T | null>)>(key: unknown, func: F): Promise<T | null> {
|
|
23
|
-
const keyStringify = JSON.stringify(key) // 不需要跨设备、软件一致,所以直接用 JSON.stringify
|
|
24
|
-
runInAction(() => this.currentKey = keyStringify)
|
|
25
|
-
const funcReturn = await func()
|
|
26
|
-
if (funcReturn == null) return funcReturn
|
|
27
|
-
runInAction(() => {
|
|
28
|
-
this.cache = {
|
|
29
|
-
...this.cache,
|
|
30
|
-
[keyStringify]: {
|
|
31
|
-
data: funcReturn,
|
|
32
|
-
createTime: new Date().toISOString()
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
return funcReturn
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { AsideCache } from './aside';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { AsideCache } from './aside'
|
|
File without changes
|