@canlooks/statio 1.0.0
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/LICENSE +21 -0
- package/README.md +511 -0
- package/dist/cjs/api.js +51 -0
- package/dist/cjs/compute.js +51 -0
- package/dist/cjs/createStore.js +104 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/log.js +4 -0
- package/dist/cjs/storage.js +44 -0
- package/dist/cjs/util.js +110 -0
- package/dist/esm/api.js +47 -0
- package/dist/esm/compute.js +46 -0
- package/dist/esm/createStore.js +101 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/log.js +1 -0
- package/dist/esm/storage.js +41 -0
- package/dist/esm/util.js +103 -0
- package/index.d.ts +79 -0
- package/package.json +58 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {Computable} from './src'
|
|
2
|
+
|
|
3
|
+
declare namespace Statio {
|
|
4
|
+
type StoreClass<S = any> = new (set: SetStateMethod<S>, api: StoreApi<S>) => S
|
|
5
|
+
|
|
6
|
+
type StoreFactory<S> = (set: SetStateMethod<S>, api: StoreApi<S>) => S
|
|
7
|
+
|
|
8
|
+
type SetStateMethod<S> = (state: SetStateAction<S>, overwrite?: boolean) => void
|
|
9
|
+
|
|
10
|
+
type SetStateAction<S> = Partial<S> | ((state: S) => Partial<S>)
|
|
11
|
+
|
|
12
|
+
class StoreApi<S> {
|
|
13
|
+
state: S
|
|
14
|
+
serverState?: S
|
|
15
|
+
setState: SetStateMethod<S>
|
|
16
|
+
getState(): S
|
|
17
|
+
compute: Compute
|
|
18
|
+
computable: Computable<S>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type Compute = <T>(factory: () => T, deps: any[]) => T
|
|
22
|
+
|
|
23
|
+
type Listener<S> = (state: S) => void
|
|
24
|
+
|
|
25
|
+
type IsEqual<T> = (snapshot: T, prevSnapshot: T) => any
|
|
26
|
+
|
|
27
|
+
type SubscribeOptions<T = any> = {
|
|
28
|
+
immediate?: boolean
|
|
29
|
+
isEqual?: IsEqual<T>
|
|
30
|
+
/** @private */
|
|
31
|
+
_initSnapshot?: any
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ---------------------------------------------------------------------------------------
|
|
36
|
+
* createStore
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
function createStore<S extends object = any>(factory: StoreFactory<S> | StoreClass<S>): S
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* ---------------------------------------------------------------------------------------
|
|
43
|
+
* Storage
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
type StorageOptions<S> = {
|
|
47
|
+
name: string
|
|
48
|
+
/** Default to `localStorage` */
|
|
49
|
+
type?: 'localStorage' | 'sessionStorage'
|
|
50
|
+
selector?<T = S>(state: S): T
|
|
51
|
+
adapter?: {
|
|
52
|
+
getItem(key: string): string | null
|
|
53
|
+
setItem(key: string, value: string): void
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function storage<S extends object>(factory: StoreFactory<S> | StoreClass<S>, options: StorageOptions<S>): StoreFactory<S>
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* ---------------------------------------------------------------------------------------
|
|
61
|
+
* Util
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
function getAllPropertyDescriptors(o: any): { [p: PropertyKey]: PropertyDescriptor }
|
|
65
|
+
|
|
66
|
+
function isClass(fn: Function | StoreClass): fn is StoreClass
|
|
67
|
+
|
|
68
|
+
function shallowEqual(a: any, b: any): boolean
|
|
69
|
+
|
|
70
|
+
interface AbortablePromise<T> extends Promise<T> {
|
|
71
|
+
abort(): void
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function nextTick<T>(callback?: (...args: T[]) => void, ...args: T[]): AbortablePromise<T>
|
|
75
|
+
|
|
76
|
+
function createBatchAction<T extends (this: any, ...a: any[]) => any>(action: T, effect: () => any): T
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export = Statio
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@canlooks/statio",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "C.CanLiang <canlooks@gmail.com>",
|
|
5
|
+
"description": "Simple react state manager",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"state manager"
|
|
9
|
+
],
|
|
10
|
+
"main": "dist/cjs/index.js",
|
|
11
|
+
"module": "dist/esm/index.js",
|
|
12
|
+
"types": "index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"import": "./dist/esm/index.js",
|
|
17
|
+
"require": "./dist/cjs/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/canlooks/statio"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/canlooks/statio",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/canlooks/statio/issues",
|
|
31
|
+
"email": "canlooks@gmail.com"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"scripts": {
|
|
35
|
+
"clean": "npx shx rm -rf dist",
|
|
36
|
+
"build": "tsc -m esnext --outDir dist/esm & tsc -m commonjs --outDir dist/cjs",
|
|
37
|
+
"build:alias": "tsc-alias --outDir dist/esm",
|
|
38
|
+
"rebuild": "npm run clean && npm run build && npm run build:alias",
|
|
39
|
+
"test:browser": "vite -c test/vite.config.mts",
|
|
40
|
+
"test:ssr": "next dev test",
|
|
41
|
+
"test:unit": "npx ts-node test/unit.ts"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"tslib": "^2.8.1"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^25.8.0",
|
|
48
|
+
"@types/react": "^19.2.14",
|
|
49
|
+
"@types/react-dom": "^19.2.3",
|
|
50
|
+
"next": "^16.2.6",
|
|
51
|
+
"react": "^19.2.6",
|
|
52
|
+
"react-dom": "^19.2.6",
|
|
53
|
+
"tsc-alias": "^1.8.17",
|
|
54
|
+
"typescript": "^6.0.3",
|
|
55
|
+
"vite": "^8.0.13",
|
|
56
|
+
"zustand": "^5.0.13"
|
|
57
|
+
}
|
|
58
|
+
}
|