script effect
<script effect> is the opt-in source form for component-local Effect execution.
Source form
svelte
<script lang="ts" effect>
import * as Effect from "effect/Effect";
let count = $state(0);
const increment = Effect.gen(function* () {
count += 1;
});
</script>Transform semantics
- Declarations remain hoisted at component scope.
- Top-level executable statements are lowered into a mount-time
Effect.gen(...). yield*declarations are preserved through the lowering pass.- The generated program runs on mount.
- The generated program is canceled on unmount.
- HMR disposal is registered for running programs.