Skip to content

Commit 48b6b37

Browse files
committed
refactor: Combine _initialOptions and _optionsToUpdate
1 parent 2a54986 commit 48b6b37

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/core/component.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import {
1818
} from './nested-option';
1919

2020
export abstract class DxComponent implements AfterViewInit, AfterContentChecked, INestedOptionContainer, ICollectionNestedOptionContainer {
21-
private _initialOptions: any;
22-
private _optionToUpdate: any;
21+
private _optionToUpdate: any = {};
2322
private _collectionContainerImpl: ICollectionNestedOptionContainer;
2423
eventHelper: EmitterHelper;
2524
templates: DxTemplateDirective[];
@@ -35,12 +34,12 @@ export abstract class DxComponent implements AfterViewInit, AfterContentChecked,
3534
this.templates.forEach(template => {
3635
initialTemplates[template.name] = template;
3736
});
38-
this._initialOptions.integrationOptions.templates = initialTemplates;
37+
this._optionToUpdate.integrationOptions.templates = initialTemplates;
3938
}
4039
}
4140
private _initOptions() {
42-
this._initialOptions.eventsStrategy = this.eventHelper.strategy;
43-
this._initialOptions.integrationOptions.watchMethod = this.watcherHelper.getWatchMethod();
41+
this._optionToUpdate.eventsStrategy = this.eventHelper.strategy;
42+
this._optionToUpdate.integrationOptions.watchMethod = this.watcherHelper.getWatchMethod();
4443
}
4544
protected _createEventEmitters(events) {
4645
events.forEach(event => {
@@ -57,20 +56,11 @@ export abstract class DxComponent implements AfterViewInit, AfterContentChecked,
5756
return true;
5857
}
5958
protected _getOption(name: string) {
60-
if (this.instance) {
61-
return this.instance.option(name);
62-
} else {
63-
return this._initialOptions[name];
64-
}
59+
return this.instance ?
60+
this.instance.option(name) :
61+
this._optionToUpdate[name];
6562
}
6663
protected _setOption(name: string, value: any) {
67-
if (this.instance) {
68-
this._prepareOptionToUpdate(name, value);
69-
} else {
70-
this._initialOptions[name] = value;
71-
}
72-
}
73-
protected _prepareOptionToUpdate(name: string, value: any) {
7464
if (this._shouldOptionChange(name, value)) {
7565
this._optionToUpdate[name] = value;
7666
};
@@ -79,17 +69,19 @@ export abstract class DxComponent implements AfterViewInit, AfterContentChecked,
7969
protected _createWidget(element: any) {
8070
let events = [];
8171

72+
this._optionToUpdate.integrationOptions = {};
8273
this._initTemplates();
8374
this._initOptions();
8475

8576
let optionChangeHandler = function(e) {
8677
events.push(e.name);
8778
};
8879

89-
this._initialOptions.onInitializing = function() {
80+
this._optionToUpdate.onInitializing = function() {
9081
this.on('optionChanged', optionChangeHandler);
9182
};
92-
this.instance = this._createInstance(element, this._initialOptions);
83+
this.instance = this._createInstance(element, this._optionToUpdate);
84+
this._optionToUpdate = {};
9385

9486
this.instance.off('optionChanged', optionChangeHandler);
9587
this.instance.on('optionChanged', (e) => {
@@ -115,8 +107,6 @@ export abstract class DxComponent implements AfterViewInit, AfterContentChecked,
115107
}
116108
}
117109
constructor(protected element: ElementRef, private ngZone: NgZone, templateHost: DxTemplateHost, private watcherHelper: WatcherHelper) {
118-
this._initialOptions = { integrationOptions: {} };
119-
this._optionToUpdate = {};
120110
this.templates = [];
121111
templateHost.setHost(this);
122112
this._collectionContainerImpl = new CollectionNestedOptionContainerImpl(this._setOption.bind(this));

templates/component.tst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ export class <#= it.className #>Component extends <#= baseClass #> <#? implement
148148
this._watcherHelper.checkWatchers();
149149
}
150150

151-
_prepareOptionToUpdate(name: string, value: any) {
151+
_setOption(name: string, value: any) {
152152
if (Array.isArray(value)) {
153153
this._idh.setupSingle(name, value);
154154
this._idh.getChanges(name, value);
155155
}
156156

157-
super._prepareOptionToUpdate(name, value);
157+
super._setOption(name, value);
158158
}<#?#>
159159
<#? it.isEditor #>
160160
ngAfterContentInit() {

0 commit comments

Comments
 (0)