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

fix(prop): fix prop.export can not correctly export undefined[] #1912

Merged
merged 1 commit into from
Apr 19, 2023

Conversation

liujuping
Copy link
Collaborator

该 PR,为了解决 loopArgs不返回[undefined, undefined],但是会导致需要设置 prop value 为 undefined[] 类型的设置器,无法获取正确的值。

https://github.com/alibaba/lowcode-engine/pull/141/files

Closes #1891

@github-actions
Copy link

ChatGPT Code Review:

CodeReview:

根据 diff,代码移除了一个 if 需要关注下这个分支的逻辑,这段逻辑的主要目的是判断是否所有的 items 的值都是 undefined,如果是,则返回 undefined。

如果把 map 的返回值直接返回,是合法的逻辑,因为如果没有 items,子项没有被添加,值就直接返回 value 的内容。但如果 map 的结果中只有 undefined,此时需要根据 if 的逻辑进行返回。

修改建议:

  1. 做到 if 的分支目的在代码上也有体现
export class Prop implements IProp, IPropParent {
  // ......
  getValue(stage?: PropExportStage) {
    if (!this._items) {
      return this._value;
    }

    const values = this.items!.map((prop) => {
      return prop?.export(stage);
    });

    const everyValueAreUndefined = values.every((val) => val === undefined)
    if (everyValueAreUndefined) {
      return undefined;
    } else {
      return values;
    }
  }
}
  1. 尽可能使用 typeof 和 strict comparison 来做,以避免因为类型不同的隐式转换引入的错误
export class Prop implements IProp, IPropParent {
  // ...
  getValue(stage?: PropExportStage) {
    if (!this._items) {
      return this._value;
    }

    const values = this.items!.map((prop) => {
      return prop?.export(stage);
    });

    if (typeof values[0] === 'undefined' &&
      values.every((value) => value === values[0])) {
      return undefined;
    } else {
      return values;
    }
  }
}

Commit Message:fix(Prop): fix Prop.getValue can not correctly export undefined values。根据 Angular 规范,CommitMessage 包含以下三个部分:

  • 类型: fix
  • 文件路径: Prop
  • 简要说明: fix Prop.getValue can not correctly export undefined values

@github-actions
Copy link

Coverage report for packages/utils

St.
Category Percentage Covered / Total
🔴 Statements 48.18% 119/247
🔴 Branches 42.64% 113/265
🔴 Functions 41.03% 32/78
🔴 Lines 49.36% 115/233

Test suite run success

32 tests passing in 5 suites.

Report generated by 🧪jest coverage report action from f51c700

@github-actions
Copy link

Coverage report for packages/renderer-core

St.
Category Percentage Covered / Total
🟡 Statements 71.95% 908/1262
🟡 Branches 61.23% 567/926
🟡 Functions 69.12% 197/285
🟡 Lines 71.94% 892/1240

Test suite run success

91 tests passing in 8 suites.

Report generated by 🧪jest coverage report action from f51c700

@github-actions
Copy link

Coverage report for packages/react-simulator-renderer

St.
Category Percentage Covered / Total
🔴 Statements 33.63% 114/339
🔴 Branches 14.88% 25/168
🔴 Functions 26.14% 23/88
🔴 Lines 34.23% 114/333

Test suite run success

2 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from f51c700

@github-actions
Copy link

Coverage report for packages/designer

St.
Category Percentage Covered / Total
🟢 Statements
96.34% (-0% 🔻)
2842/2950
🟢 Branches
88.83% (-0.01% 🔻)
1630/1835
🟢 Functions
95.97% (-0% 🔻)
858/894
🟢 Lines
96.41% (-0% 🔻)
2769/2872
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / prop.ts
99.32% (-0.01% 🔻)
92.19% (-0.06% 🔻)
100%
99.31% (-0.01% 🔻)

Test suite run success

370 tests passing in 42 suites.

Report generated by 🧪jest coverage report action from f51c700

@JackLian JackLian merged commit dff06e7 into develop Apr 19, 2023
@JackLian JackLian deleted the fix/prop-list-undefined branch April 19, 2023 07:55
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