Skip to content

Commit

Permalink
perf: remove lamda and bind() from templates
Browse files Browse the repository at this point in the history
fix #346
  • Loading branch information
adrianschmidt committed Sep 10, 2019
1 parent 60646df commit 7c33d6b
Show file tree
Hide file tree
Showing 57 changed files with 1,123 additions and 697 deletions.
11 changes: 7 additions & 4 deletions src/components/chip-set/chip-set.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class ChipSet {
this.handleTextFieldFocus = this.handleTextFieldFocus.bind(this);
this.handleInputBlur = this.handleInputBlur.bind(this);
this.handleTextInput = this.handleTextInput.bind(this);
this.inputFieldOnChange = this.inputFieldOnChange.bind(this);
}

/**
Expand Down Expand Up @@ -257,10 +258,8 @@ export class ChipSet {
onFocus={this.handleTextFieldFocus}
onInput={this.handleTextInput}
// Some browsers emit a change event on input elements, we need to stop
// that event from propagating since we are emiting our own change event
onChange={event => {
event.stopPropagation();
}}
// that event from propagating since we are emitting our own change event
onChange={this.inputFieldOnChange}
/>
</div>
<label
Expand All @@ -282,6 +281,10 @@ export class ChipSet {
);
}

private inputFieldOnChange(event) {
event.stopPropagation();
}

/**
* Enter edit mode when the text field receives focus. When editMode is true, the input element will be visible
* @returns {void}
Expand Down
6 changes: 5 additions & 1 deletion src/components/collapsible-section/collapsible-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ export class CollapsibleSection {
@Event()
private close: EventEmitter<void>;

constructor() {
this.onClick = this.onClick.bind(this);
}

public render() {
return (
<section class={`${this.isOpen ? 'open' : ''}`}>
<header onClick={this.onClick.bind(this)}>
<header onClick={this.onClick}>
<span class="expander">
<svg viewBox="0 0 30 30" width="100%" height="100%">
{(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/date-picker/pickers/MonthPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class MonthPicker extends Picker {
return (
<div
class="datepicker-month"
onClick={() => {
onClick={() => { // tslint:disable-line:jsx-no-lambda prettier
const date = moment([fp.currentYear])
.month(month)
.toDate();
Expand Down
2 changes: 1 addition & 1 deletion src/components/date-picker/pickers/QuarterPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class QuarterPicker extends Picker {
<div
class="datepicker-quarter"
id={`datepicker-quarter-${quarter}`}
onClick={() => {
onClick={() => { // tslint:disable-line:jsx-no-lambda prettier
const date = moment([fp.currentYear])
.quarter(quarter)
.toDate();
Expand Down
2 changes: 1 addition & 1 deletion src/components/date-picker/pickers/YearPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class YearPicker extends Picker {
return (
<div
class="datepicker-year"
onClick={() => {
onClick={() => { // tslint:disable-line:jsx-no-lambda prettier
const date = moment(year).toDate();
fp.setDate(date, true);
fp.close();
Expand Down
4 changes: 4 additions & 0 deletions src/components/icon-button/icon-button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ menu: Components
## Example

<limel-example name="limel-example-icon-button" />

### Toggle State

<limel-example name="limel-example-icon-button-toggle-state" path="icon-button" />
12 changes: 8 additions & 4 deletions src/components/input-field/input-field.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ menu: Components

## Examples

### Input field of type text
### Input Field of Type Text

<limel-example path="input-field" name="limel-example-input-field-text" />

### Input field of type number
#### Multiple Fields Inline

<limel-example path="input-field" name="limel-example-input-field-text-inline" />

### Input Field of Type Number

<limel-example path="input-field" name="limel-example-input-field-number" />

### Input field with completions
### Input Field with Completions

<limel-example
path="input-field"
name="limel-example-input-field-autocomplete"
/>

### Input field with icon action
### Input Field with Icon Action

<limel-example
path="input-field"
Expand Down
32 changes: 22 additions & 10 deletions src/components/input-field/input-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ export class InputField {
@Event()
private action: EventEmitter<void>;

constructor() {
this.handleChange = this.handleChange.bind(this);
this.handleIconKeyPress = this.handleIconKeyPress.bind(this);
this.handleIconClick = this.handleIconClick.bind(this);
this.onFocus = this.onFocus.bind(this);
this.onBlur = this.onBlur.bind(this);
}

public componentDidLoad() {
this.mdcTextField = new MDCTextField(
this.limelInputField.shadowRoot.querySelector('.mdc-text-field')
Expand Down Expand Up @@ -134,13 +142,9 @@ export class InputField {
{this.renderFormattedNumber()}
<input
class="mdc-text-field__input"
onInput={this.handleChange.bind(this)}
onFocus={() => {
this.isFocused = true;
}}
onBlur={() => {
this.isFocused = false;
}}
onInput={this.handleChange}
onFocus={this.onFocus}
onBlur={this.onBlur}
value={this.value}
required={this.required}
disabled={this.disabled}
Expand Down Expand Up @@ -168,15 +172,23 @@ export class InputField {
];
}

private onFocus() {
this.isFocused = true;
}

private onBlur() {
this.isFocused = false;
}

private renderTrailingIcon() {
if (!this.trailingIcon) {
return;
}

return (
<i
onKeyPress={this.handleIconKeyPress.bind(this)}
onClick={this.handleIconClick.bind(this)}
onKeyPress={this.handleIconKeyPress}
onClick={this.handleIconClick}
class="mdc-text-field__icon"
tabindex="0"
role="button"
Expand Down Expand Up @@ -215,7 +227,7 @@ export class InputField {
return (
<li
class="mdc-list-item"
onMouseDown={() => {
onMouseDown={() => { // tslint:disable-line:jsx-no-lambda prettier
this.completionClickHandler(completion);
}}
>
Expand Down
16 changes: 16 additions & 0 deletions src/components/select/select.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,19 @@ menu: Components
When importing Option, see [Import Statements](/#import-statements).

<limel-example name="limel-example-select" />

### Initially Empty

<limel-example name="limel-example-select-initially-empty" path="select" />

### Initially Empty but the Empty Option Cannot Be Reselected

<limel-example name="limel-example-select-initially-empty-required" path="select" />

### Specific Value Preselected

<limel-example name="limel-example-select-preselected" path="select" />

### Changing Available Options

<limel-example name="limel-example-select-change-options" path="select" />
8 changes: 5 additions & 3 deletions src/components/select/test/select.test-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ export class SelectTestWrapper {
@Prop({ mutable: true })
public onChangeLastEventDetails: string;

constructor() {
this.onChange = this.onChange.bind(this);
}

public render() {
return (
<limel-select
label="Favourite Doctor"
value={this.value}
onChange={event => {
this.onChange(event);
}}
onChange={this.onChange}
/>
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/slider/slider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ menu: Components
## Example

<limel-example name="limel-example-slider" />

### With Multiplier

<limel-example name="limel-example-slider-multiplier" path="slider"/>
2 changes: 1 addition & 1 deletion src/examples/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class ButtonExample {
<limel-switch
label={control.label}
value={!!this.props[control.property]}
onChange={event => {
onChange={event => { // tslint:disable-line:jsx-no-lambda prettier
this.props = {
...this.props,
...{
Expand Down
18 changes: 12 additions & 6 deletions src/examples/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class CheckboxExample {

constructor() {
this.changeHandler = this.changeHandler.bind(this);
this.onClickToggleEnabled = this.onClickToggleEnabled.bind(this);
this.onClickToggleChecked = this.onClickToggleChecked.bind(this);
}

public render() {
Expand All @@ -29,15 +31,11 @@ export class CheckboxExample {
/>
<limel-flex-container justify="end">
<limel-button
onClick={() => {
this.disabled = !this.disabled;
}}
onClick={this.onClickToggleEnabled}
label={this.disabled ? 'Enable' : 'Disable'}
/>
<limel-button
onClick={() => {
this.value = !this.value;
}}
onClick={this.onClickToggleChecked}
label="Toggle checked"
/>
</limel-flex-container>
Expand All @@ -49,6 +47,14 @@ export class CheckboxExample {
);
}

private onClickToggleEnabled() {
this.disabled = !this.disabled;
}

private onClickToggleChecked() {
this.value = !this.value;
}

private changeHandler(event) {
this.value = event.detail;
}
Expand Down
20 changes: 12 additions & 8 deletions src/examples/chip-set/chip-set-choice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,30 @@ export class ChipSetChoiceExample {
@State()
private disabled: boolean = false;

constructor() {
this.disabledOnChange = this.disabledOnChange.bind(this);
this.chipSetOnChange = this.chipSetOnChange.bind(this);
}

public render() {
return [
<limel-switch
label="Disabled"
onChange={event => {
return (this.disabled = event.detail);
}}
/>,
<limel-switch label="Disabled" onChange={this.disabledOnChange} />,
<br />,
<br />,
<limel-chip-set
disabled={this.disabled}
type="choice"
onChange={this.handleChange}
onChange={this.chipSetOnChange}
value={this.chips}
/>,
];
}

private handleChange(event) {
private disabledOnChange(event) {
this.disabled = event.detail;
}

private chipSetOnChange(event) {
console.log(event.detail);
}
}
20 changes: 12 additions & 8 deletions src/examples/chip-set/chip-set-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,30 @@ export class ChipSetFilterExample {
@State()
private disabled: boolean = false;

constructor() {
this.disabledOnChange = this.disabledOnChange.bind(this);
this.chipSetOnChange = this.chipSetOnChange.bind(this);
}

public render() {
return [
<limel-switch
label="Disabled"
onChange={event => {
return (this.disabled = event.detail);
}}
/>,
<limel-switch label="Disabled" onChange={this.disabledOnChange} />,
<br />,
<br />,
<limel-chip-set
disabled={this.disabled}
type="filter"
onChange={this.handleChange}
onChange={this.chipSetOnChange}
value={this.chips}
/>,
];
}

private handleChange(event) {
private disabledOnChange(event) {
this.disabled = event.detail;
}

private chipSetOnChange(event) {
console.log(event.detail);
}
}
Loading

0 comments on commit 7c33d6b

Please sign in to comment.