Skip to content

[Feature Request Runes] Change $derived() to accept a function with a return value #9250

Closed as not planned
@D-Marc1

Description

@D-Marc1

Describe the problem

While $derived() is a welcomed Rune addition, I don't quite understand why it has a confusing syntax of:

const area = $derived(width * height)

Multi line code ends up adding way too much noise too, as it requires an IIFE:

const area = $derived((() => {
  return width * height
})())

Describe the proposed solution

It would be much more idiomatic in JavaScript for it to accept a function with a return value, so:

const area = $derived(() => width * height)

This is also more flexible for multiline code:

const area = $derived(() => {
  return width * height
})

Alternatives considered

There's no alternative in Runes that I'm aware of.

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions