-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize pack-manager for style&lint #15872
Conversation
export type Unpacker = ( | ||
packUuid: string[], | ||
data: any, | ||
options: Record<string, any>, | ||
onComplete: ((err: Error | null, data?: any) => void), | ||
) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint problem: too long line
|
||
interface IUnpackRequest { | ||
onComplete: ((err: Error | null, data?: any | null) => void); | ||
onComplete: ((err: Error | null, data?: any) => void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint problem: any | null
is equivalent to any
.
@@ -73,12 +78,17 @@ export class PackManager { | |||
* }); | |||
* | |||
*/ | |||
public unpackJson (pack: string[], json: any, options: Record<string, any>, onComplete: ((err: Error | null, data?: Record<string, any> | null) => void)): void { | |||
let out = js.createMap(true); | |||
public unpackJson ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint problem: too long line
options: Record<string, any>, | ||
onComplete: ((err: Error | null, data?: Record<string, any> | null) => void), | ||
): void { | ||
const out: Record<string, any> = js.createMap(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem: untyped thing.
let err: Error | null = null; | ||
|
||
if (Array.isArray(json)) { | ||
json = unpackJSONs(json as any); | ||
json = unpackJSONs(json as Parameters<typeof unpackJSONs>[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem: type cast
@@ -107,7 +117,8 @@ export class PackManager { | |||
} | |||
} else { | |||
err = new Error('unmatched type pack!'); | |||
out = null; | |||
onComplete(err, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem: if don't do this, the out
should be null | Record<...>
which then causes many assertions in above.
@@ -170,7 +181,13 @@ export class PackManager { | |||
* }); | |||
* | |||
*/ | |||
public unpack (pack: string[], data: any, type: string, options: Record<string, any>, onComplete: ((err: Error | null, data?: any | null) => void)): void { | |||
public unpack ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint problem: too long line
@@ -200,7 +217,7 @@ export class PackManager { | |||
* packManager.load(requestItem, null, (err, data) => console.log(err)); | |||
* | |||
*/ | |||
public load (item: RequestItem, options: Record<string, any> | null, onComplete: ((err: Error | null, data?: any | null) => void)): void { | |||
public load (item: RequestItem, options: Record<string, any> | null, onComplete: ((err: Error | null, data?: any) => void)): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint problem: any | null is equivalent to any.
@@ -215,35 +232,39 @@ export class PackManager { | |||
const packs = item.info.packs; | |||
|
|||
// find a loading package | |||
let pack = packs.find((val): boolean => this._loading.has(val.uuid)); | |||
const loadingPack = packs.find((val): boolean => this._loading.has(val.uuid)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid below from pack!
assertion.
for (let i = 0, l = callbacks!.length; i < l; i++) { | ||
const cb = callbacks![i]; | ||
const callbacks = this._loading.remove(pack.uuid); | ||
assertIsTrue(callbacks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer explicit assertion.
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: