-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the problem
In #10240 we added $derived.call(fn) alongside $derived(expression), and somehow overlooked the fact that Function.prototype.call is a thing.
Strictly speaking this is fine — these are runes, not functions, and we can do what the hell we want. But realistically this is going to be a source of confusion at best and annoyance at worst for many people.
Describe the proposed solution
Programmers often talk about 'lazy evaluation', which basically means providing a function to compute some value rather than the value itself.
Even though the under-the-hood mechanism of $derived is that it's always lazy, meaning that this...
let value = $derived(expression);...is syntactic sugar for this...
let value = $derived.call(() => expression);...I think the conceptual framing is the right one. I therefore propose $derived.lazy:
let a = $derived(expression); // evaluated eagerly
let b = $derived.lazy(() => expression); // evaluated lazilyWe'll also need to add an error message for anyone who is already using $derived.call, of course.
Importance
would make my life easier