passsy / use-signalsr4
Use Signals for Reactive State
PublicKeep 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
✓fires2.8 ms
fires on ChangeNotifier and ValueNotifier plumbing the agent writes
write lib/cart_controller.dartfired: line 1, line 2
class CartController extends ChangeNotifier {
final selected = ValueNotifier<int>(0);
double total = 0;
}✓quiet2.9 ms
stays quiet in a file that already uses state_beacon
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;
}✓quiet3.0 ms
stays quiet on a BeaconController
write lib/cart_controller.dartstayed quiet
class CartController extends BeaconController {
late final items = B.list<CartItem>([]);
}
✓quiet3.0 ms
stays quiet on plumbing the edit did not touch
write lib/cart_controller.dart · wrote line 3stayed quiet
class CartController extends ChangeNotifier {
final selected = ValueNotifier<int>(0);
double total = 0;
}✓skips0.0 ms
stays quiet when the agent only reads the file
read lib/cart_controller.dartno handler of the detector wants this event
class CartController extends ChangeNotifier {
final selected = ValueNotifier<int>(0);
double total = 0;
}✓fires6.5 ms
points at the principle when the user mentions ChangeNotifier in a Dart project
prompt · in fixtures/dart_appfired: "ChangeNotifier"
Make the cart a ChangeNotifier✓quiet6.6 ms
stays quiet on the bare word signal
prompt · in fixtures/dart_appstayed quiet
The stream emits a signal when done✓quiet3.7 ms
stays quiet outside a Dart project
promptstayed quiet
Make the cart a ChangeNotifierdetector.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([]);
});