Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
feat(event): 调整事件触发时机,分离 render、update 事件
Browse files Browse the repository at this point in the history
  • Loading branch information
liuwei committed Aug 20, 2019
1 parent c50bbea commit 99e06b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
32 changes: 20 additions & 12 deletions src/libs/core/amap-echarts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,28 @@ export default class AMapEcharts extends events {
AMapEcharts._configs.theme,
AMapEcharts._configs.opts
)
this._amapContainer.setRender(this._redener.bind(this))
this._amapContainer.setRender(this._render.bind(this))
// 内部重绘事件
this.on(EventName.__REDENER__, this._redener.bind(this))
this.emit(EventName.INIT)
this.on(EventName.__UPDATE__, this._update.bind(this))
this._execPlugin(PluginType.INIT)
// 如果已经 setOption ,则需要调用插件
if (this._cachedOptions) {
this._execPlugin(PluginType.UPDATE)
}
this.emit(EventName.INIT)
}

_redener() {
this._execPlugin(PluginType.REDENER)
_render() {
this._execPlugin(PluginType.RENDER)
// this._instance.resize()
this._instance.setOption(this._cachedOptions)
this.emit(EventName.REDENER)
this.emit(EventName.RENDER)
}

_update() {
this._execPlugin(PluginType.UPDATE)
this._instance.setOption(this._cachedOptions)
this.emit(EventName.UPDATE)
}

_execPlugin(type) {
Expand Down Expand Up @@ -159,16 +170,12 @@ export default class AMapEcharts extends events {
..._cachedOptions,
getMap: () => this._amapContainer.getMap()
}
this._execPlugin(PluginType.UPDATE)
// 触发内部重绘事件
this.emit(EventName.__REDENER__)
this.emit(EventName.UPDATE)
// 触发内部更新事件
this.emit(EventName.__UPDATE__)
}

dispose() {
this.emit(EventName.DESTROY)
this._execPlugin(PluginType.DESTROY)

this._disposed = true
if (this._instance) {
this._instance.dispose()
Expand All @@ -177,6 +184,7 @@ export default class AMapEcharts extends events {
this.removeAllListeners()
}
this._clear()
this.emit(EventName.DESTROY)
}

isDisposed() {
Expand Down
8 changes: 4 additions & 4 deletions src/libs/core/amap-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* 事件名称,带下划线的表示内部使用
*/
const EventName = {
// 内部重绘监听
__REDENER__: '__reRedener__',
// 内部更新事件
__UPDATE__: '__UPDATE__',
// 高德地图插件加载完毕,第一次绘制完成
INIT: 'init',
// 地图移动、缩放、__REDENER__ 事件导致的重绘事件
REDENER: 'redener',
// 地图移动、缩放的重绘事件
RENDER: 'render',
// 调用 setOption 方法
UPDATE: 'update',
// 调用 dispose 方法
Expand Down

0 comments on commit 99e06b7

Please sign in to comment.