emberjs / emberjs/ember-render-modifiers

Improve the error message when `this` is undefined

Open
#17 8 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
86
Forks
34
PR merge metrics
No merged PRs in 30d

Description

If you try to use `this` within methods called by `{{on}}` and `{{fn}}`, they show a helpful error instructing the developer to use the `@action` decorator. The render modifiers could show something like that too.

Here's an example "error" use case for `did-insert`:

```


```

```
import Component from '@glimmer/component';

export default class CodeEditor extends Component {
renderEditor(el) {
console.log(this.args.code)
}
}
```

> TypeError: this is undefined

`{{fn}}` uses this error message:
> You accessed `this.arg2` from a function passed to the `fn` helper, but the function itself was not bound to a valid `this` context. Consider updating to usage of `@action`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.