# san/no-async-in-computed-properties

disallow asynchronous actions in computed properties

  • ⚙️ This rule is included in all of "plugin:san/essential", "plugin:san/strongly-recommended" and "plugin:san/recommended".

Computed properties should be synchronous. Asynchronous actions inside them may not work as expected and can lead to an unexpected behaviour, that's why you should avoid them.

# 📖 Rule Details

This rule is aimed at preventing asynchronous methods from being called in computed properties.

<script> export default { computed: { /* ✓ GOOD */ foo () { var bar = 0 try { bar = bar / this.data.get('a') } catch (e) { return 0 } finally { return bar } }, /* ✗ BAD */ pro () { return Promise.all([new Promise((resolve, reject) => {})]) }, foo1: async function () { return await someFunc() }, bar () { return fetch(url).then(response => {}) }, tim () { setTimeout(() => { }, 0) }, inter () { setInterval(() => { }, 0) }, anim () { requestAnimationFrame(() => {}) } } } </script>
Now loading...

# 🔧 Options

Nothing.

# 🔍 Implementation

Last Updated: 10/26/2021, 7:23:11 AM