Browse Source

Pull request #1413: 添加inject.js中的描述 && 监听事件方法添加返回值,用来直接解除绑定

Merge in VISUAL/fineui from ~DAILER/fineui:master to master

* commit '943c10699263bfe3089f1158ef583b897721ee6c':
  update inject 描述
  无jira任务 chore: 监听事件方法添加返回值,用来直接解除绑定
  无JIRA任务 chore: 添加inject.js中的描述
es6
parent
commit
d2f1aebfcf
  1. 1
      changelog.md
  2. 13
      src/core/ob.js
  3. 47
      typescript/core/inject.ts
  4. 2
      typescript/core/ob.ts
  5. 5
      typescript/index.ts

1
changelog.md

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

13
src/core/ob.js

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

47
typescript/core/inject.ts

@ -0,0 +1,47 @@
type _module = (xtype: string, cls: any) => void;
type _constant = (xtype: string, cls: any) => void;
type _model = (xtype: string, cls: any) => void;
type _store = (xtype: string, cls: any) => void;
type _service = (xtype: string, cls: any) => void;
type _provider = (xtype: string, cls: any) => void;
interface _modules {
getModule: (type: string) => any;
getAllModules: () => any;
}
interface _constants {
getConstant: (type: string) => any;
}
interface _models {
getModel: (type: string, options?: any) => any;
}
interface _stores {
getStore: (type: string, options?: any) => any;
}
interface _providers {
getProvider: (type: string, options?: any) => any;
}
interface _services {
getService: (type: string, options?: any) => any;
}
export type _inject = {
module: _module;
constant: _constant;
model: _model;
store: _store;
provider: _provider;
service: _service;
Modules: _modules;
Constants: _constants;
Models: _models;
Stores: _stores;
Providers: _providers;
Services: _services;
}

2
typescript/core/ob.ts

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

5
typescript/index.ts

@ -36,6 +36,7 @@ import { _i18n } from "./core/i18n";
import { _Plugin } from "./core/plugin"; import { _Plugin } from "./core/plugin";
import { _OB } from "./core/ob"; import { _OB } from "./core/ob";
import { _Widget, _WidgetStatic } from "./core/widget"; import { _Widget, _WidgetStatic } from "./core/widget";
import { _inject } from "./core/inject";
import { _Layout } from "./core/wrapper/layout"; import { _Layout } from "./core/wrapper/layout";
import { _AbsoluteLayout } from "./core/wrapper/layout/layout.absolute"; import { _AbsoluteLayout } from "./core/wrapper/layout/layout.absolute";
import { _HTapeLayout, _VTapeLayout } from "./core/wrapper/layout/layout.tape"; import { _HTapeLayout, _VTapeLayout } from "./core/wrapper/layout/layout.tape";
@ -49,9 +50,9 @@ type ClassConstructor<T extends {}> = T & {
readonly prototype: T; readonly prototype: T;
} }
export interface BI extends _func, _i18n, _base { export interface BI extends _func, _i18n, _base, _inject {
OB: ClassConstructor<_OB>; OB: ClassConstructor<_OB>;
Plugin:_Plugin; Plugin: _Plugin;
Widget: ClassConstructor<_Widget> & _WidgetStatic; Widget: ClassConstructor<_Widget> & _WidgetStatic;
Single: ClassConstructor<_Single>; Single: ClassConstructor<_Single>;
BasicButton: ClassConstructor<_BasicButton> & _BasicButtonStatic; BasicButton: ClassConstructor<_BasicButton> & _BasicButtonStatic;

Loading…
Cancel
Save