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 2021/10/04 05:36:24 UTC
[echarts] branch svg-ssr updated: fix(class): optimize native class
mixed with legacy class extend.
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch svg-ssr
in repository https://gitbox.apache.org/repos/asf/echarts.git
The following commit(s) were added to refs/heads/svg-ssr by this push:
new 116b245 fix(class): optimize native class mixed with legacy class extend.
116b245 is described below
commit 116b245d2388434e3a9813bb5e3d87cb88f4fc01
Author: pissang <bm...@gmail.com>
AuthorDate: Mon Oct 4 13:34:46 2021 +0800
fix(class): optimize native class mixed with legacy class extend.
---
src/util/clazz.ts | 48 ++++++++++++++++++++++--------------------------
src/view/Chart.ts | 6 +++++-
2 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/util/clazz.ts b/src/util/clazz.ts
index e9f29b2..13532ba 100644
--- a/src/util/clazz.ts
+++ b/src/util/clazz.ts
@@ -91,40 +91,36 @@ export function enableClassExtend(rootClz: ExtendableConstructor, mandatoryMetho
}
const superClass = this;
- // For backward compat, we both support ts class inheritance and this
- // "extend" approach.
- // The constructor should keep the same behavior as ts class inheritance:
- // If this constructor/$constructor is not declared, auto invoke the super
- // constructor.
- // If this constructor/$constructor is declared, it is responsible for
- // calling the super constructor.
- function ExtendedClass(this: any, ...args: any[]) {
- if (!proto.$constructor) {
-
- if (!isESClass(superClass)) {
- // Will throw error if superClass is an es6 native class.
- superClass.apply(this, arguments);
- }
- else {
- const ins = zrUtil.createObject(
- // @ts-ignore
- ExtendedClass.prototype, new superClass(...args)
- );
- return ins;
+ let ExtendedClass: any;
+
+ if (isESClass(superClass)) {
+ ExtendedClass = class extends superClass {
+ constructor() {
+ super(...arguments as any);
}
- }
- else {
- proto.$constructor.apply(this, arguments);
- }
+ };
+ }
+ else {
+ // For backward compat, we both support ts class inheritance and this
+ // "extend" approach.
+ // The constructor should keep the same behavior as ts class inheritance:
+ // If this constructor/$constructor is not declared, auto invoke the super
+ // constructor.
+ // If this constructor/$constructor is declared, it is responsible for
+ // calling the super constructor.
+ ExtendedClass = function (this: any) {
+ (proto.$constructor || superClass).apply(this, arguments);
+ };
+
+ zrUtil.inherits(ExtendedClass, this);
}
- ExtendedClass[IS_EXTENDED_CLASS] = true;
zrUtil.extend(ExtendedClass.prototype, proto);
+ ExtendedClass[IS_EXTENDED_CLASS] = true;
ExtendedClass.extend = this.extend;
ExtendedClass.superCall = superCall;
ExtendedClass.superApply = superApply;
- zrUtil.inherits(ExtendedClass, this);
ExtendedClass.superClass = superClass;
return ExtendedClass as unknown as ExtendableConstructor;
diff --git a/src/view/Chart.ts b/src/view/Chart.ts
index 8f32838..b31253b 100644
--- a/src/view/Chart.ts
+++ b/src/view/Chart.ts
@@ -146,7 +146,11 @@ class ChartView {
init(ecModel: GlobalModel, api: ExtensionAPI): void {}
- render(seriesModel: SeriesModel, ecModel: GlobalModel, api: ExtensionAPI, payload: Payload): void {}
+ render(seriesModel: SeriesModel, ecModel: GlobalModel, api: ExtensionAPI, payload: Payload): void {
+ if (__DEV__) {
+ throw new Error('render method must been implemented');
+ }
+ }
/**
* Highlight series or specified data item.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org