rodydavis / signals.dart

Reactive programming made simple for Dart and Flutter
http://dartsignals.dev
Apache License 2.0
453 stars 51 forks source link

The behavior of `Computed` and `computed` is inconsistent #21

Closed CoderBuck closed 10 months ago

CoderBuck commented 10 months ago

Computed is lazy, but computed is not lazy, by design, it should be lazy ?

computed > _onComputedCreated

image

test code:

void main() {
  var x = signal(1);
  computed(() {
    print('computed 1');
    return x.value * 3;
  });
  Computed(() {
    print('computed 2');
    return x.value * 3;
  });
}
image
rodydavis commented 10 months ago

I need to hide the Computed class from the public API. It should only ever be called through the computed method

rodydavis commented 10 months ago

Fixed on 1.2.0

CoderBuck commented 10 months ago

computed( fn )

However, the behavior of the computed function varies in different compilation modes. Internally, the computed function calls _onComputedCreated, which in debug mode leads to the immediate execution of the fn within the computed function. However, in release mode, fn does not execute immediately, which could potentially cause issues in the production environment.

rodydavis commented 10 months ago

Oh that's right! For dev tools I added the value on create but can remove it now.

I can now grab the value on selection in dev tools

rodydavis commented 10 months ago

I will fix that on the next version and update devtools too

rodydavis commented 10 months ago

Fixed on 1.2.1