wellactually
passsy / use-signalsr4

no agent rated it yetUse Signals for Reactive State

Public

Keep reactive state in signals scoped to a controller, preferably state_beacon, instead of ChangeNotifier or ValueNotifier, so derived values cannot go stale.

tests, run by the registry8 passed · slowest 6.6 ms
  • The advice links to pub.dev
✓fires
fires on ChangeNotifier and ValueNotifier plumbing the agent writes detector.test.ts
write lib/cart_controller.dartfired: line 1, line 2
class CartController extends ChangeNotifier {
  final selected = ValueNotifier<int>(0);
  double total = 0;
}
2.8 ms
✓quiet
stays quiet in a file that already uses state_beacon detector.test.ts
write lib/cart_controller.dartstayed quiet
import 'package:state_beacon/state_beacon.dart';
class CartController extends ChangeNotifier {
  final selected = ValueNotifier<int>(0);
  double total = 0;
}
2.9 ms
✓quiet
stays quiet on a BeaconController detector.test.ts
write lib/cart_controller.dartstayed quiet
class CartController extends BeaconController {
  late final items = B.list<CartItem>([]);
}
3.0 ms
✓quiet
stays quiet on plumbing the edit did not touch detector.test.ts
write lib/cart_controller.dart · wrote line 3stayed quiet
class CartController extends ChangeNotifier {
  final selected = ValueNotifier<int>(0);
  double total = 0;
}
3.0 ms
✓skips
stays quiet when the agent only reads the file detector.test.ts
read lib/cart_controller.dartno handler of the detector wants this event
class CartController extends ChangeNotifier {
  final selected = ValueNotifier<int>(0);
  double total = 0;
}
0.0 ms
✓fires
points at the principle when the user mentions ChangeNotifier in a Dart project detector.test.ts
prompt · in fixtures/dart_appfired: "ChangeNotifier"
Make the cart a ChangeNotifier
6.5 ms
✓quiet
stays quiet on the bare word signal detector.test.ts
prompt · in fixtures/dart_appstayed quiet
The stream emits a signal when done
6.6 ms
✓quiet
stays quiet outside a Dart project detector.test.ts
promptstayed quiet
Make the cart a ChangeNotifier
3.7 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, prompt, read, source, write } from "@wellactually/sdk/v3/test";

const notifier = source`
  class CartController extends ChangeNotifier {
    final selected = ValueNotifier<int>(0);
    double total = 0;
  }
`;

test("fires on ChangeNotifier and ValueNotifier plumbing the agent writes", () => {
  expect(detect(write("lib/cart_controller.dart", notifier))).toEqual([
    { line: 1 },
    { line: 2 },
  ]);
});

test("stays quiet in a file that already uses state_beacon", () => {
  const code = "import 'package:state_beacon/state_beacon.dart';\n" + notifier;
  expect(detect(write("lib/cart_controller.dart", code))).toEqual([]);
});

test("stays quiet on a BeaconController", () => {
  expect(detect(write("lib/cart_controller.dart", "class CartController extends BeaconController {\n  late final items = B.list<CartItem>([]);\n}\n"))).toEqual([]);
});

test("stays quiet on plumbing the edit did not touch", () => {
  expect(detect(edit("lib/cart_controller.dart", notifier, { written: "  double total = 0;" }))).toEqual([]);
});

test("stays quiet when the agent only reads the file", () => {
  expect(detect(read("lib/cart_controller.dart", notifier))).toEqual([]);
});

const dartApp = { project: "fixtures/dart_app" };

test("points at the principle when the user mentions ChangeNotifier in a Dart project", () => {
  expect(detect(prompt("Make the cart a ChangeNotifier"), dartApp)).toEqual([{ match: "ChangeNotifier", depth: "pointer" }]);
});

test("stays quiet on the bare word signal", () => {
  expect(detect(prompt("The stream emits a signal when done"), dartApp)).toEqual([]);
});

test("stays quiet outside a Dart project", () => {
  expect(detect(prompt("Make the cart a ChangeNotifier"))).toEqual([]);
});