Skip to content

Commit 5aff44a

Browse files
committed
rename to $effect.allowed
1 parent 3345ed0 commit 5aff44a

File tree

13 files changed

+48
-39
lines changed

13 files changed

+48
-39
lines changed

.changeset/two-dancers-speak.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'svelte': minor
33
---
44

5-
feat: add `$effect.active` rune
5+
feat: add `$effect.allowed` rune

documentation/docs/02-runes/04-$effect.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,22 @@ const destroy = $effect.root(() => {
255255
destroy();
256256
```
257257

258-
## `$effect.active`
258+
## `$effect.allowed`
259259

260-
The `$effect.active` rune is an advanced feature that indicates whether or not an effect or [async `$derived`](await-expressions) can be created in the current context. To improve performance and memory efficiency, effects and async deriveds can only be created when a root effect is active. Root effects are created during component setup, but they can also be programmatically created via `$effect.root`.
260+
The `$effect.allowed` rune is an advanced feature that indicates whether or not an effect or [async `$derived`](await-expressions) can be created in the current context. To improve performance and memory efficiency, effects and async deriveds can only be created when a root effect is active. Root effects are created during component setup, but they can also be programmatically created via `$effect.root`.
261261

262262
```svelte
263263
<script>
264-
console.log('in component setup', $effect.active()); // true
264+
console.log('in component setup', $effect.allowed()); // true
265265
266266
function onclick() {
267-
console.log('after component setup', $effect.active()); // false
267+
console.log('after component setup', $effect.allowed()); // false
268268
}
269269
function ondblclick() {
270270
$effect.root(() => {
271-
console.log('in root effect', $effect.active()); // true
271+
console.log('in root effect', $effect.allowed()); // true
272272
return () => {
273-
console.log('in effect teardown', $effect.active()); // false
273+
console.log('in effect teardown', $effect.allowed()); // false
274274
}
275275
})();
276276
}

packages/svelte/src/ambient.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,22 @@ declare function $effect(fn: () => void | (() => void)): void;
238238

239239
declare namespace $effect {
240240
/**
241-
* The `$effect.active` rune is an advanced feature that indicates whether an effect or async `$derived` can be created in the current context.
241+
* The `$effect.allowed` rune is an advanced feature that indicates whether an effect or async `$derived` can be created in the current context.
242242
* Effects and async deriveds can only be created in root effects, which are created during component setup, or can be programmatically created via `$effect.root`.
243243
*
244244
* Example:
245245
* ```svelte
246246
* <script>
247-
* console.log('in component setup', $effect.active()); // true
247+
* console.log('in component setup', $effect.allowed()); // true
248248
*
249249
* function onclick() {
250-
* console.log('after component setup', $effect.active()); // false
250+
* console.log('after component setup', $effect.allowed()); // false
251251
* }
252252
* function ondblclick() {
253253
* $effect.root(() => {
254-
* console.log('in root effect', $effect.active()); // true
254+
* console.log('in root effect', $effect.allowed()); // true
255255
* return () => {
256-
* console.log('in effect teardown', $effect.active()); // false
256+
* console.log('in effect teardown', $effect.allowed()); // false
257257
* }
258258
* })();
259259
* }
@@ -262,9 +262,9 @@ declare namespace $effect {
262262
* <button {ondblclick}>Click me twice!</button>
263263
* ```
264264
*
265-
* https://svelte.dev/docs/svelte/$effect#$effect.active
265+
* https://svelte.dev/docs/svelte/$effect#$effect.allowed
266266
*/
267-
export function active(): boolean;
267+
export function allowed(): boolean;
268268
/**
269269
* Runs code right before a component is mounted to the DOM, and then whenever its dependencies change, i.e. `$state` or `$derived` values.
270270
* The timing of the execution is right before the DOM is updated.

packages/svelte/src/compiler/phases/2-analyze/visitors/CallExpression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export function CallExpression(node, context) {
150150

151151
break;
152152

153-
case '$effect.active':
153+
case '$effect.allowed':
154154
case '$effect.tracking':
155155
if (node.arguments.length !== 0) {
156156
e.rune_invalid_arguments(node, rune);

packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export function CallExpression(node, context) {
1717
case '$host':
1818
return b.id('$$props.$$host');
1919

20-
case '$effect.active':
21-
return b.call('$.effect_active');
20+
case '$effect.allowed':
21+
return b.call('$.effect_allowed');
2222

2323
case '$effect.tracking':
2424
return b.call('$.effect_tracking');

packages/svelte/src/compiler/phases/3-transform/server/visitors/CallExpression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function CallExpression(node, context) {
1616
return b.void0;
1717
}
1818

19-
if (rune === '$effect.tracking' || rune === '$effect.active') {
19+
if (rune === '$effect.tracking' || rune === '$effect.allowed') {
2020
return b.false;
2121
}
2222

packages/svelte/src/internal/client/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export {
107107
} from './reactivity/deriveds.js';
108108
export {
109109
aborted,
110-
effect_active,
110+
effect_allowed,
111111
effect_tracking,
112112
effect_root,
113113
legacy_pre_effect,

packages/svelte/src/internal/client/reactivity/effects.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const EFFECT_TEARDOWN = 3;
5353
* If not, a value indicating why is returned.
5454
* @returns {number}
5555
*/
56-
function active_root_effect() {
56+
function valid_effect_creation_context() {
5757
if (active_effect === null && active_reaction === null) {
5858
return EFFECT_ORPHAN;
5959
}
@@ -73,7 +73,7 @@ function active_root_effect() {
7373
* @param {'$effect' | '$effect.pre' | '$inspect'} rune
7474
*/
7575
export function validate_effect(rune) {
76-
const valid_effect_parent = active_root_effect();
76+
const valid_effect_parent = valid_effect_creation_context();
7777
switch (valid_effect_parent) {
7878
case VALID_EFFECT_PARENT:
7979
return;
@@ -195,11 +195,11 @@ export function effect_tracking() {
195195
}
196196

197197
/**
198-
* Internal representation of `$effect.active()`
198+
* Internal representation of `$effect.allowed()`
199199
* @returns {boolean}
200200
*/
201-
export function effect_active() {
202-
return active_root_effect() === VALID_EFFECT_PARENT;
201+
export function effect_allowed() {
202+
return valid_effect_creation_context() === VALID_EFFECT_PARENT;
203203
}
204204

205205
/**

packages/svelte/src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ const RUNES = /** @type {const} */ ([
442442
'$props.id',
443443
'$bindable',
444444
'$effect',
445-
'$effect.active',
445+
'$effect.allowed',
446446
'$effect.pre',
447447
'$effect.tracking',
448448
'$effect.root',
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
error: {
5+
code: 'rune_renamed',
6+
message: '`$effect.active` is now `$effect.tracking`'
7+
}
8+
});

0 commit comments

Comments
 (0)