Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update docs and message on template arrow and bind #126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions docs/rules/no-template-arrow.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,31 @@ loss.
Instead, you should do something like so:

```ts
_render() {
return html`<x-foo @event=${this._onClick}>`;
}
class MyElement extends LitElement {
render() {
return html`<x-foo @event=${this._onClick}>`;
}

_onClick() { ... }
_onClick() { ... }
}
```

As lit will automatically bind it to the correct context.
As LitElement will automatically bind event listeners to the correct context, or:

```ts
class MyElement extends LitElement {
constructor () {
super();
this.someFunc = this.someFunc.bind(this);
}

render() {
return html`<x-foo .funcProp=${this.someFunc}>`;
}

someFunc() { ... }
}
```

## Rule Details

Expand Down
26 changes: 22 additions & 4 deletions docs/rules/no-template-bind.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,32 @@ loss.
Instead, you should do something like so:

```ts
_render() {
return html`<x-foo @event=${this._onClick}>`;
class MyElement extends LitElement {
render() {
return html`<x-foo @event=${this._onClick}>`;
}

_onClick() { ... }
}
```

As LitElement will automatically bind event listeners to the correct context, or:

_onClick() { ... }
```ts
class MyElement extends LitElement {
constructor () {
super();
this.someFunc = this.someFunc.bind(this);
}

render() {
return html`<x-foo .funcProp=${this.someFunc}>`;
}

someFunc() { ... }
}
```

As lit will automatically bind it to the correct context.

## Rule Details

Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-template-arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const rule: Rule.RuleModule = {
},
messages: {
noArrow:
'Arrow functions must not be used in templates, ' +
'a method should be passed directly like `${this.myMethod}` as it ' +
'will be bound automatically.'
'Arrow functions should not be used in templates. ' +
'LitElement event bindings are bound automatically, ' +
'otherwise a method/function should be bound outside the render method (e.g. in the constructor) beforehand'
}
},

Expand Down
3 changes: 1 addition & 2 deletions src/rules/no-template-bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const rule: Rule.RuleModule = {
messages: {
noBind:
'`.bind` must not be used in templates, ' +
'a method should be passed directly like `${this.myMethod}` as it ' +
'will be bound automatically.'
'a method should be bound once in the constructor and passed directly like `${this.myMethod}`.'
}
},

Expand Down