Hacker News new | ask | show | jobs
by fabiospampinato 1456 days ago
> I don’t understand the purpose of effect. Seems like compute can be used in all cases since you can dispose compute as well.

Not OP, but:

- You could just use computeds instead of effects, but:

  - Effects don't have an internal observable, so they are cheaper to make and to keep in memory.

  - If OP will implement something like Suspense they'll probably want to pause the execution of effects, but not the execution of computeds.

  - OP didn't implement this, but potentially you could support returning a cleanup functions inside effects, you can't do the same for computeds.
> Couldn’t read only be replaced with wrapping an observable in a closure?

Yes, internally it's probably just a `$computed( $observable )`. The differences are that one is just a function and the other is an observable, which is a detectable difference that may matter, but also potentially the utility function could return you always the same observable if it has already a reference to a read-only version of the one you give it, which may consume less memory (1 function to keep around rather than N), though this is a bit of an edge case.