Skip to content

Commit aa95e97

Browse files
Refactoring
1 parent 6e281d0 commit aa95e97

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/core/component.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export abstract class DxComponent implements AfterViewInit, INestedOptionContain
2424
instance: any;
2525
changedOptions = {};
2626
renderOnViewInit = true;
27-
events = {};
28-
ProcessEvent: Function;
2927

3028
protected _events: { subscribe?: string, emit: string }[];
3129

@@ -47,10 +45,6 @@ export abstract class DxComponent implements AfterViewInit, INestedOptionContain
4745
this.eventHelper.createEmitter(event.emit, event.subscribe);
4846
});
4947
}
50-
private optionChangeHandler(e) {
51-
this.changedOptions[e.name] = e.value;
52-
this.ProcessEvent(e);
53-
}
5448
_shouldOptionChange(name: string, value: any) {
5549
if (this.changedOptions.hasOwnProperty(name)) {
5650
const prevValue = this.changedOptions[name];
@@ -82,29 +76,32 @@ export abstract class DxComponent implements AfterViewInit, INestedOptionContain
8276
protected abstract _createInstance(element, options)
8377
protected _createWidget(element: any) {
8478
let that = this;
79+
let events = {};
8580

8681
this._initTemplates();
8782
this._initOptions();
8883

89-
this.ProcessEvent = function(e) {
90-
that.events[e.name + 'Change'] = [e.value];
84+
let optionChangeHandler = function(e) {
85+
events[e.name + 'Change'] = [e.value];
9186
};
9287

9388
this._initialOptions.onInitializing = function() {
94-
this.on('optionChanged', that.optionChangeHandler.bind(that));
89+
this.on('optionChanged', optionChangeHandler);
9590
};
9691
this.instance = this._createInstance(element, this._initialOptions);
9792

98-
this.ProcessEvent = function(e) {
93+
this.instance.off('optionChanged', optionChangeHandler);
94+
this.instance.on('optionChanged', function(e){
95+
that.changedOptions[e.name] = e.value;
9996
that.eventHelper.fireNgEvent(e.name + 'Change', [e.value]);
100-
};
97+
});
10198

10299
let subsriber = this.ngZone.onStable.subscribe(() => {
103100
subsriber.unsubscribe();
104101

105102
that.ngZone.run(() => {
106-
for (let key in that.events) {
107-
that.eventHelper.fireNgEvent(key, that.events[key]);
103+
for (let key in events) {
104+
that.eventHelper.fireNgEvent(key, events[key]);
108105
}
109106
});
110107
});

0 commit comments

Comments
 (0)