Browse Source

无jira任务 chore: 监听事件方法添加返回值,用来直接解除绑定

master
zsmj1994 4 years ago
parent
commit
2cec4e2691
  1. 1
      changelog.md
  2. 13
      src/core/ob.js
  3. 2
      typescript/core/ob.ts

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志
2.0(2020-07)
- BI.OB的on方法返回一个解除监听的函数
- 修复了grid_view执行_unMount时不调用子组件的_unMount的问题
- combo新增belowMouse属性,允许popup在点击处弹出
- combo新增hideWhenAnotherComboOpen属性,开启则其他combo下拉时当前combo收起

13
src/core/ob.js

@ -1,5 +1,5 @@
!(function () {
function extend () {
function extend() {
var target = arguments[0] || {}, length = arguments.length, i = 1, options, name, src, copy;
for (; i < length; i++) {
// Only deal with non-null/undefined values
@ -86,8 +86,8 @@
},
_getEvents: function () {
if (!_.isArray(this.events)) {
this.events = [];
if (!_.isObject(this.events)) {
this.events = {};
}
return this.events;
},
@ -98,6 +98,7 @@
* @param {Function} fn 事件对应的执行函数
*/
on: function (eventName, fn) {
var self = this;
eventName = eventName.toLowerCase();
var fns = this._getEvents()[eventName];
if (!_.isArray(fns)) {
@ -105,6 +106,10 @@
this._getEvents()[eventName] = fns;
}
fns.push(fn);
return function () {
self.un(eventName, fn);
};
},
/**
@ -148,7 +153,7 @@
*/
purgeListeners: function () {
/* alex:清空events*/
this.events = [];
this.events = {};
},
/**
* 触发绑定过的事件

2
typescript/core/ob.ts

@ -19,7 +19,7 @@ export interface _OB {
_getEvents(): { [eventName: string]: Function[] };
on(eventName: string, fn: Function): void;
on(eventName: string, fn: Function): Function;
once(eventName: string, fn: Function): void;

Loading…
Cancel
Save