You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/02/19 12:11:49 UTC
[incubator-echarts] 01/02: fix: rollback previous commit about
Model only support object becuase of performance drops
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch typescript
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit bfa66493bce54bb1ed5e58310576f089d22e750b
Author: pissang <bm...@gmail.com>
AuthorDate: Wed Feb 19 17:01:47 2020 +0800
fix: rollback previous commit about Model only support object becuase of performance drops
---
src/data/List.ts | 4 ----
src/model/Model.ts | 15 ++++++++++++---
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/data/List.ts b/src/data/List.ts
index 5f8dd2e..0f2f93c 100644
--- a/src/data/List.ts
+++ b/src/data/List.ts
@@ -1555,13 +1555,9 @@ class List {
/**
* Get model of one data item.
*/
- // FIXME Model proxy ?
getItemModel(idx: number): Model {
var hostModel = this.hostModel;
var dataItem = this.getRawDataItem(idx) as ModelOption;
- if (this._rawData.pure || !isDataItemOption(dataItem)) {
- dataItem = { value: dataItem };
- }
return new Model(dataItem, hostModel, hostModel && hostModel.ecModel);
}
diff --git a/src/model/Model.ts b/src/model/Model.ts
index e9f3351..1925620 100644
--- a/src/model/Model.ts
+++ b/src/model/Model.ts
@@ -42,6 +42,14 @@ import { Dictionary } from 'zrender/src/core/types';
var mixin = zrUtil.mixin;
var inner = makeInner();
+// Since model.option can be not only `Dictionary` but also primary types,
+// we do this conditional type to avoid getting type 'never';
+type Key<Opt> = Opt extends Dictionary<any>
+ ? keyof Opt : string;
+type Value<Opt, R> = Opt extends Dictionary<any>
+ ? (R extends keyof Opt ? Opt[R] : ModelOption)
+ : ModelOption;
+
/**
* @alias module:echarts/model/Model
* @constructor
@@ -132,11 +140,12 @@ class Model<Opt extends ModelOption = ModelOption> {
): Opt[R] {
var option = this.option;
- var val: Opt[R] = option == null ? null : option[key];
+ var val = option == null ? option : option[key];
if (val == null) {
var parentModel = !ignoreParent && getParent(this, key as string);
if (parentModel) {
- val = (parentModel as Model<Opt>).getShallow(key);
+ // FIXME:TS do not know how to make it works
+ val = parentModel.getShallow(key);
}
}
return val;
@@ -229,7 +238,7 @@ function doGet(obj: ModelOption, pathArr: string[], parentModel?: Model<Dictiona
continue;
}
// obj could be number/string/... (like 0)
- obj = obj[pathArr[i]];
+ obj = (obj && typeof obj === 'object') ? obj[pathArr[i] as keyof ModelOption] : null;
if (obj == null) {
break;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org