Skip to content

Commit

Permalink
Merge pull request #351 from ghiscoding/feat/editor-to-native-element
Browse files Browse the repository at this point in the history
chore(editors): use optional chaining to remove editor from dom
  • Loading branch information
AnnetteZhang authored May 26, 2021
2 parents 6220216 + 8ac67f5 commit c490dda
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/editors/autoCompleteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class AutoCompleteEditor implements Editor {

/** Get the Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return (this.columnEditor && this.columnEditor.validator) || (this.columnDef && this.columnDef.validator);
return this.columnEditor?.validator ?? this.columnDef?.validator;
}

init() {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/checkboxEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class CheckboxEditor implements Editor {

/** Get the Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return (this.columnEditor && this.columnEditor.validator) || (this.columnDef && this.columnDef.validator);
return this.columnEditor?.validator ?? this.columnDef?.validator;
}

init(): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/dualInputEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class DualInputEditor implements Editor {

/** Get the Shared Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return (this.columnEditor && this.columnEditor.validator) || (this.columnDef && this.columnDef.validator);
return this.columnEditor?.validator ?? this.columnDef?.validator;
}

init() {
Expand Down
10 changes: 2 additions & 8 deletions packages/common/src/editors/floatEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class FloatEditor implements Editor {

/** Get the Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return (this.columnEditor && this.columnEditor.validator) || (this.columnDef && this.columnDef.validator);
return this.columnEditor?.validator ?? this.columnDef?.validator;
}

init() {
Expand Down Expand Up @@ -117,13 +117,7 @@ export class FloatEditor implements Editor {

destroy() {
this._bindEventService.unbindAll();
if (this._input) {
setTimeout(() => {
if (this._input) {
this._input.remove();
}
});
}
this._input?.remove?.();
}

disable(isDisabled = true) {
Expand Down
13 changes: 3 additions & 10 deletions packages/common/src/editors/integerEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class IntegerEditor implements Editor {

/** Get the Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return (this.columnEditor && this.columnEditor.validator) || (this.columnDef && this.columnDef.validator);
return this.columnEditor?.validator ?? this.columnDef?.validator;
}

init() {
Expand Down Expand Up @@ -114,15 +114,8 @@ export class IntegerEditor implements Editor {
}

destroy() {
if (this._input) {
this._bindEventService.unbindAll();
setTimeout(() => {
if (this._input) {
this._input.remove();
this._input = undefined;
}
});
}
this._bindEventService.unbindAll();
this._input?.remove?.();
}

disable(isDisabled = true) {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/selectEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class SelectEditor implements Editor {

/** Get the Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return (this.columnEditor && this.columnEditor.validator) || (this.columnDef && this.columnDef.validator);
return this.columnEditor?.validator ?? this.columnDef?.validator;
}

init() {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/sliderEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class SliderEditor implements Editor {

/** Get the Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return (this.columnEditor && this.columnEditor.validator) || (this.columnDef && this.columnDef.validator);
return this.columnEditor?.validator ?? this.columnDef?.validator;
}

init(): void {
Expand Down
13 changes: 3 additions & 10 deletions packages/common/src/editors/textEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class TextEditor implements Editor {

/** Get the Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return (this.columnEditor && this.columnEditor.validator) || (this.columnDef && this.columnDef.validator);
return this.columnEditor?.validator ?? this.columnDef?.validator;
}

init() {
Expand Down Expand Up @@ -106,15 +106,8 @@ export class TextEditor implements Editor {
}

destroy() {
if (this._input) {
this._bindEventService.unbindAll();
setTimeout(() => {
if (this._input) {
this._input.remove();
this._input = undefined;
}
});
}
this._bindEventService.unbindAll();
this._input?.remove?.();
}

disable(isDisabled = true) {
Expand Down

0 comments on commit c490dda

Please sign in to comment.