Skip to content

Commit

Permalink
plugin event will not be triggered until plugin is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Maizify committed Jan 2, 2018
1 parent cb8d301 commit a09c104
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
English | [简体中文](./CHANGELOG_CN.md)

#### V3.1.1-dev (2018-01-xx)

- [FIX] Fix `setOption()` error.


#### V3.1.0 (2017-12-27)

- [FEATURE] Add `vConsole.showSwitch()` and `vConsole.hideSwitch()` methods, see [Public Properties & Methods](./doc/public_properties_methods.md).
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG_CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[English](./CHANGELOG.md) | 简体中文

#### V3.1.1 (2018-01-xx)

- 【修复】修复初始化后立即调用 `setOption` 引起的错误。


#### V3.1.0 (2017-12-27)

- 【特性】新增 `vConsole.showSwitch()``vConsole.hideSwitch()` 方法,请查阅[公共属性及方法](./doc/public_properties_methods_CN.md)
Expand Down
8 changes: 4 additions & 4 deletions dist/vconsole.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions example/demo1.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ <h1 class="page_title">Demo 1</h1>
defaultPlugins: ['system', 'network', 'element', 'storage'], // 可以在此设定要默认加载的面板
maxLogNumber: 1000,
onReady: function() {
// console.log('vConsole is ready.');
console.log('vConsole is ready.');
},
onClearLog: function() {
// console.log('on clearLog');
console.log('on clearLog');
}
});


console.info('欢迎使用 vConsole。vConsole 是一个由微信公众平台前端团队研发的 Web 前端开发者面板,可用于展示 console 日志,方便开发、调试。');

$('.js_btn_log').on('tap', function(e) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vconsole",
"version": "3.1.0",
"version": "3.1.1-dev",
"description": "A lightweight, extendable front-end developer tool for mobile web page.",
"homepage": "https://github.com/Tencent/vConsole",
"main": "dist/vconsole.min.js",
Expand Down
10 changes: 7 additions & 3 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ class VConsole {
*/
_initPlugin(plugin) {
let that = this;
console.debug('_initPlugin');
plugin.vConsole = this;
// start init
plugin.trigger('init');
Expand Down Expand Up @@ -496,6 +497,7 @@ class VConsole {
}
});
// end init
plugin.isReady = true;
plugin.trigger('ready');
}

Expand All @@ -505,7 +507,9 @@ class VConsole {
*/
_triggerPluginsEvent(eventName) {
for (let id in this.pluginList) {
this.pluginList[id].trigger(eventName);
if (this.pluginList[id].isReady) {
this.pluginList[id].trigger(eventName);
}
}
}

Expand All @@ -515,7 +519,7 @@ class VConsole {
*/
_triggerPluginEvent(pluginName, eventName) {
let plugin = this.pluginList[pluginName];
if (plugin) {
if (!!plugin && plugin.isReady) {
plugin.trigger(eventName);
}
}
Expand Down Expand Up @@ -690,7 +694,7 @@ class VConsole {
$.removeClass($.all('.vc-tool', this.$dom), 'vc-toggle');
$.addClass($.all('.vc-tool-' + tabID, this.$dom), 'vc-toggle');
// trigger plugin event
this._triggerPluginEvent(this.activedTab, 'hide');
this.activedTab && this._triggerPluginEvent(this.activedTab, 'hide');
this.activedTab = tabID;
this._triggerPluginEvent(this.activedTab, 'show');
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class VConsolePlugin {
constructor(id, name = 'newPlugin') {
this.id = id;
this.name = name;

this.isReady = false;

this.eventList = {};
}

Expand Down

0 comments on commit a09c104

Please sign in to comment.