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(series): fix series data type judgment bug. close #14293 #14413

Merged
merged 4 commits into from
Mar 8, 2021
Merged

fix(series): fix series data type judgment bug. close #14293 #14413

merged 4 commits into from
Mar 8, 2021

Conversation

leosxie
Copy link
Contributor

@leosxie leosxie commented Mar 6, 2021

Brief Information

fix series data type judgment bug

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

fix series data type judgment bug, typeof null === "object"

Fixed issues

#14293

Details

when set

Before: What was the problem?

image
when rawItem is null, get prop selected error

After: How is it fixed in this PR?

image

Usage

Are there any API changes?

  • The API has been changed.

Related test cases or examples to use the new APIs

test/line-non-continuous.html

Others

Merging options

  • Please squash the commits into a single one when merge.

Other information

@echarts-bot
Copy link

echarts-bot bot commented Mar 6, 2021

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

if (typeof rawItem === 'object'
&& (rawItem as OptionDataItemObject<unknown>).selected
if (zrUtil.isObject(rawItem)
&& (rawItem as OptionDataItemObject<unknown>)?.selected
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional chaining will be transpiled to

rawItem === null || rawItem === void 0 ? void 0 : rawItem.selected;

and brings extra codes in the final distribution.

So we limited the use of optional chaining in echarts to keep the distribution as small as possible.

Instead

(rawItem && (rawItem as OptionDataItemObject<unknown>).selected)

is enough here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get it

Copy link
Contributor Author

@leosxie leosxie Mar 8, 2021

Choose a reason for hiding this comment

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

use zrUtil.isObject(rawItem) replace in here may be more safe?@pissang

@@ -575,8 +575,7 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> extends ComponentMode
if (data.hasItemOption) {
data.each(function (idx) {
const rawItem = data.getRawDataItem(idx);
if (typeof rawItem === 'object'
&& (rawItem as OptionDataItemObject<unknown>).selected
if (rawItem && (rawItem as OptionDataItemObject<unknown>).selected
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to newline here for a better code style.

if (rawItem && (rawItem as OptionDataItemObject<unknown>).selected) {

@@ -0,0 +1,693 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should not be committed

@pissang pissang merged commit 13f1f03 into apache:master Mar 8, 2021
@echarts-bot
Copy link

echarts-bot bot commented Mar 8, 2021

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants