xxf_react 0.2.5 → 0.2.7
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/dist/foundation/Debug.d.ts +7 -0
- package/dist/foundation/Debug.d.ts.map +1 -0
- package/dist/foundation/Debug.js +12 -0
- package/dist/foundation/PerformanceMonitor.d.ts +13 -0
- package/dist/foundation/PerformanceMonitor.d.ts.map +1 -0
- package/dist/foundation/PerformanceMonitor.js +26 -0
- package/dist/foundation/index.d.ts +3 -0
- package/dist/foundation/index.d.ts.map +1 -0
- package/dist/foundation/index.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/models/ApiResponse.d.ts +29 -0
- package/dist/models/ApiResponse.d.ts.map +1 -0
- package/dist/models/ApiResponse.js +32 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Debug.d.ts","sourceRoot":"","sources":["../../src/foundation/Debug.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,IAAI,GAAG,MAAM,CAK3D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PerformanceMonitor } from "./PerformanceMonitor";
|
|
2
|
+
/**
|
|
3
|
+
* 类似 Kotlin 的 measureTimeMillis
|
|
4
|
+
* @param block 要测量的代码块
|
|
5
|
+
* @returns 执行时间(毫秒)
|
|
6
|
+
*/
|
|
7
|
+
export function measureTimeMillis(block) {
|
|
8
|
+
const monitor = new PerformanceMonitor();
|
|
9
|
+
monitor.start();
|
|
10
|
+
block();
|
|
11
|
+
return monitor.end();
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PerformanceMonitor.d.ts","sourceRoot":"","sources":["../../src/foundation/PerformanceMonitor.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,KAAK,CAAa;IAE1B;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,kBAAkB;IAOzC;;OAEG;IACH,GAAG,IAAI,MAAM;CAKhB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class PerformanceMonitor {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.startTime = 0;
|
|
4
|
+
this.label = '';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 开始计时
|
|
8
|
+
*/
|
|
9
|
+
start(label) {
|
|
10
|
+
this.startTime = performance.now();
|
|
11
|
+
if (label)
|
|
12
|
+
this.label = label;
|
|
13
|
+
if (this.label)
|
|
14
|
+
console.time(this.label);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 结束计时并返回时间(毫秒)
|
|
19
|
+
*/
|
|
20
|
+
end() {
|
|
21
|
+
const elapsed = performance.now() - this.startTime;
|
|
22
|
+
if (this.label)
|
|
23
|
+
console.timeEnd(this.label);
|
|
24
|
+
return elapsed;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/foundation/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,sBAAsB,CAAA"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAG7B,wBAAgB,OAAO,SAEtB"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAG7B,wBAAgB,OAAO,SAEtB"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一 API 响应格式
|
|
3
|
+
*/
|
|
4
|
+
export interface ApiResponse<T> {
|
|
5
|
+
code: number;
|
|
6
|
+
message: string;
|
|
7
|
+
data: T;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 检查 API 响应是否成功
|
|
11
|
+
*/
|
|
12
|
+
export declare function isApiSuccess(code: number): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* API 错误类
|
|
15
|
+
*/
|
|
16
|
+
export declare class ApiError extends Error {
|
|
17
|
+
code: number;
|
|
18
|
+
constructor(code: number, message: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 从 API 响应中json提取data字段数据,失败时抛出错误
|
|
22
|
+
* @deprecated 请使用 {@link getDataFieldOrThrow} 代替
|
|
23
|
+
*/
|
|
24
|
+
export declare function getDataOrThrow<T>(response: ApiResponse<T>): T;
|
|
25
|
+
/**
|
|
26
|
+
* 从 API 响应中json提取data字段数据,失败时抛出错误
|
|
27
|
+
*/
|
|
28
|
+
export declare function getDataFieldOrThrow<T>(response: ApiResponse<T>): T;
|
|
29
|
+
//# sourceMappingURL=ApiResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiResponse.d.ts","sourceRoot":"","sources":["../../src/models/ApiResponse.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,CAAC,CAAA;CACV;AAGD;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAC/B,IAAI,EAAE,MAAM,CAAA;gBAEA,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK5C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAE7D;AAGD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAKlE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检查 API 响应是否成功
|
|
3
|
+
*/
|
|
4
|
+
export function isApiSuccess(code) {
|
|
5
|
+
return code === 0 || code === 200;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* API 错误类
|
|
9
|
+
*/
|
|
10
|
+
export class ApiError extends Error {
|
|
11
|
+
constructor(code, message) {
|
|
12
|
+
super(`API Error: (${code}) ${message}`);
|
|
13
|
+
this.name = 'ApiError';
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 从 API 响应中json提取data字段数据,失败时抛出错误
|
|
19
|
+
* @deprecated 请使用 {@link getDataFieldOrThrow} 代替
|
|
20
|
+
*/
|
|
21
|
+
export function getDataOrThrow(response) {
|
|
22
|
+
return getDataFieldOrThrow(response);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 从 API 响应中json提取data字段数据,失败时抛出错误
|
|
26
|
+
*/
|
|
27
|
+
export function getDataFieldOrThrow(response) {
|
|
28
|
+
if (!isApiSuccess(response.code)) {
|
|
29
|
+
throw new ApiError(response.code, response.message);
|
|
30
|
+
}
|
|
31
|
+
return response.data;
|
|
32
|
+
}
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
|
package/dist/models/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xxf_react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
|
|
6
6
|
"type": "module",
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"./responsive": {
|
|
45
45
|
"types": "./dist/responsive/index.d.ts",
|
|
46
46
|
"import": "./dist/responsive/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./foundation": {
|
|
49
|
+
"types": "./dist/foundation/index.d.ts",
|
|
50
|
+
"import": "./dist/foundation/index.js"
|
|
47
51
|
}
|
|
48
52
|
},
|
|
49
53
|
|