Commit 0f076091 by hank

修复event tslint

parent 4241bbb7
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
"dev:tt": "npm run build:tt -- --watch", "dev:tt": "npm run build:tt -- --watch",
"dev:h5": "npm run build:h5 -- --watch", "dev:h5": "npm run build:h5 -- --watch",
"dev:rn": "npm run build:rn -- --watch", "dev:rn": "npm run build:rn -- --watch",
"precommit": "npm run lint",
"lint": "tslint --project ./tsconfig.json && stylelint \"./src/**/*.scss\"", "lint": "tslint --project ./tsconfig.json && stylelint \"./src/**/*.scss\"",
"run:shell": "cd ../taro-native-shell/ && yarn android" "run:shell": "cd ../taro-native-shell/ && yarn android"
}, },
......
// tslint:disable:no-invalid-this
// tslint:disable-next-line:only-arrow-functions
const EventBus = (function() { const EventBus = (function() {
function EventBusClass() { function EventBusClass() {
this.msgQueues = {} this.msgQueues = {}
...@@ -18,6 +20,7 @@ const EventBus = (function() { ...@@ -18,6 +20,7 @@ const EventBus = (function() {
// 消息队列中仅保存一个消息 // 消息队列中仅保存一个消息
one: function(msgName, func) { one: function(msgName, func) {
// 无需检查msgName是否存在 // 无需检查msgName是否存在
this.msgQueues[msgName] = func this.msgQueues[msgName] = func
}, },
// 发送消息 // 发送消息
...@@ -25,6 +28,7 @@ const EventBus = (function() { ...@@ -25,6 +28,7 @@ const EventBus = (function() {
if (!this.msgQueues.hasOwnProperty(msgName)) { if (!this.msgQueues.hasOwnProperty(msgName)) {
return return
} }
if (typeof this.msgQueues[msgName] === 'function') { if (typeof this.msgQueues[msgName] === 'function') {
this.msgQueues[msgName](msg) this.msgQueues[msgName](msg)
} else { } else {
...@@ -39,11 +43,12 @@ const EventBus = (function() { ...@@ -39,11 +43,12 @@ const EventBus = (function() {
if (!this.msgQueues.hasOwnProperty(msgName)) { if (!this.msgQueues.hasOwnProperty(msgName)) {
return return
} }
delete this.msgQueues[msgName] delete this.msgQueues[msgName]
} }
} }
var EventBus = new EventBusClass() let Event = new EventBusClass()
return EventBus return Event
})() })()
export default EventBus export default EventBus
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment