* @function LevelRenderer.Eventful.prototype.dispatch * @description 事件分发。 * @param {string} type - 事件类型。 * @returns {LevelRenderer.Eventful} this
(type)
| 146 | * @returns {LevelRenderer.Eventful} this |
| 147 | */ |
| 148 | dispatch(type) { |
| 149 | if (this._handlers[type]) { |
| 150 | var args = arguments; |
| 151 | var argLen = args.length; |
| 152 | |
| 153 | if (argLen > 3) { |
| 154 | args = Array.prototype.slice.call(args, 1); |
| 155 | } |
| 156 | |
| 157 | var _h = this._handlers[type]; |
| 158 | var len = _h.length; |
| 159 | for (var i = 0; i < len;) { |
| 160 | // Optimize advise from backbone |
| 161 | switch (argLen) { |
| 162 | case 1: |
| 163 | _h[i]['h'].call(_h[i]['ctx']); |
| 164 | break; |
| 165 | case 2: |
| 166 | _h[i]['h'].call(_h[i]['ctx'], args[1]); |
| 167 | break; |
| 168 | case 3: |
| 169 | _h[i]['h'].call(_h[i]['ctx'], args[1], args[2]); |
| 170 | break; |
| 171 | default: |
| 172 | // have more than 2 given arguments |
| 173 | _h[i]['h'].apply(_h[i]['ctx'], args); |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | if (_h[i]['one']) { |
| 178 | _h.splice(i, 1); |
| 179 | len--; |
| 180 | } else { |
| 181 | i++; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return this; |
| 187 | } |
| 188 | |
| 189 | |
| 190 | /** |
no outgoing calls
no test coverage detected