From b0264ef876680225724b137163bf6fac10fab53f Mon Sep 17 00:00:00 2001 From: zsmj1994 Date: Fri, 24 Jul 2020 15:23:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20chore:=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0inject.js=E4=B8=AD=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typescript/core/inject.ts | 47 +++++++++++++++++++++++++++++++++++++++ typescript/index.ts | 5 +++-- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 typescript/core/inject.ts diff --git a/typescript/core/inject.ts b/typescript/core/inject.ts new file mode 100644 index 0000000000..29d77b3280 --- /dev/null +++ b/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; +} diff --git a/typescript/index.ts b/typescript/index.ts index a9243f40ca..ed9f792153 100644 --- a/typescript/index.ts +++ b/typescript/index.ts @@ -36,6 +36,7 @@ import { _i18n } from "./core/i18n"; import { _Plugin } from "./core/plugin"; import { _OB } from "./core/ob"; import { _Widget, _WidgetStatic } from "./core/widget"; +import { _inject } from "./core/inject"; import { _Layout } from "./core/wrapper/layout"; import { _AbsoluteLayout } from "./core/wrapper/layout/layout.absolute"; import { _HTapeLayout, _VTapeLayout } from "./core/wrapper/layout/layout.tape"; @@ -49,9 +50,9 @@ type ClassConstructor = T & { readonly prototype: T; } -export interface BI extends _func, _i18n, _base { +export interface BI extends _func, _i18n, _base, _inject { OB: ClassConstructor<_OB>; - Plugin:_Plugin; + Plugin: _Plugin; Widget: ClassConstructor<_Widget> & _WidgetStatic; Single: ClassConstructor<_Single>; BasicButton: ClassConstructor<_BasicButton> & _BasicButtonStatic; From 2cec4e2691ce76b6d6ac107b9070a892155ef69c Mon Sep 17 00:00:00 2001 From: zsmj1994 Date: Fri, 24 Jul 2020 15:34:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=20chore:=20?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E4=BA=8B=E4=BB=B6=E6=96=B9=E6=B3=95=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=BF=94=E5=9B=9E=E5=80=BC,=E7=94=A8=E6=9D=A5?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=A7=A3=E9=99=A4=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 + src/core/ob.js | 13 +++++++++---- typescript/core/ob.ts | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 4555f53dab..ead4d92ef0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2020-07) +- BI.OB的on方法返回一个解除监听的函数 - 修复了grid_view执行_unMount时不调用子组件的_unMount的问题 - combo新增belowMouse属性,允许popup在点击处弹出 - combo新增hideWhenAnotherComboOpen属性,开启则其他combo下拉时当前combo收起 diff --git a/src/core/ob.js b/src/core/ob.js index ed8ac87446..9dc8b99592 100644 --- a/src/core/ob.js +++ b/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 = {}; }, /** * 触发绑定过的事件 diff --git a/typescript/core/ob.ts b/typescript/core/ob.ts index 16ce71024d..88f89968e7 100644 --- a/typescript/core/ob.ts +++ b/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; From 943c10699263bfe3089f1158ef583b897721ee6c Mon Sep 17 00:00:00 2001 From: zsmj1994 Date: Fri, 24 Jul 2020 16:58:10 +0800 Subject: [PATCH 3/3] =?UTF-8?q?update=20inject=20=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typescript/core/inject.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/typescript/core/inject.ts b/typescript/core/inject.ts index 29d77b3280..3852fe4427 100644 --- a/typescript/core/inject.ts +++ b/typescript/core/inject.ts @@ -15,19 +15,19 @@ interface _constants { } interface _models { - getModel: (type: string, options: any) => any; + getModel: (type: string, options?: any) => any; } interface _stores { - getStore: (type: string, options: any) => any; + getStore: (type: string, options?: any) => any; } interface _providers { - getProvider: (type: string, options: any) => any; + getProvider: (type: string, options?: any) => any; } interface _services { - getService: (type: string, options: any) => any; + getService: (type: string, options?: any) => any; }