New Rule: no-async-actions
See original GitHub issuesee http://ember-concurrency.com/docs/tutorial (scroll down to Version 4)
Bad:
actions: {
async handleClick() {
// ...
}
}
actions: {
handleClick() {
return something.then(() => { /* ... */ });
}
}
@action
async handleClick() {
// ...
}
@action
handleClick() {
return something.then(() => { /* ... */ });
}
Good:
actions: {
handleClick() {
return nothingOrSomethingThatIsNotAPromise;
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:15 (10 by maintainers)
Top Results From Across the Web
Does current.operation() work with Async Business Rule.
Hi, I am creating an Async Business Rule which is calling a REST API. Business Rule is supposed to run on insert and...
Read more >vue/no-async-in-computed-properties
Rule Details #. This rule is aimed at preventing asynchronous methods from being called in computed properties and functions.
Read more >san/no-async-in-computed-properties | eslint-plugin-san
san/no-async-in-computed-properties. disallow asynchronous actions in computed properties. ⚙️ This rule is included in all of "plugin:san/essential" ...
Read more >14 Linting Rules To Help You Write Asynchronous Code in ...
1. no-async-promise-executor ... This rule disallows passing an async function to the new Promise constructor. // ❌ new Promise(async (resolve, reject) => {}); ......
Read more >Asynchronous programming: futures, async, await - Dart
Asynchronous operations let your program complete work while waiting for another operation to finish. Here are some common asynchronous operations:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there a reason this is targeting actions specifically, as opposed to any member functions of
EmberObject
or glimmer Component sub-classes? Seems like the pitfalls aren’t unique to “actions,” and the@action
decorator no longer even really implies that it’s called from a template, so targeting “actions” seems a little arbitrary?@mansona I’m still not sold. Everything you said makes sense, but I think this will only partially address what it’s aiming for and could introduce further confusion. Async scenarios that this won’t cover:
this
-bound by some eventing mechanism, e.g.@ember/object/events
oreventemitter3
All of the above have the same pitfalls as the targeted scenario, and only differ from the targeted scenario in that they are less common in practice (probably, although I think async service functions are pretty common).
Further points of confusion:
@action
, whether in a component or not.Ember.set()
. There’s no runtime assertion if you set a@tracked
property after its object is destroyed, and there’s no inherent harm – the autotracking system is unrelated to theisDestroying
/isDestroyed
, so its just like setting a property on a{}
that your application logic has “stopped using”.So it looks like this is partially addressing a problem that is not clearly rationalized for modern Ember code. Given that the problem itself, especially when considered in the absence of
Ember.set()
, is not at all specific to Ember (you always have to be careful with async functions inside class methods!), and@action
already kinda confuses people and suggests that it’s more “magical” than it is in non-EmberObject
usages, I really worry that this rule will end up doing more harm than good.A couple of ways I could see improving the situation somewhat:
EmberObject
s, or perhaps onlyEmber.Component
s andEmber.Controller
s (because they are much more likely to be usingEmber.set()
rather than@tracked
)Ember.set()
invocations, so it’s really the lint-time warning about that specific runtime assertion.use-ember-concurrency-for-async-behavior
or something, where any async member function anywhere is flagged (perhaps with some post-await
this
checks or something). This would be putting a rule that’s not at all Ember-specific in Ember’s linting package, but I could see justifying that because we have a specific recommendation to make (ember-concurrency
).Regardless, at the very least I think we need to understand whether this rule is actually meant to target only components (and ensure that the implementation agrees with that), and if it’s meant to target more scenarios than just the
Ember.set()
assertion, provide document/examples of some of those other scenarios and the related pitfalls.