Skip to content
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

Merged
merged 2 commits into from
Aug 7, 2023
Merged

Conversation

shrinktofit
Copy link
Contributor

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

Comment on lines +35 to +40
export type Unpacker = (
packUuid: string[],
data: any,
options: Record<string, any>,
onComplete: ((err: Error | null, data?: any) => void),
) => void;
Copy link
Contributor Author

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);
Copy link
Contributor Author

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 (
Copy link
Contributor Author

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);
Copy link
Contributor Author

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]);
Copy link
Contributor Author

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);
Copy link
Contributor Author

@shrinktofit shrinktofit Aug 4, 2023

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 (
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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));
Copy link
Contributor Author

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer explicit assertion.

@SantyWang SantyWang merged commit b42a2fa into cocos:v3.8.1 Aug 7, 2023
10 checks passed
@shrinktofit shrinktofit deleted the PackManager branch August 8, 2023 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants