ember-cli / ember-cli/eslint-plugin-ember
New Rule: `no-controller-model-reads`
- Dominant language
- JavaScript
- Stars
- 263
- Forks
- 214
- Avg merge
- 30m
- Merged PRs (30d)
- 5
Description
`reads` and `oneWay` are footguns if used in a controller to access a `model` property, because once changed they will no longer update when the `model` for the route changes. The singleton nature of controllers means that once changed, any additional route entries will both need to clear out the stale controller state and the property will no longer reflect the value on the model as expected.
This problem exists in controllers generally, but since properties accessed from services are also part of long-lived singleton state it is unclear that linting against `reads` and `oneWay` in controllers in general would be good. Perhaps a broader lint-against could be done via configuration.
```js
import Controller from '@ember/controller';
import { inject } from '@ember/service';
import { oneWay, reads, readOnly } from '@ember/object/computed';
export default MyController extends Controller {
@inject myService;
// BAD
@oneWay('model.aProp') oneWayModelProp;
@reads('model.aProp') readsModelProp;
// Configurable to be BAD
@oneWay('myService.aProp') oneWayServiceProp;
@reads('myService.aProp') readsServiceProp;
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.