Skip to content

Commit 29b42fc

Browse files
committed
perf(utils): 移除 error, warn 方法,直接使用warning 包
affects: @vue-async/utils
1 parent 9f30a1f commit 29b42fc

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"repository": {
3535
"type": "git",
3636
"url": "https://github.com/aceHubert/vue-async.git",
37-
"directory": "packages/helpers"
37+
"directory": "packages/utils"
3838
},
3939
"bugs": {
4040
"url": "https://github.com/aceHubert/vus-async/issues"

packages/utils/src/tools.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* tools
33
*/
4-
import { isUndef } from './types';
54
export const hasSymbol = typeof Symbol === 'function' && Symbol.for;
65

76
export const noop: any = (_: any) => _;
@@ -46,33 +45,9 @@ export function createUid() {
4645
return Math.random().toString(36).substring(3, 8);
4746
}
4847

49-
export function assert(condition: any, msg: string) {
48+
export function assert(condition: boolean, err: string | Error) {
5049
if (!condition) {
51-
throw new Error(`error: ${msg}`);
52-
}
53-
}
54-
55-
export function warn(condition: boolean, msg: string, vm?: any) {
56-
if (!condition) {
57-
if (isUndef(vm)) {
58-
// eslint-disable-next-line no-console
59-
console.warn(`warning: ${msg}`);
60-
} else {
61-
// eslint-disable-next-line no-console
62-
console.warn(`warning: ${msg}`, vm);
63-
}
64-
}
65-
}
66-
67-
export function error(condition: boolean, msg: string, vm?: any) {
68-
if (!condition) {
69-
if (isUndef(vm)) {
70-
// eslint-disable-next-line no-console
71-
console.error(`error: ${msg}`);
72-
} else {
73-
// eslint-disable-next-line no-console
74-
console.error(`error: ${msg}`, vm);
75-
}
50+
throw typeof err === 'string' ? new Error(`error: ${err}`) : err;
7651
}
7752
}
7853

packages/utils/src/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,27 @@ export function isPlainObject(x: unknown): x is Record<any, any> {
2222
export function isFunction(x: unknown): x is Function {
2323
return typeof x === 'function';
2424
}
25+
26+
// Inlined Object.is polyfill.
27+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
28+
export function objectIs(x: any, y: any) {
29+
if (x === y) {
30+
return x !== 0 || 1 / x === 1 / y;
31+
}
32+
// eslint-disable-next-line
33+
return x !== x && y !== y;
34+
}
35+
36+
// https://developer.mozilla.org/en-US/docs/Glossary/Primitive
37+
export function isPrimitive(value: any): boolean {
38+
return (
39+
typeof value === 'string' ||
40+
typeof value === 'number' ||
41+
// $flow-disable-line
42+
typeof value === 'symbol' ||
43+
typeof value === 'boolean' ||
44+
typeof value === 'bigint' ||
45+
typeof value === 'undefined' ||
46+
value === null
47+
);
48+
}

packages/utils/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { version } from '../src';
22
export { getComponentName, sanitizeComponent } from '../src/vue-extend';
3-
export { proxy, hasOwn, assert, print, warn, error } from '../src/tools';
4-
export { isArray, isFunction, isObject, isPlainObject, isUndef } from '../src/types';
3+
export { proxy, def, createUid, hasOwn, hasSymbol, assert, print } from '../src/tools';
4+
export { isArray, isFunction, isObject, isPlainObject, isUndef, objectIs, isPrimitive } from '../src/types';

0 commit comments

Comments
 (0)