Skip to content

Commit

Permalink
perf: update error function
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodong2008 committed Jan 25, 2024
1 parent f19d5a0 commit 1c1dec7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 42 deletions.
19 changes: 9 additions & 10 deletions src/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ class FastjsBaseModule<T extends FastjsBaseModule<any>> {
then(func: (e: T) => void, time: number = 0): T {
if (__DEV__) {
if (typeof func !== "function") {
_dev.warn("fastjs/base/FastjsBaseModule", "Invalid function, **a function is required**.", [
`***func: ${func}`,
`time: ${time}`,
"then(**func: (e: T) => void**, time: number = 0): T",
"FastjsBaseModule.then"
], ["fastjs.wrong"]);
throw _dev.error("fastjs/base/FastjsBaseModule", "Invalid function, a function is required.", [
"then(func: (e: T) => void, time: number = 0): T",
"FastjsBaseModule.then"
]);
if (__DEV__) {
throw _dev.error("fastjs/base/FastjsBaseModule", "Invalid function, **a function is required**.", [
`***func: ${func}`,
`time: ${time}`,
"then(**func: (e: T) => void**, time: number = 0): T",
"FastjsBaseModule.then"
], ["fastjs.wrong"]);
}
throw "t33q";
}
if (typeof time !== "number") {
_dev.warn("fastjs/base/FastjsBaseModule", "Invalid time, **a number is required**.", [
Expand Down
12 changes: 2 additions & 10 deletions src/date/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,12 @@ class FastjsDate extends FastjsBaseModule<FastjsDate> {
if (allTokens.includes(char)) {
if (isToken) {
if (__DEV__) {
_dev.warn("fastjs/date/FastjsDate", "Invalid format string, token cannot be adjacent", [
throw _dev.error("fastjs/date/FastjsDate", "Invalid format string, token cannot be adjacent", [
"***formatString: " + formatString,
"***dateString: " + dateString,
"private parseFormatString(formatString: string, dateString: string): number",
"super: ", this
], ["fastjs.wrong"]);
throw _dev.error("fastjs/date/FastjsDate", "Invalid format string, token cannot be adjacent", [
"private parseFormatString(formatString: string, dateString: string): number",
"FastjsDate.parseFormatString",
]);
}
throw "fg3j"
}
Expand Down Expand Up @@ -205,16 +201,12 @@ class FastjsDate extends FastjsBaseModule<FastjsDate> {
if (is12Hour) {
if (isAm === null) {
if (__DEV__) {
_dev.warn("fastjs/date/FastjsDate", "Invalid format string, using 12 hours format but missing AM/PM token", [
throw _dev.error("fastjs/date/FastjsDate", "Invalid format string, using 12 hours format but missing AM/PM token", [
"***formatString: " + formatString,
"***dateString: " + dateString,
"private parseFormatString(formatString: string, dateString: string): number",
"super: ", this
], ["fastjs.wrong"]);
throw _dev.error("fastjs/date/FastjsDate", "Invalid format string, using 12 hours format but missing AM/PM token", [
"private parseFormatString(formatString: string, dateString: string): number",
"FastjsDate.parseFormatString",
]);
}
throw "2b5s"
}
Expand Down
29 changes: 12 additions & 17 deletions src/dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,17 @@ class FastjsDom extends FastjsBaseModule<FastjsDom>{
}
} else if (el instanceof HTMLElement) {
this._el = el
} else if (__DEV__) {
_dev.warn("fastjs/dom/Dom", `el is not **HTMLElement or string**, instead of **${typeof el}**`, [
"*el: ", el,
"properties: ", p,
"constructor(**el: Dom | HTMLElement | Element | string**, properties?: FastjsDomProps)",
"super: ", this
], ["fastjs.right", "fastjs.wrong"]);
throw _dev.error("fastjs/dom/Dom", "el is not HTMLElement or string, instead of " + typeof el, [
"constructor(el: Dom | HTMLElement | Element | string, properties?: FastjsDomProps)",
"Dom.constructor",
]);
} else throw "6e2s"
} else {
if (__DEV__) {
throw _dev.error("fastjs/dom/Dom", `el is not **HTMLElement or string**, instead of **${typeof el}**`, [
"*el: ", el,
"properties: ", p,
"constructor(**el: Dom | HTMLElement | Element | string**, properties?: FastjsDomProps)",
"super: ", this
], ["fastjs.right", "fastjs.wrong"]);
}
throw "6e2s"
}

return this;
}
Expand Down Expand Up @@ -270,17 +269,13 @@ class FastjsDom extends FastjsBaseModule<FastjsDom>{
if (el.parentElement === null) {
if (__DEV__) {
let callback = typeof callbackOrTarget === "function" ? callbackOrTarget : undefined;
_dev.warn("fastjs/dom/push", "el.parentElement is null, did you pass the **document object** or is this element **exist in document**?", [
throw _dev.error("fastjs/dom/push", "el.parentElement is null, did you pass the **document object** or is this element **exist in document**?", [
"*el: ", el,
"target: Fastjs.PushTarget." + target,
"clone: " + clone,
"callback: " + callback,
"push<T extends PushTarget>(**el?: HTMLElement | FastjsDomList | Dom**, target?: T, clone?: boolean): PushReturn<T>",
], ["fastjs.warn", "fastjs.warn", "fastjs.wrong"]);
throw _dev.error("fastjs/dom/push", "el.parentElement can't be null", [
"push<T extends PushTarget>(el?: HTMLElement | FastjsDomList | Dom, target?: T, clone?: boolean): PushReturn<T>",
"Dom.push",
])
}
throw "hg42"
}
Expand Down
6 changes: 1 addition & 5 deletions src/request/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ class FastjsRequest extends FastjsBaseModule<FastjsRequest> {
super();

if (__DEV__ && !url) {
_dev.warn("fastjs/request", "A correct url is **required**.", [
throw _dev.error("fastjs/request", "A correct url is **required**.", [
`***url: ${url}`,
"data: ", data,
"config: ", config,
"super: ", this
], ["fastjs.wrong"])
throw _dev.error("fastjs/request", "A correct url is required.", [
"constructor(public url: string, public data: data = {}, config: Partial<requestConfig> = {})",
"FastjsRequest.constructor"
]);
}

this.config = {
Expand Down

0 comments on commit 1c1dec7

Please sign in to comment.